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

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

Re: [avr-gcc-list] Setting pin to high in function instead of main, inst


From: Richard Zetterberg
Subject: Re: [avr-gcc-list] Setting pin to high in function instead of main, instructions in main never run?
Date: Thu, 01 Mar 2012 14:38:00 +0100
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Thank you for the input, Peter and Cory.

Peter: The 3 chips I tried, were ordered at the same time, so if there
would be a manufacturing error the risk that all 3 are affected are
still there, I guess. I'm using a stabilized DC power supply which is
connected to Vcc and Gnd supplying 5 volts. I do not have a
possibility to try another chip except these 3 I have. But I am going
to order some and test, if we can't find anything wrong with the
disassembly.

Cory: No, setting PB0 to 1 in DDRB two times in main doesn't change
anything. Doing "DDRB = 0xFF;" doesn't change anything. However, if I
put that line of code inside the "turn_on_pb" function it works as
expected.

I have attatched two first code examples with dumping done on the
elf-file with the sections included aswell:

=== // Bare minimum start (faulty behavior) ===

#include <avr/io.h>

void turn_on_pb(void);

int main(void)
{
        DDRB |= (1 << PB0);
        turn_on_pb();

        for (;;) {

        }

        return 0;
}

void turn_on_pb(void)
{
        PORTB |= (1 << PB0);
}

- --- --- Disassembly start --- ---

example.elf:     file format elf32-avr

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000008  00000000  00000000  00000054  2**1

Disassembly of section .text:

00000000 <main>:
#include <avr/io.h>

int main(void)
{
        PORTB = 0xFF;
   0:   8f ef           ldi     r24, 0xFF       ; 255
   2:   85 b9           out     0x05, r24       ; 5
        DDRB = 0xFF;
   4:   84 b9           out     0x04, r24       ; 4
   6:   ff cf           rjmp    .-2             ; 0x6 <__zero_reg__+0x5>

- --- --- Disassembly end --- ---

=== \\ Bare minimum end ===



=== // Static bare minimum start (expected behavior) ===

#include <avr/io.h>

static void turn_on_pb(void);

int main(void)
{
        DDRB |= (1 << PB0);
        turn_on_pb();

        for (;;) {

        }

        return 0;
}

static void turn_on_pb(void)
{
        PORTB |= (1 << PB0);
}

- --- --- Disassembly start --- ---

example.elf:     file format elf32-avr

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000006  00000000  00000000  00000054  2**1

Disassembly of section .text:

00000000 <main>:

static void turn_on_pb(void);

int main(void)
{
        DDRB |= (1 << PB0);
   0:   20 9a           sbi     0x04, 0 ; 4
        return 0;
}

static void turn_on_pb(void)
{
        PORTB |= (1 << PB0);
   2:   28 9a           sbi     0x05, 0 ; 5
   4:   ff cf           rjmp    .-2             ; 0x4 <__zero_reg__+0x3>


- --- --- Disassembly end --- ---

=== \\ Static bare minimum end ===

On 3/1/12 2:15 PM, Peter Fuhrmann wrote:
> 
> The assembly looks correct. This should work. Maybe the RAM of your
> AVR is faulty so function return doesn't work, or the powersupply
> is unstable. I think this is most likely to be a hardware problem. 
> Another possibilitty ist that the Stack Pointer isn't set up
> properly in the startup code, so the function can not return.
> 
> Could you try another chip or another Board ?
> 
> Best Regards, Peter
> 
> _______________________________________________ AVR-GCC-list
> mailing list address@hidden 
> https://lists.nongnu.org/mailman/listinfo/avr-gcc-list
> 

On 3/1/12 2:17 PM, Cory Cross wrote:
> You should dump example.elf not example.o, could identify linking
problem.
> Does it work if you double the DDRB |=... command so it runs
> twice?
> 
> Cory
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJPT3u4AAoJEP99n2Mvs+maRBAP/2g6dJ5abqnUW+AJUxmbO0AY
BD7NIu/v7AYYby5qsy2T8ahTVmGxWF0G/CCSqE9B/QvA+wBpBly7XDVaIGMkjeyq
m8bbIwPXDZ1ISQJ/ZY0zisbANR7xfA8zGN+QHpmGgP+Mh6Nh5gHiO0tKFC5Kpu/9
N4Yf6zC1IS1t+IxS2jO++krJ1fBkWq/Z81bo8cbRFfXY/O9ijbjjpVu9vAV3vmjQ
UP86vcoGG5lPSgNhD+Pr8yUw7vzDKUeoAlHifEQsETwH552Sb/Ia14wyh0UozQjp
9+nGJht2CIPMf+5Pll6HZUYa4Pu2SAAO2lpdxv3bMlM8A4Wb+18iB4GzGseWkq2A
T9kQkqSLhMfH+Xi3hgf4Eyp7EWGJ2/7DwNR2nsj7c9x/s29ggprjKlrt3JREK5wv
+3a/nU7UDkgDs1ErOrVM9C0So4Fkw9pUgZzCH+5NDQnnMt6enoqKTVmAFQKV1kQW
o4Z3R2UT69cfv8Jn+egpB51NaPgGACt0Rc77EdKFBir/3O2x1Mg6vessPL7N1dTw
CtKmlQ0MDG7oenGRydFMZVh21WgAHPu5QmPtIAJQlCaGQ0PRXUhfgYjKboUBi4EX
bSSuXm3AvThGqrz0e0psV4Dj/p7wIfDKVzl8WPIFDfPJdhAAJYO4suaNxRFIw3EJ
ThTYpO1RYAl8EsoLYyjG
=SwzG
-----END PGP SIGNATURE-----



reply via email to

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