cancel
Showing results for 
Search instead for 
Did you mean: 

UART Problems on STM32F103C8T6

SteenA
Associate

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
STea
ST Employee

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
  

 

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

3 REPLIES 3
STea
ST Employee

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
  

 

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Should perhaps qualify it has a RXNE flag before reading DR

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..

@STea

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