Set Arduino Due SPI mode.

Hi I want to communicate with an arduino Due with a digital potentiometer. For this I should communicate in SPI_mode1 but either way I always try only SPI_mode2 or SPI_mode3 (I don't know which of the two). I have already managed to communicate with the digital potentiometer with Arduino nano. Then I used these settings:

  SPI.beginTransaction(SPISettings(SPI_CLOCK_DIV4, MSBFIRST, SPI_MODE1));

This was the last time I tried this code. But according to the oscilloscope, it works much faster and not in SPI_mode1.

#include <SPI.h>

const int slaveSelectPin = 10;

void setup() 
{
  //pinMode (slaveSelectPin, OUTPUT);
  Serial.begin(9600);
  SPI.begin(slaveSelectPin);
  SPI.setDataMode(slaveSelectPin, SPI_MODE1);
  SPI.setClockDivider(slaveSelectPin, 21);
  //digitalWrite(slaveSelectPin,LOW);
  SPI.transfer(slaveSelectPin , 0x18 , SPI_CONTINUE);
  SPI.transfer(slaveSelectPin , 0x06);
  //digitalWrite(slaveSelectPin,HIGH);
  SPI.endTransaction();
}

void loop() 
{
    digitalPotWrite(1022);
    delay(200);
}

void digitalPotWrite(unsigned int val) {
  byte highbyte = (val >> 8) + 0x04; //high wiper byte + command
  byte lowbyte = val & 0xFF;
  SPI.setDataMode(slaveSelectPin, SPI_MODE1);
  SPI.setClockDivider(slaveSelectPin, 21);
  SPI.transfer(slaveSelectPin , highbyte , SPI_CONTINUE); //send wiper data high byte
  SPI.transfer(slaveSelectPin , lowbyte); //send wiper data low byte
  SPI.endTransaction();
}

How can I switch to SPI_mode1?

(My tongue is not English, sorry for the resulting problems. )

Hi
With this I have already managed to set the parameters of the SPI properly, but even this does not change the mode.

  SPISettings settings (21, MSBFIRST, SPI_MODE1); 
  SPI.beginTransaction(slaveSelectPin, settings);

Resolved

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.