Need help with timer interrupt | Cypress Semiconductor
Need help with timer interrupt
I am trying to set up an interrupt driven RS232 receiver that uses a simple state machine to gather bytes.
Essentially, Each time the interrupt fires and I capture the byte into my buffer, I want to set up a 50ms timeout so I can detect end of transmission (Unless the UART has some sort of idle time interrupt? that would be great).
The data is being received ok. I can run it for a while, pasue and look at the redceive buffer and correct data is in it.
The timeout does not seem to be working too well. The timer should be reinitialized to 50ms timeout each time a byte is received and when no byte within 50ms then the Timer-Int should fire and flag that data is ready in my buffer.
I also need a method to timeout the overall process (ie. Send a command and wait for certain time for response and then timeout if none). I suppose this would be a non-interrupt driven timer that I start and then poll for EITHER TC or RX Data in my buffer?
Here is my little snippet of code. Thanks, I appreciate all the help you folks have given me as I climb up the learning curve with PSOC and the components in creator.
CY_ISR(ServiceTimer1) //timer 1 int - This routine should only fire when no bytes for 50ms and flag packet if receiving
Timer1_Stop(); //50ms timeout since last byte received
numSoundRXbytes = AudioRX_Ptr; //get number of bytes received
if(SoundRXmode == RECEIVING) DatainBuf = true; //flag packet ready
CY_ISR(Service_SoundRX) //this shuld fire evry received byte (it does) and should restart the timer to prevent it timing out if more bytes are arriving.
AUDIO_RXBuf[AudioRX_Ptr++] = SOUND_RXDATA_REG;
SoundRXmode = RECEIVING;
Audio_Int_StartEx(ServiceTimer1); //Enable timer 1 int
DatainBuf = false;
SoundRXmode = IDLE;
AudioRX_Ptr = 0x00;