Hello!
Does the SDK support a 3-wire SPI interface with bi-directional communication?
Like this:
Thanks!
Hello!
Does the SDK support a 3-wire SPI interface with bi-directional communication?
Like this:
Thanks!
No initially, but you can connect the MISO and MOSI pins externally with a resistor.
That would require a hardware change in our custom board
Ok, thanks for the answer
Yes you can :-) This is a bare-metal example, but the same idea can be used with the Nordic drivers.
Start in 3-wire command transmit; Send the command, then configure for 3-wire receive:
// Send 3-wire whoami command byte (1 byte only) // Connect output drive, connect 1-wire rx/tx output to MOSI NRF_SPIM0->PSEL.MISO = 0xFFFFFFFF; // MISOPIN; NRF_SPIM0->PSEL.MOSI = MOSIPIN; NRF_GPIO->PIN_CNF[MOSIPIN] = 1; // output NRF_SPIM0->TXD.PTR = (uint32_t)spi3wTXBuf; NRF_SPIM0->TXD.MAXCNT = 1; NRF_SPIM0->RXD.PTR = NULL; NRF_SPIM0->RXD.MAXCNT = 0; NRF_SPIM0->EVENTS_ENDTX = 0; NRF_GPIO->OUTCLR = 1 << CSPIN; // drive cs low to initiate spi comm NRF_SPIM0->TASKS_START = 1; while(!NRF_SPIM0->EVENTS_ENDTX); // last byte transmitted // Manual says disable SPI before changing pins, but actually doesn't matter NRF_SPIM0->ENABLE = 0; // disable SPI // Disconnect output drive, connect 1-wire rx/tx input to MISO NRF_SPIM0->PSEL.MOSI = 0xFFFFFFFFUL; // MOSIPIN; NRF_GPIO->PIN_CNF[MOSIPIN] = 0; // input pin, input buffer connected, no pull, S0S1, sense disabled NRF_SPIM0->PSEL.MISO = MOSIPIN; // MISOPIN; NRF_SPIM0->ENABLE = 7; // enable SPI if it was disabled
This works fine; on some SPI devices remember the internal 3-wire register mode has to be set first before reading.
We rather not access the registers directly in our code, but thanks for the answer
We ended using the same SPI instance with different pins, we just need to enable/disable it every time we switch the device we are talking to
You can try this driver here that supports 3 wires directly no resistor require
https://github.com/IOsonata/IOsonata/blob/master/ARM/Nordic/src/spi_nrfx.cpp