Not too difficult.
What I do is create a timer that increments every 1ms. I then create a
volatile long variable that gets incremented in the timer interrupt.
Now in your code you reset the timer to ZERO and then just check it for
greater than or equal to 500.
Main thing to make this work is not to call any function that reads the
serial port until there is anything in the buffer (assuming you use the
interrupt driven serial routines in Codevision, which I would recommend you
do?)
e.g. (not complete working code)
msTimer = 0;
while(1)
{
if(rx_counter) // Is there any RS232 data to process?
{
ReadRS232();
}
else if
{
if(msTimer >= 500)
{
DoSomethingHere();
msTimer = 0; // Reset the timer
}
}
}
In the above, you simply loop around looking for data arriving on the serial
port and process it if so. If not, you go off and do your other stuff after
500ms has elapsed and then go back to checking for data.
I have not shown the interrupt handler for the timer. Use the excellent
AVRCalc to give you a value to set one of the timers to 1ms resolution.
Simple and easy to do.
Dave...
---
Very funny Scotty, now beam down my clothes!!!
---
From: AVR-Chat@yahoogroups.com [mailto:AVR-Chat@yahoogroups.com] On Behalf
Of farhan ahmad
Sent: 24 May 2011 19:55
To: AVR-Chat@yahoogroups.com
Subject: [AVR-Chat] Timeout detection Serial RS232 USART
Dear All,
I am currently in the process of writing software which involves reading
characters from RS232 port. Can anyone suggest a good way of detecting a
timeout condition? For example, if there will be no data on RS232 port for
500ms then program will do something else.
I am using ATMEGA64 ATMEL AVR micro-controller. The software compiler is
CodeVisionAVR.
I hope to get valuable responses from all.
Best Regards,
Farhan Ahmad
[Non-text portions of this message have been removed]Message
RE: [AVR-Chat] Timeout detection Serial RS232 USART
2011-05-24 by Dave McLaughlin
Attachments
- No local attachments were found for this message.