# SPI on Arduino Due

**URL:** <https://forum.arduino.cc/t/spi-on-arduino-due/296422>\
**Category:** Due\
**Created:** [March 10, 2015, 8:21am UTC](https://forum.arduino.cc/t/spi-on-arduino-due/296422 "2015-03-10T08:21:36Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![waalsh](https://avatars.discourse-cdn.com/v4/letter/w/fbc32d/32.png) [@waalsh](https://forum.arduino.cc/u/waalsh)\
**Post date:** [March 10, 2015, 8:21am UTC](https://forum.arduino.cc/t/spi-on-arduino-due/296422/1 "2015-03-10T08:21:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MorganS](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/morgans/32/218718_2.png) [@MorganS](https://forum.arduino.cc/u/MorganS)\
**Post date:** [March 10, 2015, 10:09am UTC](https://forum.arduino.cc/t/spi-on-arduino-due/296422/2 "2015-03-10T10:09:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 10, 2015, 3:37pm UTC](https://forum.arduino.cc/t/spi-on-arduino-due/296422/3 "2015-03-10T15:37:53Z")

</div>

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](http://arduino.cc/en/Reference/DueExtendedSPI)"

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

---

<div class="post-metadata">

**Author:** ![MarkT](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@MarkT](https://forum.arduino.cc/u/MarkT)\
**Post date:** [March 10, 2015, 6:22pm UTC](https://forum.arduino.cc/t/spi-on-arduino-due/296422/4 "2015-03-10T18:22:23Z")

</div>

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](http://arduino.cc/en/Reference/DueExtendedSPI) ]

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 10, 2015, 8:38pm UTC](https://forum.arduino.cc/t/spi-on-arduino-due/296422/5 "2015-03-10T20:38:42Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![MarkT](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@MarkT](https://forum.arduino.cc/u/MarkT)\
**Post date:** [March 11, 2015, 1:22am UTC](https://forum.arduino.cc/t/spi-on-arduino-due/296422/6 "2015-03-11T01:22:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 11, 2015, 3:52pm UTC](https://forum.arduino.cc/t/spi-on-arduino-due/296422/7 "2015-03-11T15:52:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MarkT](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@MarkT](https://forum.arduino.cc/u/MarkT)\
**Post date:** [March 11, 2015, 4:04pm UTC](https://forum.arduino.cc/t/spi-on-arduino-due/296422/8 "2015-03-11T16:04:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hackhack77](https://avatars.discourse-cdn.com/v4/letter/h/e79b87/32.png) [@hackhack77](https://forum.arduino.cc/u/hackhack77)\
**Post date:** [May 1, 2020, 2:29am UTC](https://forum.arduino.cc/t/spi-on-arduino-due/296422/9 "2020-05-01T02:29:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 5:40pm UTC](https://forum.arduino.cc/t/spi-on-arduino-due/296422/10 "2021-05-06T17:40:03Z")

</div>


