cancel
Showing results for 
Search instead for 
Did you mean: 

Incorrect Data after reception when used 7,Even,1 stop bit UART combination.

Alpha Mr
Associate II
Posted on May 11, 2018 at 14:07

Hello,

I am trying to communicate with remote serial device which needs 7-bit data length, Even or odd parity, 1 stop bit. But I am facing problems in implementing this. Problem is the data received in RDR register is incorrect. For example I am transmitting 0x31 from PC terminal and I am getting 0xB1 when I configured UART  with 8,E,1 and PC terminal with 7,E,1 setting.This seems wrong but its correct as STM32 has data word length including parity If seen the above byte in binary form : 0x31 is 00110001 and 0xB1 is 10110001 . Its clear that the latter is the 0x31 with added even parity. But I am not getting why RDR has 0xB1 instead of 0x31 

after reception

?  I am using STM32F091RCT6 with SWSTM32 IDE.The same was tested with odd parity too but with same results. Parity handling is done in STM32 isn't it? I have tried searching for user manual of this MCU but didn't find any, found only reference manual which didn't helped in knowing how STM32 handles parity. I have successfully tested the 8,E/O,1 combination and it worked fine, but 7,E/O,1  didn't worked. Any help will be appreciated.

#stm32f-uart
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on May 14, 2018 at 06:05

The latter probably gets masked as you handle chars (uint8_t) rather than what comes out of the RDR register (uint16_t), ST saves a bunch of gates in the USART design and you have to write uint8_t data = (uint8_t)(USART1->RDR & 0x7F);

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

View solution in original post

3 REPLIES 3
Posted on May 11, 2018 at 15:50

The STM32 counts the parity bit in the settings, for 8E1 you need to configure 9-bit operation, of 7O1 you need 8-bit. You should also mask the data register on a read to the bits that carry the payload, and exclude the parity bit.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 14, 2018 at 05:57

Hello Clive,

Yes the same configuration I used 8,E/O,1 works but the 7,E/O,1 don't. I thought parity handling is done on chip and software get the payload it needs because it worked for 8,E/O,1 , but it turns out that this needs to be handled in software.

Posted on May 14, 2018 at 06:05

The latter probably gets masked as you handle chars (uint8_t) rather than what comes out of the RDR register (uint16_t), ST saves a bunch of gates in the USART design and you have to write uint8_t data = (uint8_t)(USART1->RDR & 0x7F);

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