Pages: [1]   Go Down
Author Topic: X-Ray of the Blink example skecth for DUE  (Read 1379 times)
0 Members and 1 Guest are viewing this topic.
Venezuela
Offline Offline
God Member
*****
Karma: 17
Posts: 522
Ground, ground, always ground
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here a raw blink code for due revealing SAM3X8E registers used.

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

// Pin 13 mask
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   
}
Logged

UK
Offline Offline
God Member
*****
Karma: 1
Posts: 530
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
uint32_t led = (0b00001000000000000000000000000000);

Still, why 1U? 1unsigned?
« Last Edit: August 15, 2013, 05:23:31 pm by jtw11 » Logged

Venezuela
Offline Offline
God Member
*****
Karma: 17
Posts: 522
Ground, ground, always ground
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

UK
Offline Offline
God Member
*****
Karma: 1
Posts: 530
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah, that makes sense - i'll read up a little more, but thanks.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@Palliser  is there any documentation that describes how to write directly to these 3X8E ports PIOA thru PIOF? 

Code:
   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.
Logged

Nashville Tennessee, USA
Offline Offline
Sr. Member
****
Karma: 15
Posts: 367
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: