DPRG
DPRG List  



[DPRG] Serial woes 2

Subject: [DPRG] Serial woes 2
From: Ed K. edk at kinetric.com
Date: Mon Feb 26 08:08:56 CST 2007

You don't show your declaration for cFromUART, but if it's a signed variable
of more than 8 bits, (e.g. 16) it will have a value of 0xFFF1 or some such,
because of sign extension for signed integer assignment.

Declare it as 8 bits, or as unsigned and the "if" should match it OK.

Otherwise use " if ( cFromUART&0xFF == 0xF1 )"

Ed Koffeman  

> -----Original Message-----
> From: dprglist-bounces at dprg.org [mailto:dprglist-bounces at dprg.org] On
> Behalf Of scott at lighthouse21.com
> Sent: Sunday, February 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
> http://list.dprg.org/mailman/listinfo/dprglist


More information about the DPRG mailing list

Copyright © 1984 - 2006 Dallas Personal Robotics Group. All rights reserved.
Website Design by NCC

For the latest robot news visit robots.net