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

app_sdc_init() not allowed to use XL1 (P0.0) as sck pin? / Proper setup of SD Card with other SPI usage

NRF52840, S140, SDK 14.2

I am trying to write to an SD Card. But whenever I insert the card, I get a failure on ASSERT. I believe this is because I am using P0.0 as the SCK pin, and anything &-ed with 0 is 0. 

Does this mean I am not allowed to use the 0.0 SCK pin? That seems wrong. Was this fixed in a later SDK update? 

When I comment out the &&  p_config->sck_pin, I no longer get the Assert. however, I get this error instead (triggered from nrf_drv_spi_init()) 

which is NRF_ERROR_INVALID_STATE (Invalid state, operation disallowed in this state)

I suspect this is because now that I am trying to use the SD Card, there are 2 SPI resources on the system. I configured the SD Card as follows:

Whereas the other SPI device was configured "normally":

 (i do app_error_check in the fn that calls spi_config). 

This error happens and the application freezes immediately when I use SPI 0 for the second SPI device. When I use SPI 1 for the second SPI device without changing the GPIO pins, I get strange behavior: my main loop stops running entirely (seems to hit power manage and just stop? but I have interrupts coming in), and garbage data (instead of the data that is normally sent) goes out on my SPI line to the second device. I am able to still connect over BLE though. Why is this happening?

I read this and this. My other questions:

  1. What SPI instance is the SD Card using? SPI 0? 
  2. Is each SPI instance supposed to use its own separate GPIO?

If this is the case that I have to use a separate SPI instance with separate GPIO, it is a bit disappointing that NRF doesn't let you use SPI for its intended purpose (multiplexing data on a bus). I am a little low on board space and would prefer not to route 3 extra lines if possible. Please advise. What should my path forward be, to use SPI with SD card and a different device?

Thank you!

Parents
  • Hi,

    1. The SPI instance is configurable through the sdk_config.h define APP_SDCARD_SPI_INSTANCE.
    2. Yes, each SPI instance requires its own set of GPIOs, if multiple instances are enabled at the same time. The serial peripherals of the nRF52 ICs can be configured to use any GPIO, so it is possible to configure different SPI instances to use the same GPIOs, given that you first disable any other SPI instances configured to use these GPIOs.
    If this is the case that I have to use a separate SPI instance with separate GPIO, it is a bit disappointing that NRF doesn't let you use SPI for its intended purpose (multiplexing data on a bus).

    This is not a limitation of the SPI peripheral in the chip itself, it is just how the SD Card library is written. You are free to use the SPI peripheral for more than one slave by controlling the CSN/SS pin from your code. As I mention in the second thread you linked, it is possible to modify the library to provide the SPI instance from outside the library, to utilize it for other SPI devices as well. Another option is to uninitialize the app_sdcard library before initializing the SPI driver for other operations, and similarly uninitialize the SPI driver before re-enabling the app_sdcard library.

    Best regards,
    Jørgen

  • Thank you Jorgen. I will have to think through these options.

    Can you also answer my first question about not being able to use P0.0 as the clock if you use the SD Card Library? Is this a known bug / is it fixed in later SDKs?

Reply Children
No Data
Related