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?
- why is the code not working?
- How do I transfer continuous 16 clock cycles?