UART packet timeout | Cypress Semiconductor
UART packet timeout
A short time ago I posted a question relating to setting up a time to determine when a packet has completed transmission.
I would like to use a small state machine that resets the timer each time a byte is received and sets a flag when packet is complete. The pseudo code is what I think should work but I needed to know if it is ok to stop the UART interrupt inside a timer interrupt and whether resetting the timer period is ok inside an interrupt. I have not shown the init routines or exact syntax but kept it simple to show the concept. I am also not sure if I have to do some sort of read in timer isr to keep timer running.
CY_ISR(TimerInterrupt) //this routine fires when no bytes received for more than 20ms
if(Mode == RECEIVING) //only set flag if data reception has begin, else ignore timeout
DatainBuf = true;
UART_Stop(); //stop UART to prevent state changing after timeout
if(Mode == IDLE) //reset stae machine, add incoing data to buffer and reset timer
DatainBuf = false;
Mode = RECEIVING;
Ptr = 0
ComBuf[Ptr] = UART_Read();
ResetCom() // call this before when ready to receive data
Mode = IDLE;
if(DatainBuf) ProcessCom(); /