Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

RE: [AVR-Chat] Timeout detection Serial RS232 USART

2011-05-26 by farhan ahmad

Thanks Dave,
 
I have implemented in my code and it is working properly. 
 
Thanks for your Tip.
 
Best Regards,
Farhan Ahmad

--- On Tue, 5/24/11, Dave McLaughlin <dave_mclaughlin@nerdshack.com> wrote:


From: Dave McLaughlin <dave_mclaughlin@nerdshack.com>
Subject: RE: [AVR-Chat] Timeout detection Serial RS232 USART
To: AVR-Chat@yahoogroups.com
Date: Tuesday, May 24, 2011, 9:02 AM


  



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]








[Non-text portions of this message have been removed]

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.