Serial Buffer overflow while sleeping

I have sensor aggregation unit, which is connected via UART (Serial4) with a particle e series.
It sends data roughly around every 500ms. As long as i dont use the sleep mode of the particle everything works fine.
But as soon as i use the sleep mode i dont get the data from the serial buffer. After waking obviously the serial buffer is full, as in 60s around 120time the data aggregation unit has written to the buffer. Changing the update times of the aggregation unit makes no sense, as the sleeping time of the particle will be different from each application.
Is there a way to clear the buffer as long as the particle is sleeping?


The buffer never overflows as it is a circular buffer, it may only overwrite previously received data when it is not read out quickly enough.
Also the device will not receive data during sleep.

However, since the A in UART stands for asynchronous you need to find a way to synchronise the reading to the datastream.
The way how to do that heavily depends on the data you expect to receive.

This is one way of flushing the RX buffer of unwanted data

  while( >= 0);

This will read and discard all data that is currently in the buffer - once the buffer is empty the return value will be (int)-1 and hence exit the loop.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.