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

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

AW: [avr-gcc-list] Gcc bug??


From: Peter Hierholzer
Subject: AW: [avr-gcc-list] Gcc bug??
Date: Wed, 3 Mar 2004 11:52:02 +0100

> I'm having some problems with an app that uses AvrX and gcc (v. 3.3.1) on
> an
> ATmega16. In the interrupt routine for the TWI  I write a static with a
> code
> that indicates its current state. In an effort to debug a different
> problem
> I compiled the code without any optimization.
> 
> While I did discover the original problem I had been hunting, I started to
> see some very unreliable behavior with the TWI. After some investigation I
> determined that the state variable (mentioned above) was getting written
> with an unreasonable value (not a valid state). The correct state value
> that
> should have been written into the variable is "0". Further experiments
> revealed that memory corruption (at least directly into the variable's
> memory location) was not the problem.
> 
> What I then determined is that the "0" register (r1) contained the value
> 8!
> This, not coincidentally (and looking at the disassembled code) is exactly
> the value that's being incorrectly written into the static state variable.
> Interestingly, turning on any level of optimization seems to fix it, at
> least as observed by the TWI port handler not hanging.
> 
> I was wondering if anyone else has seen anything like this, or has any
> advice or suggestions.
> 
> Thanks
> 
> -brian


Hi Brian,

Did you declare the state variable as volatile?
If you access a variable in your normal program AND in the interrupt routine
you must declare it as volatile. Otherwise the compiler is not aware that
the variable is modified in the interrupt routine and generates wrong code.

Peter



_______________________________________________
avr-gcc-list mailing list
address@hidden
http://www.avr1.org/mailman/listinfo/avr-gcc-list


reply via email to

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