DPRG List  

[DPRG] Serial woes 2

Subject: [DPRG] Serial woes 2
From: Chris Jang cjang at ix.netcom.com
Date: Mon Feb 26 02:00:10 CST 2007

Hello Scott,

You may try something as with: http://golem5.org/robot1/sourcecode/avr/tt.c . It never checks the port before reading from it. There is a three byte FIFO that builds up command frames over multiple polling loops.

My experience has been that some kind of explicit buffering like this becomes necessary for reliable serial framing when not using interrupts (...when not having hardware do the work for you). Polling and spinning is tricky to get right. And it tends to break pretty easily with subtle changes in timing.

I know that I am accustomed to large interrupt driven device buffers supplied either by hardware or software drivers. So normally I don't have to think about a software reliability layer for something as basic as communications. But I started using a DSO for signal capture while debugging a lot of serial code (some of which was bit banging). It was much trickier than I thought.


-----Original Message-----
>From: scott at lighthouse21.com
>Sent: Feb 25, 2007 11:21 PM
>To: dprglist at dprg.org
>Subject: [DPRG] Serial woes 2
>Hello all,
>I'm trying to grab characters from a serial data stream coming into an
>Atmega 88.  If I just debug print them to the LCD I can see the value come
>through that I'm looking for but if I try to capture it with an IF the IF
>never runs.  Here's the code snippet:
>	  if (!(UCSR0A & (1 << RXC0))) // See if there's a character waiting
>	  {
>	     iFoo = ~iFoo; // do nothing if there's no char waiting
>	  }
>	  else
>	  {
>		 cFromUART = UDR0; // Get the character from the UART
>		 if (cFromUART == 0xF1) // If its a time code message, catch it
>		 {
>		    sprintf (sTimeCode,"%cTIME%d",12,cFromUART);
>			LCDBug (sTimeCode);
>			while (1); // Show it on the LCD for ever and ever
>		 }
>This IF never actually comes through.  If I just run the data straight to
>the LCD you can see 0xF1 go by a couple of times.
>DPRGlist mailing list
>DPRGlist at dprg.org

More information about the DPRG mailing list