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

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

Re: [avr-gcc-list] Mega32 wierdness


From: Jonny Dyer
Subject: Re: [avr-gcc-list] Mega32 wierdness
Date: Sun, 23 Jan 2005 10:30:33 -0800

I am using avr-gcc -c -g -O3 -Wall -mmcu=atmega32 test.c - should be exactly equivalent to your build command.

Jonny

On Jan 23, 2005, at 2:38 AM, Ben Mann wrote:

It is almost as if somehow messing with
timer_step (which gcc is saving at r0)
outside of the interrupt

What build command are you using? When I build this code it is being saved
to RAM at location 0x0000.

ie:
        timer_step++;
  3a:   80 91 00 00     lds     r24, 0x0000
  3e:   8f 5f           subi    r24, 0xFF       ; 255
  40:   80 93 00 00     sts     0x0000, r24


Is it possible your build command is not for atmega32?

My build command:
avr-gcc -g -Os -Wall -funsigned-char -mmcu=atmega32 -c TEST.C
avr-objdump -h -S TEST.O >  TEST.LST

Otherwise I for one see nothing wrong with the code or asm (but don't have
an atmega32 to test with).

Ben Mann



-----Original Message-----
From: address@hidden [mailto:address@hidden
On Behalf Of Jonny Dyer
Sent: Sunday, 23 January 2005 5:39 PM
To: address@hidden
Subject: [avr-gcc-list] Mega32 wierdness


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 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]