2024-01-21 01:56 AM
Hi all i'm implementing a serial communication between my evaluation board and my PC
i managed to send data from my board and read it via PuTTY.
but when i run HAL_UART_Receive_IT and send messages via PuTTY it doesnt trigger the
"HAL_UART_RxCpltCallback" Function
im using NUCLEO H743ZI2
and USART3 baud rate: 115200
Interrupt is enabled for USART3
This is my code (just the important stuff):
Thanks! :)
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
char str[100];
strcpy(str, "hi hi\n\r");
HAL_UART_Transmit(&huart3, (uint8_t*)str, strlen(str), 1000);
}
int main(void)
{
char str[100];
strcpy(str, "hello hello\n\r");
HAL_UART_Transmit(&huart3, (uint8_t*)str, strlen(str), 1000);
HAL_UART_Receive_IT(&huart3, rx_data, 6);
while (1)
{
}
}
Solved! Go to Solution.
2024-01-22 06:46 AM
If you get HAL_TIMEOUT, then data isn't coming in on the RX line. This isn't something that can be fixed by code. Look at the pins involved, ensure you're hooking things up in the appropriate manner. Look at the board schematic, ensure the pin isn't being used by something else and is actually connected to the header you're using for access. Get a logic analyzer and look at signals on the pins.
2024-01-21 07:45 AM
Get blocking mode up and running first. Can you receive any characters at all? See if HAL_UART_Receive returns HAL_OK along with the expected data.
Note that calling a blocking function (HAL_UART_Transmit) within an interrupt can cause issues.
2024-01-22 04:06 AM
yea i did try the blocking one but didnt manage to get it working either, i tried a diffrent terminal as well
these were my steps for "HAL_UART_Receive" (no interrupt)
i keep getting timeout
* disabled USART3 Interrupt
code:
int main(void)
{
uint8_t rx_buffer[10];
HAL_StatusTypeDef status;
while (1)
{
status = HAL_UART_Receive(&huart3, rx_buffer, sizeof(rx_buffer), 1000);
if (status == HAL_OK)
{
send_message("ok\n\r");
}
else if (status == HAL_TIMEOUT)
{
send_message(".");
}
else
{
send_message("ERR");
}
}
}
2024-01-22 06:46 AM
If you get HAL_TIMEOUT, then data isn't coming in on the RX line. This isn't something that can be fixed by code. Look at the pins involved, ensure you're hooking things up in the appropriate manner. Look at the board schematic, ensure the pin isn't being used by something else and is actually connected to the header you're using for access. Get a logic analyzer and look at signals on the pins.
2024-01-22 09:01 AM
You keep getting a timeout perhaps because you tell HAL_UART_Receive() to wait 1 second to receive 10 bytes. If it receives less than 10 bytes in that 1 second it will return a timeout BUT THERE MAY BE SOME RECEIVED DATA in the RX buffer. You can check the huart3 member variables to see how many bytes it did receive.
Are you really (REALLY) expecting to receive fixed-length data on the UART? The stock HAL UART functions are not intended to deal with variable length RX. If you are expecting variable length RX data then look at the code here:
https://github.com/MaJerle/stm32-usart-uart-dma-rx-tx
There is a lot of stuff there, but he does talk about (and give examples of) RX without an RTOS.
2024-01-22 09:43 AM
Also, avoid the receiver overrun! If it occurs it will block further receive until cleared off..
2024-01-23 05:08 AM
to my surprise this was actually the problem, the RX pin i was assigned by default for some reason did not work.
when i changed RX Pin from PB11 to PD9 (my TX is PD8), everything seems to work.
im still not sure why because PB11 wasn't used in my code for anything else.
Thanks!
2024-01-23 07:02 AM
Verify how PB11 is being used with your Nucleo board's schematics and/or User Manual.