I'm trying to get spi communication to work on my due, but I am getting some unexpected results. I know how to use SPI on the Uno, Nano and Mega board but somethings happening to the Due. I connected a logic analyzer to the spi header (except for the 5v pin) and told the due to send 0xAA. I tried using the old API (https://www.arduino.cc/en/Reference/DueExtendedSPI) and the new API (https://www.arduino.cc/en/Tutorial/SPITransaction), but both yield different and wrong results. When I use the new API the due lowers the CS for one clock cycle so it is not transmitting 8 bits but 4bits or one bit. When I use the old API the due sends for bits then raises the CS. What am I doing wrong?

#include <SPI.h>
// The setup() function runs once each time the micro-controller starts
void setup()
    //Initialize serial and wait for port to open:
    while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB
    test area
    SPI.begin(52);         // SPI Module 'wake up'
    SPI.setClockDivider(52, SPI_CLOCK_DIV128 );
    SPI.setDataMode(52, SPI_MODE0);
    SPI.setBitOrder(52, MSBFIRST);
    delay(200);          // SPI delay for initialization
    SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0)); // SPI setup SPI communication

    while (true)
        SPI.transfer(52, 0xAA, SPI_LAST);

void loop()

Simply put the code works below works, just not on a due and the only thing in the system that changes is the the board(nano to due) what can I do to make it work on a due?

SPI.beginTransaction(SPISettings(500000, MSBFIRST, SPI_MODE0)); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.