2012-09-27 06:27 AM
Should I be checking for buffer overflows?
Do I just clear the bit if the interrupt occurs? What is the best way to handle buffer overflows?2012-09-27 06:41 AM
You should check for ALL the error status bits, and read the DR to clear them, otherwise the receiver will stop working.
How you deal with them will depend on your system/protocols. For things like XMODEM-1K you could ignore them and let the higher level protocol detect the transmission failure, and retry. Generally in systems where you want tolerance/robustness, you packetize or otherwise validate data blocks with CRC's or checksums.2012-09-27 07:52 AM
You should check for ALL the error status bits
I assume you mean turning on the USART_IT_ERR and possibly the USART_IT_PE interrupts. My protocol is simple - transmit buffer size of 3 worth of data, receive buffer size of 3 worth of data. Specifically, the RxBuffer[0] = 170 unless I ignore data and reset RxCount, else move on the the 2 remaining receives; So if I were to get a frame error, noise error, or overflow error, what would I do besides reset the bits that caused the interrupt to happen? Possibly clear out USART buffer when any error occurs, clear certain flags, etc. I mean there is no way to capture lost (overflowed) data or is there?2012-09-27 08:05 AM
I mean
#define USART_FLAG_ERRORS (USART_FLAG_ORE | USART_FLAG_NE | USART_FLAG_FE | USART_FLAG_PE) Ignore the ''interrupt'' reflections of the bits in the actual USART status register. Yes, once you're missed the byte(s) they are gone. You could work around that by using error correction methods.2012-09-27 09:43 AM
So basically,
if (USART_FLAG_ERRORS > 0){ USART_ClearFlag(Off whatever bit triggered error); errors++; //whatever else is usually done to handle errors } I guess I am wondering about the //whatever else is usually done to handle errors part besides clearing the bits that triggered the error and keeping track of the number of errors.2012-09-27 01:34 PM
I guess I am wondering about the //whatever else is usually done to handle errors part besides clearing the bits that triggered the error and keeping track of the number of errors.
I tend to clear the error (Reading DR), and count the errors, and send my data in a manner that it can resynchronize the stream in the parsing routines. So you might need to add some sync/preamble bytes at the front, and some frame check bytes at the back.