Bug with LED's???

Hi,

I have an arduino due board. I was having issues and narrowed it down to the following code:

int led = 72;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(3000); // wait for a second
}

The result of this code is a long flash with a short off period.
I thought perhaps there was a bug in digital write so I modified it to use the registers directly but still the same issue.

void loop() {
REG_PIOC_SODR = 1 << 30; // the set register appears to turn it off
delay(500); // wait for a second
REG_PIOC_CODR = 1 << 30; // the clear register turns it on
delay(3000); // wait for a second
// the value of the REG_PIOC_OSDR is 0 here
}

The value of OSDR is correct and if it is enabled to be written to directly it has the same result.
Ie) writing a "0" appears to turn it on and "1" off

It is a minor problem but a little annoying.

I checked and it appears the TX LED does this aswell while the amber LED on pin 13 is normal.

Has anyone else come across this?

Stephen

I'd suggest that posting in the proper section of the forum would be more useful. There is a section dedicated to the DUE.

You would get inverted blinking if you accidentally wired your LED between your output pin and +5V instead of between your output pin and Gnd.

How to use this forum

Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the # button above the posting area.

FWIW I agree with johnwasser.

Pin 72 is the "RX" Led, right? In fact, looking at the Due schematic, it is wired between VCC and the driver, rather than GND and the driver, which is "backward", and will indeed invert the "on" sense (LOW = ON, HIGH = OFF.)
This is pretty common; on many micros, you can get more current through the LED this way, just because of the way the physics of the output transistors works out (although that doesn't seem to be true of the SAM3X.)
It's not so much a bug, as an alternate way of implementing LEDs.

It's probably copied from the 8u2 hardware on the Uno, so that the usb code can be somewhat common. It might have been copied there from the FTDI chip schematic. It COULD reflect the original purpose - a "serial" signal state is HIGH when it's "idle"; it has transitions to low during actual data transmission.

tmp.png

I wired an LED like that on my RS232 converter board, simply because RS232 is idle when high, and active when low, so by wiring it between the line and Vcc, it blinked when there was data.