Enabling pins of Arduino Due with direct port manipulation I want to enable pin 13 on my SAM3X8E using direct port manipulation. On this chip the pin is bit 27 in port B, so I used PIOB-&gt;PIO_PER = 1&lt;&lt;27; to enable this pin, but it doesn't work. This pin keeps at 3.08V, the default value of non-initialized pins.

Here's my complete code:

#include &lt;asf.h&gt;

int main (void) {
  // Insert system clock initialization code here (sysclk_init()).
  board_init();
  sysclk_init();
  delay_init(sysclk_get_cpu_hz());
  PIOB-&gt;PIO_PER = 1&lt;&lt;27;
  PIOB-&gt;PIO_OER = 1&lt;&lt;27;
  while(1) {
    REG_PIOB_ODSR = 1&lt;&lt;27;
    delay_ms(1000);
    REG_PIOB_ODSR = 0&lt;&lt;27;
    delay_ms(1000);     
  }
}


Can anyone tell me how I can get this to work?
I suggest the following test:  Use REG_PIOB_SODR = 1&lt;&lt;27; to set the bit, and  REG_PIOB_CODR = 1&lt;&lt;27; to clear it.  If that works ok, see about enabling synchronous data output via the port's PIO_OWSR register.  (If it doesn't work ok, perhaps review section 31.6, “I/O Lines Programming Example”, on page 629 of Atmel document 11057, the Cortex datasheet.)

Section 31.5.5, “Synchronous Data Output”, on page 623 says in part:


  After reset, the synchronous data output is disabled on all the I/O lines as PIO_OWSR resets at 0x0.


I imagine that writes to REG_PIOB_SODR and  REG_PIOB_CODR should have effect after you enabled output by setting bits in PIOB->PIO_PER and PIOB->PIO_OER, which you did.  However, with the bit in PIO_OWSR being clear, synchronous data output isn't available, so writes to REG_PIOB_ODSR have no effect.