How to know which received frame in uart had the error?

90 Views Asked by At

I am using atmega32 while learning about communication protocols and i have a question about the parity flag in uart which is set if the received data has a problem with parity. Now i know from the datasheet that the atmega32 has a 2 register buffer to receive data in so if i didn't read the data 2 times and the buffer has 2 bytes of data now how do i know which byte had the error with the parity is there a solution for this case in atmega32 and also in other microcontrollers.

Should there be multiple flags for errors in each byte of the buffer?

1

There are 1 best solutions below

0
remcycles On

According to the datasheet [1], there are a set of error flags for each frame in the receive buffer. So you can read the error flags before reading each frame of data.

20.7.4 Receiver Error Flags

The USART Receiver has three Error Flags: Frame Error (FE), Data OverRun (DOR) and Parity Error (PE). All can be accessed by reading UCSRA. Common for the Error Flags is that they are located in the receive buffer together with the frame for which they indicate the error status. Due to the buffering of the Error Flags, the UCSRA must be read before the receive buffer (UDR), since reading the UDR I/O location changes the buffer read location. Another equality for the Error Flags is that they can not be altered by software doing a write to the flag location. However, all flags must be set to zero when the UCSRA is written for upward compatibility of future USART implementations. None of the Error Flags can generate interrupts.

[1] https://ww1.microchip.com/downloads/en/DeviceDoc/Atmega32A-DataSheet-Complete-DS40002072A.pdf