[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] Mega32 wierdness
From: |
Jonny Dyer |
Subject: |
[avr-gcc-list] Mega32 wierdness |
Date: |
Sun, 23 Jan 2005 01:38:41 -0800 |
I am trying to get started working with GCC for AVR and am having a
terrible time with a Mega32. Note that I am experience with AVR
assembly and the aTinys, but this is my first C AVR project.
As a simple test program, I have Timer0 interrupt enabled and am
running Timer0 at clk/1024. On overflow, I am toggling all the pins on
Port D. If I do just this and nothing else, the program works fine.
However, I wanted to add a counter to the overflow function so that I
can divide the timer overflows further and only toggle the LED, say,
every 5 overflows. If I define my counter variable as volatile (as I
have read is necessary when working with interrupts several other
places), increment it in the interrupt function and leave the PORTD
toggling in that function, it still operates the same (as it should):
SIGNAL(SIG_OVERFLOW0)
{
timer_step++;
PORTD ^= 0xff;
}
However, if I do anything to timer_step in the rest of the code (namely
in main()), it's as if the timer overflow stops being called and the
pins on PORTD no longer flash. Note that I am doing nothing at all to
my interrupt routine:
volatile uint8_t timer_step;
int main (void)
{
uint8_t save;
timer_step = 0;
DDRD = 0xFF;
PORTD = 0x00;
TIFR = BV(TOIE0);
TCCR0 = BV(CS02) | BV(CS00); /* CTC, prescale = 128 */
TCNT0 = 0;
TIMSK = BV(TOIE0); /* enable Timer0 overflow interrupt*/
sei();
for(;;)
{
if(timer_step > 10)
{
timer_step = 0;
}
}
}
SIGNAL(SIG_OVERFLOW0)
{
timer_step++;
PORTD ^= 0xff;
}
I have disassembled the code and I can see nothing wrong with the code
GCC is generating either. It is almost as if somehow messing with
timer_step (which gcc is saving at r0) outside of the interrupt
function corrupts TIMSK or TIFR or the interrupt vector. Any help is
greatly appreciated.
Thanks
Jonny
- [avr-gcc-list] Mega32 wierdness,
Jonny Dyer <=