2022-12-20 12:03 AM
Hi, I want to receive data by UART.
In MX, I have initialized it:
this is the code:
huart1.Instance = USART1;
huart1.Init.BaudRate = 115200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
Error_Handler();
}
and I want to receive and transmit in special screens,
here is the code: I want to send and receive in screen7.
void Screen7View::handleTickEvent()
{
tickcounter++;
uint8_t a[] = "68";
//HAL_UART_Transmit(&huart1,(uint8_t*)a,8,10);// Sending in normal mode
//HAL_Delay(1000);
if(HAL_UART_Transmit_IT(&huart1, (uint8_t *)a, 8) != HAL_OK) {
Error_Handler();
}
}
for test, first of all, I want to transmit an integer assigned 68; on the other hand when other machine received 68 , it should make a sound.
the problem is UART does not work...
Can you help me what is the problem??
Thanks.
2022-12-20 02:53 AM
Doesn't work is a bit vague and non-specific.
Do you initialize the pins.
Does data come out the pin, check with a scope?
Do you have an interrupt Handler or callback function?
There aren't 8 characters in the string, and there's no termination like space or carriage return.
2022-12-23 11:19 PM
Hi, I fixed the problem now I can receive data but I have still problem through sending. I use this function sending an integer to main board but it does not work.
HAL_UART_Transmit(&huart1,(const uint8_t*)c,sizeof(c),500);
HAL_UART_TxCpltCallback(&huart1);