- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
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;
Timer1_Stop();
Timer1_WritePeriod(50000); //50ms
Timer1_Start();
Audio_Int_StartEx(ServiceTimer1); //Enable timer 1 int
}
void ResetAudio(void)
{
DatainBuf = false;
SoundRXmode = IDLE;
AudioRX_Ptr = 0x00;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I can answer my own post. I managed to figure it out and use a sofware counter instead of trying to start and stop timer. Also needed to read status to reset timer. Code below if it is useful to anyone.
CY_ISR(ServiceTimer1) //timer 1 int
{
Timer1_STATUS;
msTick++;
if((SoundRXmode == RECEIVING)&&(msTick == RxTimeout))
{
DatainBuf = true; //flag packet ready
}
}
CY_ISR(Service_SoundRX)
{
if(SoundRXmode == IDLE)
{
AudioRX_Ptr = 0x00;
SoundRXmode = RECEIVING;
}
RxTimeout = msTick + 50;
AUDIO_RXBuf[AudioRX_Ptr++] = SOUND_RXDATA_REG;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You could also have considered a LUT and a 50 mS clock as one of the LUT
qualifiers to yield a more HW aoproach. Just a thought.
Also when you do interrupts generally do most of the work outside interrupt
by setting a flag and exiting in ISR. Additionally declare globals used inside
ISR as volatile.
http://www.barrgroup.com/Embedded-Systems/How-To/C-Volatile-Keyword
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the advice Dana,
I went to the link and ended up purchasing the C Coding Standard book.
What is LUT?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Look Up Table, can be registered (feedback) or non registered.
Basically create a state machine or simple combinatorial logic.
http://www.cypress.com/?rid=46472
Attached a good C book.
Regards, Dana.