1

I needed SPI with CPOL=1 and CPHA=1. I read, that I could achieve this via SPI_MODE3. Further, I read to put the CS low and CS high code after SPI.beginTransaction(...) and before SPI.endTransaction() (See official doc). But the result does not look right. Minimal example program:

void setup() {   // put your setup code here, to run once:
    pinMode(52, OUTPUT); // CS high
    digitalWrite(52, 1);
}

void spi_transfer() {
    uint8_t buffer[] = {0, 0};

    delayMicroseconds(1);
    SPI.begin();
    SPI.beginTransaction(SPISettings(SPI_BAUD, MSBFIRST, SPI_MODE3));
    delayMicroseconds(1);
    
    digitalWrite(52, 0); // CS Low
    delayMicroseconds(1);

    SPI.transfer(buffer, 2); // Data
    delayMicroseconds(1);

    digitalWrite(52, 1); // CS High
    delayMicroseconds(1);

    SPI.endTransaction();
    SPI.end();
    delayMicroseconds(1);
}

void loop()
{
  spi_transfer();
}

Oscilloscope picture of SPI traffic

In yellow we see the CS signal (I use pin D52). In lila we see the clock signal. To my understanding, this is not CPOL=1, as the Clock signal is low when the chip select goes low. To my understanding, this is CPOL=0.

Is there a proper way to handle this? Setting CS outside of the begin/end Transfer would make the whole concept a bit superfluous.

1
  • it looks like the clock idles high ... it goes low before data transfer and returns to idle high after the transfer ... the second clock edge(rising) latches data
    – jsotola
    Sep 15, 2022 at 1:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.