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.
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.
Searched a lot but couldn't find a answer.
Section 32 in the processor data sheet tells you all about this.
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.
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
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
All sorts of nifty #defines there.
ANOTHER EDIT: Try
That looks like it has #defines for all the IO.
@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.
There's two ways of doing this that I've found so far. One is:
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:
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.
@stimmer i guess the second option is better connecting wires all over the place like in the first option will be a little irritating.
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).
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.
Does anyone know how to enable input on the port?