Receiving packet via UART interrupt | Cypress Semiconductor
Receiving packet via UART interrupt
I have been using state machines to date on the PIC processor to receive Asynchronous serial data. These relied on a timeout between bytes to know when packet has stopped transmission.
With the PSOC, I am having trouble with the timers to implement this strategy and also have been advised to do less within the interrupt.
What do you do for receiving Asynchronous data with interrupt?
Would you for instance:
Change packet structure to have exclusive start and stop delimiters (adding overhead as data would need to be sent as ASCII hex).
Start with an emppty buffer and simply poke each incoming byte into the buffer abd increment buf ptr.
In main code, check the buffer and if first character is not start delimiter then reset start ptr to beginning.
If start delimiter IS found then check data for end delimiter.
If End delimiter found then found then parse data. (probably use circular buffer to kep incoming bytes happening while processing the received packet (as long as it is process before overwriting as buffer rolls over). I expect buffer shjould be greater than 2 packet lengths.
If this is a typical method for handling data, how do you cope with data overuns and new valid data coming in after the overrun. Do you simply leave the UART to pack bytes into the circular buffer and in main code parse from Buffer TAIL until Head - looking for start byte?
Finally, Do you set a flag to indicate Start delimiter or do you just repeat search for start and then end every time round the main code?
An example would be much appreciated if anyone has one.