Arduino Due SPI Clock not changing

I am trying to use SPI on the Arduino Due rev3 located at ICSP header/SPI. I set it up based on the library, but I don't seem to have control SPI clock, clock phase, frequency etc....On power up, the clock pin is low, and it is always low to high phase when I specifically changed the mode to SPI_MODE2. It is disregarding it.

In the setup() function I dump the code below . I have tried the different ways to set it up, but all I get is a clock on Pin2 (see references below) 4MHz, MODE0, and I can't control the phase or the frequency.

//SPISettings mySetting(1000000, MSBFIRST, SPI_MODE3);
  //SPI.beginTransaction(mySetting);
  //SPI.beginTransaction(SPISettings(5000000, MSBFIRST, SPI_MODE0));
  SPI.setClockDivider(84);                      //84MHz/84 = 1MHz
  SPI.setDataMode(SPI_MODE2);
  SPI.setBitOrder(MSBFIRST);
  SPI.begin();  

void ReadADC(char AdcChannel)
{
  CtrlReg = (AdcChannel << 3);                              //Select the ADC channel by writing the register
  digitalWrite(AdcCSPin, LOW);
  Temp1=SPI.transfer16(CtrlReg);                        //Bring CS low
  digitalWrite(AdcCSPin, HIGH);
}  

The MCU SPI CLK is at MCU PIN PA27.. Is there anything that I am doing wrong?
why wouldn't this code work? Is there any underlying setup I need to do first?

When I put the scope on the clock, it is coming out, and I see two transfer of 8 bits. I thought the SPI.tranfer16 would do 16 clock cycles without any delays in between. Is there a way to do 16 bit transfer without delays?

  1. why is the code not working?
  2. How do I transfer continuous 16 clock cycles?

begin() must be called before setDataMode and others.

1 Like

OK then...

Do you know how to transmit 16 bits continously instead of two transfers of 8bits?

transfer16()

That transfers in two packets of 8 bits with an annoying delay between the packets. I mean 16clock cycles uninterrupted with the same period. Thanks for replying.

Arduino code does not support real 16 bit transfers, you have to implement it yourself. You can change word size in SPI Chip Select Register aka SPI_CSR and I assume you have to implement your own transfer function.

ps: I understand if this operation is annoying, but please tell me at the end if it was worth the work invested

Sadly I have to use this arduino to characterize time sensitive adc acquisitions not for hobbies for real hardware which I cannot discuss here. Suffice to say for a lot of folks this is adequate. I happen to not be in 98 percentile where every microsecond matters. Thank you for the reply.

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