cancel
Showing results for 
Search instead for 
Did you mean: 

UART even parity received WRONG

Ala
Senior

hey there

I try to receive some characters using UART and here is the config

huart1.Instance = USART1;
 
 huart1.Init.BaudRate = 4800;
 
 huart1.Init.WordLength = UART_WORDLENGTH_8B;
 
 huart1.Init.StopBits = UART_STOPBITS_1;
 
 huart1.Init.Parity = UART_PARITY_EVEN;
 
 huart1.Init.Mode = UART_MODE_TX_RX;
 
 huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
 
 huart1.Init.OverSampling = UART_OVERSAMPLING_16;
 

I use HTerm as a serial terminal to send data to it. I set the Baud rate to 4800, Data length to 7bits(I used CubeMX config, there it indicates the word length is parity included, so 8bits means 7bits+1parity I guess), and 1 stop bit and parity as EVEN.

things go wrong for some characters: for example 0xAF and 0xC5 are received as 0x2F and 0x45 respectively. some other characters are received OK such as: 0x41 or 0x00..

why is that? I noticed that the error is happening in the last bit of the faulty bytes, why is that?

1 ACCEPTED SOLUTION

Accepted Solutions

You need to mask the data​ read manually.

ie char ch = USART1->DR & 0x7F;​

T​he register is wider than the data, it shows you the raw parity bit, it makes the hw simpler. In the 8-bit case it often self masks based on the variables width.

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

2 REPLIES 2

You need to mask the data​ read manually.

ie char ch = USART1->DR & 0x7F;​

T​he register is wider than the data, it shows you the raw parity bit, it makes the hw simpler. In the 8-bit case it often self masks based on the variables width.

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

thanks, it worked actually:folded_hands: