SPI on Arduino Due

Hello, small question. Referring to SPI pins on Uno or Mega is easy (Mega mosi=51, miso=50). But how do you name the Mosi and Miso for the Due?

Thanks,
Hugo

Use the SPI connector in the middle of the board. See the diagram in the first post at the top of this forum.

MOSI/MISO isn't copied on any other pin on the Due.

I have an ADXL345 accelerometer evaluation board. I am able to interface with it very well with my Arduino Uno. I can write registers to it as well as read data from the device registers without any issues.

I started using Arduino Due yesterday, and I seem to not understand how to put values into the register. The page on the website is very confusing to me “http://arduino.cc/en/Reference/DueExtendedSPI”

Could someone please give me an example of how to input a value on to the register?

You don't name them, the SPI hardware is completely different, just look at the Due SPI examples.

[ actually there don't appear to be any! - look at the docs http://arduino.cc/en/Reference/DueExtendedSPI ]

I am setting up my DUE with the following code:

void setup() { SPI.begin(4); SPI.setClockDivider(4,21); SPI.setDataMode(4,SPI_MODE3); SPI.setBitOrder(4,MSBFIRST); Serial.begin(9600);

// Want to put in inside $0x2D the value 0x08 SPI.transfer(4, 0x2D, SPI_CONTINUE); SPI.transfer(4, 0x08, SPI_CONTINUE);

// Want to put in inside $0x31 the value 0x03 SPI.transfer(4, 0x31, SPI_CONTINUE); SPI.transfer(4, 0x03, SPI_CONTINUE); }

// AM I DOING THIS RIGHT?

void loop() { // I want to read from 16-bit data from $0x36 & $0x37 byte response = SPI.transfer(4, 0xB6, SPI_CONTINUE); byte response1 = SPI.transfer(4, 0x00); }

// AM I DOING THIS RIGHT?

You probably don't want the continue on the second transfer of each register write. This controls the chip select action (stay low or revert to high). Normally each register access would be a single SPI transaction (but check the datasheet, devices differ - this should also tell you which mode to use (normally mode0 is right).

Thanks MarkT.

I modified:

// Want to put in inside $0x2D the value 0x08
SPI.transfer(4, 0x2D, SPI_CONTINUE);
SPI.transfer(4, 0x08, SPI_CONTINUE);

to

// Want to put in inside $0x2D the value 0x08
SPI.transfer(4, 0x2D, SPI_CONTINUE);
SPI.transfer(4, 0x08);

and it works.

Great! Did you check the mode was right (using the wrong mode can seem to work but be either unreliable or shift your data one bit position).

I am trying to get SPI communication working on Arduino Due. However I seem not to get any activity on the SPI pins. I tried to copy the example above, but so far I have no success.

I made a small test program to check the SPI signals with the scope:


#include <SPI.h>

int testPin = 22;

void setup() {
pinMode(testPin, OUTPUT);

// initialize SPI:
SPI.begin(4);
SPI.setClockDivider(4,8);
SPI.setDataMode(4,SPI_MODE0);
SPI.setBitOrder(4,MSBFIRST); // Am I doing this right? Anything missing?

}

void loop() {

// I whant to write 0x55 on the SPI port

SPI.transfer(4, 0x55); // am I doing this right ?

digitalWrite(testPin, 1);
delay(100);

SPI.transfer(4, 0xAA);

digitalWrite(testPin, 0);
delay(100);
}


Question: Am I supposed to see pin 4 (nCS) going low once I issue the “SPI.transfer(4, 0x55);” command, or do I need to configure this pin in some additional way?

Also I can not see andy activity on the SCLK pin and the MOSI pins of the Due.

Any help or suggestions what I am missing would be very welcome.