[Top][All Lists]

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

Re: [avr-gcc-list] Global variables and ISRs ???

From: Johnathan Corgan
Subject: Re: [avr-gcc-list] Global variables and ISRs ???
Date: Tue, 06 Sep 2005 12:58:40 -0700
User-agent: Mozilla Thunderbird 1.0.6 (X11/20050727)

Vincent Trouilliez wrote:

> unsigned char flag, bin;  //global variables

Try making 'flag' volatile:

volatile unsigned char flag;
unsigned char bin;

What's probably happening is the compiler, not seeing that 'flag' is
modified anywhere in the while loop, isn't reloading it every loop
iteration (this is a common optimization.)  By declaring 'flag' as
volatile, you tell the compiler that it's value might change at any
time, unrelated to the code that is currently executing (in this case,
by your ISR.)  Now the compiler will reload the value from SRAM every
time it's needed.

You can check your assembly output to see if the SRAM location for flag
is getting accessed from within the loop to verify this is the problem.


Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

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