This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf52840 SPI clock line contention causing SPI driver to hang

Hello,

I encountered an interesting issue with SPI0 on the nrf52840 that I cannot explain. In short, my SPI bus would stop working shortly after communicating with my slave device. After an extensive investigation and trying different pins to use for SPI, I discovered that the slave device was holding the SPI clock line low. This was causing the Nordic SPI driver to hang in nrfx_spim.c at the line highlighted in green below. I could disconnect the SPI clock line from the slave device and the driver would resume operation without issues. Why does contention on the SPI clock line cause the driver to hang? Should there be some sort of safety timeout here?  I was able to reproduce this issue using the Nordic SPI peripheral example project. As a side note, I have since discovered why the slave device was holding the clock line low but not why the driver gets stuck.

SoftDevice: S140

SDK: 15.0.0

Note: I am using the Rigado BMD-340 Eval Kit which is software and pin compatible with the nrf52840 DK.

Thanks,

Derek

Parents
  • Hi,

    This is due to internal design. In short:

    The clock line is looped back through the pin to the SPI peripheral to ensure that timing of MISO and MOSI are identical, as a side effect this also means that the internal circuitry will not see the clock if the pin is forced low externally, and thereby "hang" until valid clock is present. I guess a serial resistor on the clock line could solve this and/or start an timer that can timeout and application can power cycle the SPI peripheral to recover.

    Best regards,
    Kenneth

Reply
  • Hi,

    This is due to internal design. In short:

    The clock line is looped back through the pin to the SPI peripheral to ensure that timing of MISO and MOSI are identical, as a side effect this also means that the internal circuitry will not see the clock if the pin is forced low externally, and thereby "hang" until valid clock is present. I guess a serial resistor on the clock line could solve this and/or start an timer that can timeout and application can power cycle the SPI peripheral to recover.

    Best regards,
    Kenneth

Children
Related