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

nRF51822 SPI with more than one CS signal

how can I program SPI to select more than only one slave device with any GPIO ?

SPI Routine "spi_master_int" can select SPI0 or SPI1 only with one dedicated GPIO as Slave-Select Signal.

  • Hi Reinhard,

    The SPI master module only sets CLK/MISO/MOSI. It does not hard-code the chip select. The chip-select is a GPIO (or several) that must be handled in your application to differentiate between several SPI-slaves.

    Very basic pseudo code:

    CS_SLAVE_0 = active; SPI_COMMUNICATION(); CS_SLAVE_0 = inactive;

    CS_SLAVE_1 = active: SPI_COMMUNICATION(); CS_SLAVE_1 = inactive;

    Best regards Håkon

  • I think Reinhard is referring to the spi configuration source from the SDK (spi_master.c), which expects SPI_PSELSS0 or SPI_PSELSS1 to be defined to a specific GPIO line. spi_master_tx_rx asserts the defined GPIO line during the SPI transaction.

    If you have a multidrop SPI bus, then this clearly won't work. But it would be a trivial matter to adapt your own version of spi_master_tx_rx that took the SS line as a parameter (assuming CPOL and CPHA are still the same across your devices, of course).

  • I don't think this is accurate, at least not with the 6.1 SDK. The spi_master module takes a chip select pin as a parameter. It would be great if you could just pass SPI_PIN_DISCONNECTED and have the module ignore the select pin so the app can control it, but if you do that it looks like the module will just treat it as a valid pin number and call the GPIO config on it.

Related