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

Disabling/enabling SPI Pins for SD Card

I want to save Power by disabling the SD Card. VCC of the card is already regulated with an external MOSFET switch and controlled by a pin of the nRF. The problem now is, that the SPI data lines still power the SD Card. Therefore, I want to disable them. Is this possible, without having to redo the initialisation process of the SD Card? By the initialisation process I mean the following:

	/**
* @brief  SDC block device definition
* */
NRF_BLOCK_DEV_SDC_DEFINE(
    m_block_dev_sdc,
    NRF_BLOCK_DEV_SDC_CONFIG(
            SDC_SECTOR_SIZE,
            APP_SDCARD_CONFIG(SDC_MOSI_PIN, SDC_MISO_PIN, SDC_SCK_PIN, SDC_CS_PIN)
     ),
     NFR_BLOCK_DEV_INFO_CONFIG("Nordic", "SDC", "1.00")
);
static diskio_blkdev_t drives[] = {
      DISKIO_BLOCKDEV_CONFIG(NRF_BLOCKDEV_BASE_ADDR(m_block_dev_sdc, block_dev), NULL)  };

diskio_blockdev_register(drives, ARRAY_SIZE(drives));

NRF_LOG_INFO("Initializing disk 0 (SDC)...\r\n");


for (uint32_t retries = 3; retries && disk_state; --retries)
{
      disk_state = disk_initialize(0);
}
if(disk_state)
{
     NRF_LOG_INFO("Disk initialization failed.\r\n");
     return false;
}
  • I don't understand how the SPI data lines can power your SD card if you have disconnected VCC. You can try disconnecting the pins of the SPI peripheral by setting the PSEL registers to disable:

    NRF_SPIMx->PSEL.SCK = (SPIM_PSEL_SCK_CONNECT_Disconnected<< SPIM_PSEL_SCK_CONNECT_Pos)
    NRF_SPIMx->PSEL.MOSI = (SPIM_PSEL_MOSI_CONNECT_Disconnected << SPIM_PSEL_MOSI_CONNECT_Pos)
    NRF_SPIMx->PSEL.MISO = (SPIM_PSEL_MISO_CONNECT_Disconnected << SPIM_PSEL_MISO_CONNECT_Pos)
    

    If you are using SPIM peripheral (with EasyDMA support), where x is the SPIM instance used.

    Note that you need to connect the pins again before the SPI can do any transfers again.

  • It is also a mystery to me, why there is still a voltage at the vcc line. But still, I want to disconnect the pins, in order to save power anyhow. But maybe I have to look into my mosfet switch again... I am using the SPI peripheral (SDK 12.3). The disconnect works fine. But now I have problems with enabling it again. I enable the pins like this:

     NRF_SPI1->PSEL.SCK = SDC_SCK_PIN | 0x80000000;
    	NRF_SPI1->PSEL.MISO = SDC_MISO_PIN | 0x80000000;
    	NRF_SPI1->PSEL.MOSI = SDC_MOSI_PIN | 0x80000000;
    

    Is that correct? If I then use the function:

       if (f_mount(&Fatfs,"/",1) != FR_OK)
      {
    		NRF_LOG_INFO("Mount failed.\r\n");
    		return;
      }
    

    It gets stuck in the default_wait_func(void) function in the file diskio_blkdev.c and stays there forever. Am I doing something wrong when reconnecting the pin or do I need to initialize the card again (as shown in the first question)?

  • That is a mistake. I looked in the datasheet and accidentally looked up the register configuration for the SPIM module, not the SPI module. I thought, that the connect bit needs to be set, thats why I added |0x80000000. It is now not stuck anymore in the default_wait_function(void), but it fails to mount the card. The f_mount function returns FR_DISK_ERR. The SPI works after reconnecting, I tested it with a logic analyzer. But the MISO signal stays high constantly.

  • Do you know if the SD card can work after VCC have been cut, without reinitialization?

Related