avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] if test ignored?


From: kitts
Subject: Re: [avr-gcc-list] if test ignored?
Date: Fri, 18 May 2007 09:15:09 +0530
User-agent: KMail/1.9.6

On Friday 18 May 2007 9:09:32 am Rick Mann wrote:
> I have two source files. In Serial.c, I define a global:
> char    sCommandReceived;
>
> in the corresponding Serial.h file, I have:
>
> extern char sCommandReceived;
>
> sCommandReceived is set to 1 when enough bytes have been copied into  
> a buffer from the serial port. In main.c, which includes Serial.h, I  
> have:
>
>         while (true)
>         {
>                 if (sCommandReceived)
>                 {
>                         parseCommand();
>                 }
>         }
>
> If I break on the if statement, gdb tells me that sCommandReceived is  
> 1. However, a breakpoint in parseCommand(), defined earlier in the  
> file, never gets called. If I call parseCommand() directly from the  
> USART receive interrupt handler, it gets called. (parseCommand() then  
> clears sCommandReceived).
>
> What am I missing?

You need to make sCommandReceived a volatile variable.
-- 
Cheers!
kitts




reply via email to

[Prev in Thread] Current Thread [Next in Thread]