Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 7 of 7

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

  1. #1

    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.

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    4,565
    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.

  3. #3
    The problem is that SPI.setDataMode is deprecated by Arduino see https://www.arduino.cc/en/Reference/SPISetDataMode and this behaviour causes the slave (LTC 68111) to ignore the first message because the clock is not where it should be (HIGH).

  4. #4
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    4,565
    Yes setDataMode is depreciated... Why not just start off like:
    Code:
    SPI.begin();
    SPI.beginTransaction((SPISettings(500000, MSBFIRST, SPI_MODE3));
    SPI.endTransaction();

  5. #5
    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.

  6. #6
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    8,372
    Quote Originally Posted by tecnico.solarboat View Post
    ...
    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().

  7. #7
    Quote Originally Posted by defragster View Post
    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •