2023-11-23 12:17 AM
Hi Community
I could use some help regarding UART on the "Bluepill" board so I can get my night sleep back again
I'm working on a small project where I'm creating some interrupt driven bit frames on 16 outputs. Each frame is 16mSec long and consists of a 4.3mS start bit followed by 16 data-bits.each with a fixed 310uS low period, a fixed 155uS high period and the last part of each bit it 155us and is low or high dependent on the set value
So far so good, this part is working very stable and reliable
Then I need to receive commands on the UART and use these commands to set the bits in the frames, but I have big problems receiving these commands via the UART.
The problem is that sending eg. abc and then cr to the UART is given me aabbbccc\0 in the Command buffer
As a test, looping the received byte back directly in the interrupt handler is given me ee when I send a single e to the UART port. Same for all chars.....I get 2 chars back
What am I missing or what am I doing wrong?
My understanding is that reading the USART1 DR register resets the interrupt.
Why do I get double number of chars and numbers both in the test-loopback but also in the created command-buffer?
Solved! Go to Solution.
2023-11-23 06:00 AM
Hello @SteenA and welcome to ST community ,
after a quick look to your code i see that you are setting usartready flag in the interrupt handler.
i recommand you use the HAL HAL_UART_IRQHandler() function to be sure you are couvering all the possible erros and manipulating the UART register the write way.you will find attached a code example which you can base your implementation .
BR
2023-11-23 06:00 AM
Hello @SteenA and welcome to ST community ,
after a quick look to your code i see that you are setting usartready flag in the interrupt handler.
i recommand you use the HAL HAL_UART_IRQHandler() function to be sure you are couvering all the possible erros and manipulating the UART register the write way.you will find attached a code example which you can base your implementation .
BR
2023-11-23 06:19 AM
Should perhaps qualify it has a RXNE flag before reading DR
2023-11-27 02:24 AM
Thanks a lot !!
Your recommendation forced me to read how to do it the "Official" way and it is working perfect now
I had to to set the callback to 1 byte due to variable rx string length, but it wasn't that difficult after I got your reply
Br Steen