Electronic – Arduino needs serial init to work

arduino

I recently bought arduino uno r3 and started with simple program which blinks embedded led:

#define LED_PIN 13

void setup()
{
    pinMode(LED_PIN, OUTPUT);
}

void loop()
{
    digitalWrite(LED_PIN, HIGH);
    delay(500);
    digitalWrite(LED_PIN, LOW);
    delay(500);
}

A problem is that this program isn't working. After uploading it seems got stuck in some state (led is constantly on or constantly off).

But in case program is using serial module — arduino works as expected.

#define LED_PIN 13

void setup()
{
    pinMode(LED_PIN, OUTPUT);
    Serial.begin(9600);
}

void loop()
{
    digitalWrite(LED_PIN, HIGH);
    delay(500);
    digitalWrite(LED_PIN, LOW);
    delay(500);
}

Where is the problem? Or it is by design and should work this way?

About toolchain:

  • avr-g++-4.4.6-r1 p1.0, pie-0.4.5
  • arduino-1.0.5
  • avrdude-6.0.1
  • avr-libc-1.8.0

Best Answer

Turns out that problem was in binutils toolchain part. I have used 2.19 and apparently it's broken with arduino, so I rollback to 2.18.50.0.9 and now all things works as supposed to.

So it's quite strange that arduino actually works with serial.begin().

For gentoo users next actions should resolve the issue:

crossdev -C avr
USE="multilib -cxx" crossdev --b 2.19.1-r1 -S -s1 --target avr
USE="multilib cxx" crossdev --b 2.19.1-r1 -S -s4 --target avr