Arduino DUE Insights - SPI, port manipulation and interrupt timers

After using multiple posts on this forum to help me understand how to start programming an Arduino DUE I thought I'd post up my working code here to potentially help others in a similar situation.

I am looking to port over my 8x8x8 RGB LED cube code from an Arduino MEGA to an Arduino DUE for faster processing and more memory.

To enable this I needed to understand how to code on the DUE for SPI transfer, direct port manipulation(as faster than digitalWrite) and enabling timer interrupts.

A few additional watch outs:

The Arduino DUE runs at 3.3V as opposed to 5V on the MEGA. As my cube is running at 5V I successfully used a level converter (https://www.sparkfun.com/products/12009) to upscale the MOSI, Clock, Output Enable and Latch lines from the DUE to the 74HC595 5V shift registers driving my cube.
The SPI pins on the DUE are broken out on a separate header rather - this is a great resource when using the DUE (Due pinout diagram - Arduino Due - Arduino Forum)
Writing to ports directly on a DUE is very different - you write to a set (HIGH) register and a separate clear (LOW) register - the ports and bits are identified on the pinout diagrams above

Many thanks to all the support on this forum that helped me get insights into the very different coding required to enable these functionalities - you may recognise some of the coding as direct copies from previous explanations shared here

I hope this is of help to others

James

Due_Test_Int.ino (2.6 KB)

One you forgot: If you are using the hardware SPI on the Due, do not set D4 or D10 as OUTPUT. This will cause a CPU pin conflict. If you want to disable SPI devices using those pins as slave selects, set them to HIGH only.

Thanks a lot for the helpful example. I have been suffering quite a bit anld lost time trying to get the SPI up and running on the DUE. Afther some more testing I found in your sample code a small mistake:

The SPI.begin(10) should actually be first in the init statment, otherwise you initialize the SPI with default values, so :


// Set up SPI - notice Chip Select pin 10 identified in the functions (could also be 4 or 52)
SPI.setBitOrder(10,MSBFIRST);// Chip Select, Most Significant Bit First
SPI.setDataMode(10,SPI_MODE0);// Chip select, Mode 0 Rising edge of data
SPI.setClockDivider(10,1);//Chip Select, Run the data in at Master Clock speed 84MHz/1 - 84MHz
SPI.begin(10); //Chip Select


SHOULD BECOME:


// Set up SPI - notice Chip Select pin 10 identified in the functions (could also be 4 or 52)
SPI.begin(10); //Chip Select
SPI.setBitOrder(10,MSBFIRST);// Chip Select, Most Significant Bit First
SPI.setDataMode(10,SPI_MODE0);// Chip select, Mode 0 Rising edge of data
SPI.setClockDivider(10,1);//Chip Select, Run the data in at Master Clock speed 84MHz/1 - 84MHz


only like this the configurations lie LSB or MSB first and clock divider os SPI_MODE0 are considered. In your case you seem to have the default values, so it does not matter, but I needed a other values in my case.

Hope it helps somebody