Parallel Pin Control


I have a pretty specific Question about how to address pins in parallel.

If i send the value 55 or "110111" to PIO_SODR (C) or this address 0x400E1230 i set PIN 33 ( PIN C1 ) on my Arduino Due Board. If i send 60 PIN 35 ( PIN C3 ) is set. Now i want to set more than one pin at once. But i couldnt find any ressource that tells me how the value i send will get interpreted by PIOC. I tried sendind 115 ( 60+55 ) to set C1 and C3. Now i used 60 xor 55 = 11 and i could set C1 and C3. But the xor doesnt work at different values.

So my question is:

How do i axcess different pin patterns inside the PIO (C).

I got the PIN-OUT Diagramm but there are only the values for setting one specific PIN. Is there a special method to calculate the values from those pinValues at the PinOut-Diagramm.

Hello Demokra,

I started lerning Due with exactly this issue.
And it has taken several hours to understand, how to handle such things.
It is rather easy, if You understand the background of software development. There are a lot of header files (*.h) describing the memory organisation of the microcontroller.
Via C(C++) you may address all the registers of the microcontroller by predefined pointers.
So e.g. REG_PIOA_ODSR points to the Output Data Status Register of Port A.

To start most easy:
Use pinMode(i, OUTPUT) for setting pin i of the Due to be used for output.
Look into the schematic of the board, to map the pins of the board to the ports of the mikrocontroller.
To set 3 bits of port A at the same time, which are connected to the board pins > 22, and not to change any other bit of port A, use e.g.
REG_PIOA_ODSR |= 0xC080;
To reset these 3 bits without changing any other bit, use
REG_PIOA_ODSR &= ~0xC080;

In the same manner You can initialize the port bits by using REG_PIOA_PER, REG_PIOA_OER, etc. instead of calling pinMode(…).
Look at the databook of the SAM3X (Atmel) for the meaning of PER, OER, etc.
Even You can define Your own pointers (pointers to 32 bit) to the registers by using the physical memory addresses given in that databook. But they are already defined somewhere in \arduino-1.5.2\hardware\arduino\sam\system\CMSIS\Device\ATMEL\sam3xa\include\instance\instance_pioa.h

I hope, this helps You.

I actually found the answer yesterday. Inside of the arduino-1.5.2\hardware\arduino\sam\system\CMSIS\Device\ATMEL\sam3xa\include\instance\instance_pioc.h and some other files in that directory. My biggest problem was that it didnt start with C1 inside of the processor. Basically you can use the Atmel Processor from C0 - C31 but i thought it started with C1 so first bit = C1 but the Due only has 25 C channels active. So the first channel C1 is the 2nd bit to send to SODR or the other channels. At the moment i just throw 32 bit inside of PIO_SODR and PIO_CODR to set and clear the lines of the Pins i need.

Thank you very much for your help.

You might post a code snippet of what you got working to help others trying to do the same).

So you have a 32 bit number with which you can address the : Register->output then the register bank → A,B,C and then ->pin that interests you? Or you use a different 32-bit every time?

If you just want to set some bits you can use the PIO_SODR register, as in

PIOC->PIO_SODR = 0xC080 ; // Set Output Data Register

If just clearing bits:

PIOC->PIO_CODR = 0xC080 ; // Clear Output Data Register

This saves on masking operations. Those two registers are write-only and the current state is automatically reflected on the relevant PIO_ODSR.