Offline
Newbie
Karma: 0
Posts: 1
|
 |
« on: March 10, 2013, 04:24:54 am » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 336
Posts: 36476
Seattle, WA USA
|
 |
« Reply #1 on: March 10, 2013, 09:33:31 am » |
I'd suggest that posting in the proper section of the forum would be more useful. There is a section dedicated to the DUE.
|
|
|
|
|
Logged
|
|
|
|
|
Massachusetts, USA
Offline
Tesla Member
Karma: 108
Posts: 6615
|
 |
« Reply #2 on: March 10, 2013, 11:16:09 am » |
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.
|
|
|
|
« Last Edit: March 10, 2013, 04:25:38 pm by johnwasser »
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14110
Lua rocks!
|
 |
« Reply #3 on: March 10, 2013, 03:47:26 pm » |
How to use this forumPlease 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.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14110
Lua rocks!
|
 |
« Reply #4 on: March 10, 2013, 03:48:07 pm » |
FWIW I agree with johnwasser.
|
|
|
|
|
Logged
|
|
|
|
|
SF Bay Area (USA)
Offline
Faraday Member
Karma: 80
Posts: 5513
Strongly opinionated, but not official!
|
 |
« Reply #5 on: March 10, 2013, 05:34:53 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14110
Lua rocks!
|
 |
« Reply #6 on: March 10, 2013, 11:29:45 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
|