nrf52840 3-wire spi implementation

Hi Team,

Currently we'd like to use nrf52840 to verify 3-wire spi with our device, in HW side, no connection for MISO pin, I check default nrfSDK, fine spi related example, but haven't seen 3-wire spi configuration or struct related yet. Could you please guide me how to change the underlying driver, thanks a lot!

Best regards.

Parents Reply Children
  • Hi Hmolesworth,

    Thanks for your update, I could find your mentioned above example, sorry I'm not deep familiar with nrf SDK, so I should additionally add these codes in main.c file, right?

    but in default main.c file, related spi configuration already existed as below

    nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
    spi_config.ss_pin = SPI_SS_PIN;
    spi_config.miso_pin = SPI_MISO_PIN;
    spi_config.mosi_pin = SPI_MOSI_PIN;
    spi_config.sck_pin = SPI_SCK_PIN;

  • The bare-metal code replaces all the existing spi code in main as it handles both pin initialisations and transmit/receive of data. To retain the existing spi code in main.c the bare-metal code would not be used but the sequence of switching the tx/rx pin from MOSI mode to MISO mode after the first byte has been sent would have to be added. I don't have a code snippet to hand in that format which does this; maybe replace the existing code with the snippet to verify the 3-wire spi works on the sensor then go back to the older spi code and try changing to replicate that sequence.

  • Hi Hmolesworth,

    Thanks a lot, I will have a try.

  • in your provided code snippet, spi3wTXBuf is not undeclared and clk is not defined to NRF_SPIM0->PSEL.SCK

  • The code was only a guide; here is a more complete snippet which is designed to test an accelerometer in 3-wire SPI mode. This accelerometer works in both 4-wire and 3-wire modes an must be told to switch to 3-wire mode; other 3-wire only sensors would not require that step. This should be the only code in main(), don't enable anything like nrfx spi stuff