2022-09-26 10:20 AM
I can see transmitting characters from ADUCM360 to STM32.But it does not capture the incoming characters from STM32 using interrupts. Any help on this very much appreciated. Thank you
2022-10-13 12:52 PM
2022-10-13 01:45 PM
> Can you see any problem with this code?
At least call HAL_UART_IRQHandler(&huart2); before HAL_UART_Receive_IT()
Using HAL_UART_Receive_IT to receive one byte is a problem because it disables interrupt after each received byte and you can lose interrupts.
Using HAL_UART... functions at all is a problem.
2022-10-13 01:48 PM
I need to receive 19 strings . Each string ends with '\n' character .
I know that I receive the string when I go into the debugging stage and I can see the Receive buffer is filled.
Before I receive another string of characters, I displayed on the API.
2022-10-13 02:58 PM
Are the 19 strings sent one after the other without any pause? Or are you waiting to send the next set of strings after you display what is currently in the receive buffer?
2022-10-13 03:39 PM
Also, your variable "ch" already holds the incoming character. Doing "ch = USART->DR" is not needed.
Use the HAL_USART drivers as it does everything for you. You don't have to check for flags or clear flags, it's done in the driver.
Use the HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) callback. If that is called then there are no errors. All you have to do is read the character from the "ch" variable from that callback and save to your Receive[] buffer.
The 19 strings question I asked in the previous reply still stands?
2022-10-13 11:02 PM
the 19 strings sent one after the other without any pause. So I have to capture those 19 strings.
2022-10-13 11:48 PM
HAL_UART_Receive_IT(&huart2, (uint8_t*)ch, 1); -- need pointer here ->
HAL_UART_Receive_IT(&huart2, &ch, 1);
2022-10-14 10:02 PM
Thank you for all of your replies. after increasing the buffer size. I am able to receive 19 strings. But the 19 strings I received is static. It needs to be change every time i receive. Every time I receive it should be different set of data. Is something I need to reset the buffer everytime I receive and the buffer pointer. Any thoughts about this.
2022-10-14 10:19 PM
Ok, so your Receive[] buffer is done incorrectly. You actually need a ring buffer to hold a bunch of characters which requires a In pointer and Out pointer. The ring buffer should hold at least the largest string size plus 15% more characters. But if you have a lot of background stuff going on then you may need to increase the size even more.
I have a project that does that but it takes in a text file of hundreds of lines of text, 80 characters for each line of text one after the other with no pause. Actually someone posted on this forum wanting to read a text file and look for the word "PLLR1". I already had a project that i was working on, so I added few lines of code to accomplish what they wanted. So i have buffer of 90 characters so that an Rx character can't overwrite a previous line of text before i extract it and save it to a message buffer which i can hold up to 4 messages (lines of text). I check if the Message buffer contains a certain string and act upon that. With those two buffers working together, you'll never miss a Rx character. Because receiving a UART character is slow compared to the many instruction cycles of the MCU, the MCU can already extract the string up to the '\n' character and save it to a message buffer before that new character is saved.
See my project here.