Pages: [1]   Go Down
Author Topic: Arduino Due Access Port  (Read 2117 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 508
Posts: 31416
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8439
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
« Last Edit: December 17, 2012, 07:42:59 am by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

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

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

Online Online
God Member
*****
Karma: 32
Posts: 506
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There's two ways of doing this that I've found so far. One is:
Code:
  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:
  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.
Logged


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

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

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

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);

}
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8439
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Rob Gray aka the GRAYnomad www.robgray.com

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

Does anyone know how to enable input on the port?
Logged

Pages: [1]   Go Up
Jump to: