I have built a prototype that has two SPI slave devices connected to it and it works perfectly. I have now tried to add an SPI SD card aswell by following the FatFS example in SDK 12.3 but this seems to be in conflict with my existing initialisation of the SPI bus. Specifically, the SPI bus is also initialised in app_sdcard.c and expects an explicit CS pin to be specified. With my code, I am handling CS myself in order to allow multiple slave devices. The specification of bus speed is also in conflict.
What is the Nordic recommended way of supporting multiple SPI slave devices including an SD card on a single SPI bus?
Has anyone managed to get this working without modifying the SDK code?
I can't see any way you can solve this without modifying the SDK code. You could modify app_sdcard function app_sdc_init to take a SPI instance as parameter, and only initialize the SPI driver if this parameter is set to NULL, and else use the instance passed in the parameter. This would require you to relay the SPI instance through all blockdev function calls if you are using the FatFS example. You would also have to expose the spi_handler in app_sdcard through the header files, and relay SPI events related to SDCard, from default SPI handler to the app_sdcard spi_handler. app_sdcard also control CS pin manually, so his should not be conflicting with your other devices. The frequency of the SPI interface can be changed using the SPI HAL function nrf_spi_frequency_set().
Do you not have more available serial instances for addind a separate SPI interface for the SD card? That would propably be the simplest solution.
Ah OK! Thanks Jorgen - I will see if I can move the SD card to a separate instance...
What do you mean by separate SPI interface? Like a different SPI Bus with different MOSI/MISO/SCLK? Is there no easy way to share the same bus with SD card?
Yes, a separate SPI bus, with its own MOSI/MISO/CLK pins. The nRF52832 supports up to 3 SPIM instances (SPIM0-SPIM2). The SD-Card libraries are initializing the SPI instance internally and do not provide any API to pass an existing SPI instance to the library. This could be achieved by rewriting the libraries, but it is not supported out of the box.