Go Down

Topic: Arduino Due Access Port (Read 2970 times) previous topic - next topic

tarun31

Hi Guys,
Have a small doubt regarding the Due? How do we access the port to output a byte of data in parallel not using the serial port. Searched a lot but couldn't find a answer.

Thanks,
Tarun

Grumpy_Mike

Quote
How do we access the port to output a byte of data in paralle

Well it is a 32 bit processor so bytes are not on the menu.

Quote
Searched a lot but couldn't find a answer.

Section 32 in the processor data sheet tells you all about this.

tarun31

I understand that it is a 32 bit uC but if i wanted to output a byte of data in parallel what is the best way to do it without having to write a seperate function to seperate the byte into bits and then outputting seperately using digitalwrite for each pin. Any help would be very useful.
Thanks

Graynomad

#3
Dec 17, 2012, 01:32 pm Last Edit: Dec 17, 2012, 01:42 pm by Graynomad Reason: 1
I'm not that familiar with the SAM, but on an LPC to set any say 8 bits on a port you would do something like this

Code: [Select]
LPC_GPIO0->MASK = ~mask;
LPC_GPIO0->OUT = val << shift_bits;
LPC_GPIO0->MASK = mask;


IIRC the SAM code though does not uses pointers like that, it has direct defines like GPIO0_MASK etc.

Have a look through the Arduino-supplied source code for examples, there must be heaps.

Surely there's a SAM guru here that could answer this off the top of his head.

EDIT: Have a look in and around

<your install>\hardware\arduino\sam\system\CMSIS\Device\ATMEL\sam3xa\include\sam3x4e.h

All sorts of nifty #defines there.

ANOTHER EDIT: Try

<your install>\hardware\arduino\sam\system\CMSIS\Device\ATMEL\sam3xa\include\instance\instance_pioa.h

That looks like it has #defines for all the IO.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

tarun31

@Graynomad  Thanks a lot. Went through the header file and i found the required registers. Will give it a try and get back. Should do the work.

Tarun

stimmer

There's two ways of doing this that I've found so far. One is:
Code: [Select]

  REG_PIOD_OWER= 0xff; // you only need to do this once
  REG_PIOD_ODSR = data;

Output is all over the place though - pins 25,26,27,28,14,15,29,11 (I think). Take a look at Graynomad's Due pinout diagram to see exactly where (Port D pins 0-7)

The other way is more convenient for wiring and the code is only slightly more complicated:
Code: [Select]

  REG_PIOC_OWER= 0x3fc; // again you should only need this once
  REG_PIOC_ODSR = data << 2;

and the pins are 34,35,36,37,38,39,40,41 which are all nicely together on the bottom connector.
Due VGA library - http://arduino.cc/forum/index.php/topic,150517.0.html

tarun31

@stimmer i guess the second option is better connecting wires all over the place like in the first option will be a little irritating.

Thanks,
Tarun

tarun31

yep this does it. this code will blink leds connected to pins 5 and 6 on the board. Thanks all for your help and pointing me in the right direction. But i feel it would be great if Arduino itself could give support to access a port as a whole atleast if not in the due in the other arduino's as well so that we can easily output a byte or a nibble of data in parallel where required (correct me if i'm wrong assuming there is no support for such fucntioniality in arduino yet).

void setup()
{  REG_PIOC_OER=0x03000000;
  REG_PIOC_OWER=0x03000000;
}


void loop()
{
  REG_PIOC_ODSR=0x03000000;
delay(2000);
REG_PIOC_ODSR=0x00000000;
delay(2000);

}

Graynomad

I think that such support is the last thing on Arduino's mind.

There has been a couple of threads about "pin groups" and I think some code/libraries written by members.

_____
Rob
Rob Gray aka the GRAYnomad www.robgray.com

dishimwe

Does anyone know how to enable input on the port?

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy