SPI.begin() does not set Clock HIGH in SPI_MODE3

If SPI settings are set to SPI_MODE3 clock signal should idle at HIGH but before doing:

Code:
SPI.beginTransaction(LTC6811_SPI_config);

and after doing SPI.begin(); being

Code:
LTC6811_SPI_config = SPISettings LTC6811_SPI_config(SPISettings(500000, MSBFIRST, SPI_MODE3));


the clock is idling LOW.

The problem of this behaviour is that the first message is ignored by the slave. After doing
Code:
SPI.beginTransaction(LTC6811_SPI_config);
for the first time the clock will start idling at HIGH as expected.

This bug is present at least with the Teensy 3.2 using VSCode and Platformio but I think this may be related to the Arduino SPI library itself since the function void SPIClass::begin() in the Arduino SPI library only does pinMode(SCK, OUTPUT); which by default sets the SCK pin LOW. This function should take into consideration the SPI_MODE that the user whats to operate in.
 
I believe that the system will only take it into effect if you ask it to... That is when you do the SPI.beginTransaction(), with a configuration that sets it to that state.

Alternatively you can I believe still do something like SPI.setDataMode(SPI_MODE3);
But again the beginTransaction is the preferred way.
 
Yes setDataMode is depreciated... Why not just start off like:
Code:
SPI.begin();
SPI.beginTransaction((SPISettings(500000, MSBFIRST, SPI_MODE3));
SPI.endTransaction();
 
I didn't though of that. I will give it a try when I'm near the board. Afterwards I will post the result.

Nonetheless I think this should be considered as a bug. SPI.begin() should put the bus in its operating state by its own.
 
...
Nonetheless I think this should be considered as a bug. SPI.begin() should put the bus in its operating state by its own.

Just observing … SPI is a multi device bus. Until beginTransaction() the device specific params to define 'put the bus in its operating state' are not known, that is part of the value of beginTransaction().
 
Just observing … SPI is a multi device bus. Until beginTransaction() the device specific params to define 'put the bus in its operating state' are not known, that is part of the value of beginTransaction().

Good point you have there. I didn't thought of that because I have only one device on the bus. That should be the reason why SPI.begin() does not take care of the configurations.
 
Back
Top