Skip to main content
Ala
Senior
January 26, 2021
Solved

UART even parity received WRONG

  • January 26, 2021
  • 2 replies
  • 1038 views

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?

This topic has been closed for replies.
Best answer by Tesla DeLorean

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.

2 replies

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
January 26, 2021

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
Ala
AlaAuthor
Senior
January 26, 2021

thanks, it worked actually:folded_hands: