2021-01-25 11:22 PM
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?
Solved! Go to Solution.
2021-01-26 04:22 AM
You need to mask the data read manually.
ie char ch = USART1->DR & 0x7F;
The 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.
2021-01-26 04:22 AM
You need to mask the data read manually.
ie char ch = USART1->DR & 0x7F;
The 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.
2021-01-26 04:43 AM
thanks, it worked actually:folded_hands: