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

UNABLE TO GET fatfs_pca10028 EXAMPLE FROM nRF5_SDK_12.3.0 TO WORK ON nRF51822 BOARD

Hi All,

I am using the nRF51822 board and have it connected to a micro SD card shield using SPI.

I have not changed anything in the example file with the exception of redefining the pins in the main.c file to the following (according to the table here: http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v12.2.0%2Fapp_sdcard_example.html&cp=4_0_4_4_5_30):

#define SDC_SCK_PIN 29 ///< SDC serial clock (SCK) pin.
#define SDC_MOSI_PIN 25 ///< SDC serial data in (DI) pin.
#define SDC_MISO_PIN 28 ///< SDC serial data out (DO) pin.
#define SDC_CS_PIN 24 ///< SDC chip select (CS) pin.

The project builds with zero errors or warnings but upon loading, the following is output to PuTTY:

APP:INFO:
FATFS example.

APP:INFO:Initializing disk 0 (SDC)...
APP:INFO:Capacity: 30 MB
APP:INFO:Mounting volume...
APP:INFO:Mount failed.

I have tried using a different micro SD card but got the following output:

APP:INFO:
FATFS example.

APP:INFO:Initializing disk 0 (SDC)...
APP:INFO:Disk initialization failed.

I have taken a look at the following thread and tried lowering the SPI frequency to 125 kHz as recommended but the output was exactly the same for both SD cards.

https://devzone.nordicsemi.com/f/nordic-q-a/25951/sd-card-example-not-working-fine/102224#102224

The f_mount function seems to be returning "FR_INVALID_DRIVE". What could be causing this?

I have also read that the MOSI and SCK pins might need to be set to "high drive" according to this thread:

https://devzone.nordicsemi.com/f/nordic-q-a/34401/fatfs-example-does-not-work-with-every-sd-card/133317#133317

I added the following code before the fatfs_example() function in main.c in order to set the pins to "high drive" (although I'm not entirely sure this is correct):

nrf_gpio_cfg(SDC_SCK_PIN,
NRF_GPIO_PIN_DIR_OUTPUT,
NRF_GPIO_PIN_INPUT_DISCONNECT,
NRF_GPIO_PIN_NOPULL,
NRF_GPIO_PIN_H0H1, // Require High Drive low/high level
NRF_GPIO_PIN_NOSENSE);

nrf_gpio_cfg(SDC_MOSI_PIN,
NRF_GPIO_PIN_DIR_OUTPUT,
NRF_GPIO_PIN_INPUT_DISCONNECT,
NRF_GPIO_PIN_NOPULL,
NRF_GPIO_PIN_H0H1, // Require High Drive low/high level
NRF_GPIO_PIN_NOSENSE);

There was again no change to the output.

Any help would be greatly appreciated and please let me know if there is any other info I should provide.

Cheers,

~Brandon

  • I have no clue what goes wrong, but FR_INVALID_DRIVE seems to be returned because a the called get_ldnumber() which is called from f_mount() fails to find a logical drive. Calling 

    f_mount(fs, "", 1);

    Is supposed to mount the default drive according to the documentation, but maybe it is worth trying something like:

    f_mount(fs, "0:", 1);

    Anyway, I suspect that there is something fishy with your filesystem. Unfortunately I don't have an SD card so I can't test this myself, and the guy who originally wrote the example doesn't work in Nordic anymore. Are you using a valid and properly formatted SD card? This guy got about as far as you and solved it by formatting his card to FAT32 format. 

  • I reformatted both of my micro SD cards to the FAT32 format and also made the change you suggested to the f_mount function call but I am unfortunately still getting the same errors. Just to clarify, both disks give the following output into PuTTY when the code is being loaded onto the board:

    APP:INFO:
    FATFS example.

    APP:INFO:Initializing disk 0 (SDC)...
    APP:INFO:Capacity: 30 MB
    APP:INFO:Mounting volume...
    APP:INFO:Mount failed.

    But after unplugging and resetting the board, the board will output the following into PuTTY after each time the reset button is pressed:

    APP:INFO:
    FATFS example.

    APP:INFO:Initializing disk 0 (SDC)...
    APP:INFO:Disk initialization failed.

    So I believe it is actually failing before the f_mount() function as it is not even making it to the mounting code.

    The micro SD cards are Sandisk 8 Gb and Sandisk 4 Gb cards and all I have done to them is clear them and reformat them to FAT32.

    Are there any other common things that I may have overlooked that you can think of?

    1. What kind of SD card shield are you using?
    2. If you haven't done so already, can you set the log severity level to 'debug':
    3. It could be interesting to investigate the signal integrity and check whether the HW behaves as it should. Do you have an oscilloscope or logic analyzer that you can use to measure what goes on on the SPI bus?
    4. I suppose debugging what happens the very first time after powering up the board is difficult since the code has probably executed before you are able to attach the debugger?
  • 1. The shield I am using is this one: https://www.banggood.com/3Pcs-Micro-SD-TF-Card-Memory-Shield-Module-SPI-Micro-SD-Adapter-For-Arduino-p-1003057.html?rmmds=myorder&cur_warehouse=CN

    2. I have set the log severity level to 'debug' but the output is the same.

    3. I don't have an oscilloscope on hand but I tried to slow down the SPI frequency and use an Arduino to log the pin values over time, but as expected the Arduino was too slow to read all the pins concurrently. I was able to get enough resolution to clearly read the clock pin but reading more pins caused it to slow down slightly too much. I will see if I can speed up the program tomorrow and I'll post my results then.

    4. I have to disconnect the serial USB cable to power off the board, so once I reconnect the USB to power on the board again, PuTTY needs to be restarted, so yes I am not able to get the output immediately upon reconnecting unfortunately. I think reading the SPI pins will give me a good idea of what's going on though so I will focus on figuring that out.

  • Are you using an nRF51 DK? How have you wired the SD card shield to your device?

    A colleague of mine actually had one of those shields and I tested it with a KINGMAX 16GB SDHC card that I had laying around. It works fine for me if I connect VCC on the shield to 5V on the DK kit, but I get the "Disk initialization failed." if i connect it to Vdd on the DK:

    For the record: Your SD card shield comes with a 3.3 V voltage converter and voltage level shifter for the SPI signals, but Vdd on the nRF51 DK is typically closer to 2.9 V. So that means that your SD card operates at 3.3 V, but the nRF51 operates at ~2.9 V. This means that you are operating outside the Absolute maximum ratings of the nRF51 and you risk damaging it (max GPIO input voltage = Vdd + 0.3 V). If I were you I would modify your shield to bypass the 3.3 V voltage converter and supply the SD card with Vdd from the DK directly, or I would look for a shield without all the unnecessary components. I believe SD cards should be able to run at 2.9 V so you shouldn't need the voltage regulator or level shifter.

Related