Go Down

### Topic: X-Ray of the Blink example skecth for DUE (Read 2205 times)previous topic - next topic

#### Palliser

##### Aug 14, 2013, 08:02 pm
Here a raw blink code for due revealing SAM3X8E registers used.

Code: [Select]
/*
Raw blink sketch for DUE revealing SAM3X8E registers used
Turns on an LED on for one second, then off for one second, repeatedly.
*/

uint32_t led = (1u << 27);

void setup()
{
// Output Enable Register
REG_PIOB_OER = led;
}

// the loop routine runs over and over again forever:
void loop()
{
REG_PIOB_SODR = led; // Set Output Data Register, turns LED on
delay(1000);         // wait for a second
REG_PIOB_CODR = led; // Clear Output Data Register, turns LED off
delay(1000);         // wait for a second
}

#### jtw11

#1
##### Aug 16, 2013, 12:08 amLast Edit: Aug 16, 2013, 12:23 am by jtw11 Reason: 1
Could you explain what the mask of 1u << 27 does?

I assume calling REG_PIOB_OER = led; is actually setting up the OER register for pin 27 on PIOB, but I do not understand the use of 1u?

EDIT - It seems 1u is a bitmask operator, so that statement is the same as

Code: [Select]
uint32_t led = (0b00001000000000000000000000000000);

Still, why 1U? 1unsigned?

#### Palliser

#2
##### Aug 16, 2013, 02:43 am
In C/C++, at a core level, the definition of a single (or brief) pin, controlled by a parallel I/O port is approached masking a correspondent bit.
In order to do that, a standard syntax is used. In our case, with the format: (1u << x) where:

1u  (left operator) is an unsigned value with the single bit 0 set, and all the other bits cleared. i.e.  1u = unsigned value 1.
<<    is a bit shifting operator.
x    (right operator) is the number of bits of the shifting.

In other words, (1u << 27) means create an unsigned value 1 shifted to the left 27 times (or bits). Thus, your posted code is correct.

Regards!

#### jtw11

#3
##### Aug 16, 2013, 01:42 pm
Ah, that makes sense - i'll read up a little more, but thanks.

#### grantnlee

#4
##### Oct 11, 2013, 06:15 am
@Palliser  is there any documentation that describes how to write directly to these 3X8E ports PIOA thru PIOF?

Code: [Select]
REG_PIOB_OER = led;
}

// the loop routine runs over and over again forever:
void loop()
{
REG_PIOB_SODR = led; // Set Output Data Register, turns LED on
delay(1000);         // wait for a second
REG_PIOB_CODR = led; // Clear Output Data Register, turns LED off
delay(1000);         // wait for a second

I've read the spec sheet and see the reference to them and the pins that they control.  Curious how it has been implemented in Arduino 1.5.4 to access them, as you have...    Guess I can extrapolate what I see you have written, but would like to see any docs.

Thanks!  Jay.

#### noblepepper

#5
##### Oct 12, 2013, 12:44 am
I haven't found much in  the way of docs but you have the source take a look through the forum, you'll find several threads. One was titled how to definue physical addresses/registers? It's down below CMSIS in The tree.

Go Up

Please enter a valid email to subscribe