It takes time to write to the SDHC card


I currently want to save the sensor data obtained by SPI communication to the microSDHC card by SPI communication.

Writing to the SDHC card is possible without problems, but writing takes time.

I want to acquire and write sensor values at a sampling frequency of 1000 Hz, but it takes about 18 ms to write.

What I tried to improve
・ Use of DMA
・ Change of priority
・ Use multiple arrays

Are there any other possible ways?

Thank you!



・I also use BLE communication and soft devices. I learned that the flash operation takes time when using a soft device.
And writing to SD card is 512 bytes each

・Use fatfs example

  • Hi 

    How much data are you writing in each write operation?

    I assume you would get more efficient SD access if you buffer the ADC data in 512 byte chunks so you don't have to write to the card as often?

    Best regards

  • Thank you for your reply.
    I already have data stored in a 512-byte buffer before writing.

  • Hi
    ・ About the time to fill the buffer with 512 bytes
    As the flow of processing I am currently doing,

    ret_code_t ret = nrf_drv_spi_xfer(&spi,&xfer_spi,flags);
    if(ret == NRF_SUCCESS){
        uint32_t start_tsk_addr = nrf_drv_spi_start_task_get(&spi);
        for(a = 0; a <20;a++){
            buf[j*21+a] = mpu_buf[a];
        buf[j*21+20] = time;
        if(j == 24)
            f_write(&file, buf2,512, (UINT *) &bytes_written);

    It looks like this.
    The sensor value is read into the array every 1 ms and written when 512 bytes are accumulated. At this time, the variable “time” is also incremented by +1 every 1 ms, and it is confirmed that there is no data loss by looking at the written data.

    When the written data is confirmed, the value of “time” continues to increase by +1 for 512 bytes, but when it reaches the next 512 bytes, the value jumps 18 milliseconds.

    From this
    21 bytes (data + time) * 24 ms = 504 bytes
    I think that it is 24ms to collect 512 bytes more.
    I think that it takes time for processing to be f_write of fatfs.

    ・ About flash writing of soft device
    Thank you for teaching me. I understood that there was no need to think about this time.

    ・ SPI clock speed
    The clock is set to 1MHz for both SPI0 (SDcard) and SPI1 (sensor).

    Is there a way to shorten the processing time of the external flash?

  • Hi

    Thanks a lot for the additional information. 

    The write speed of flash cards vary a lot from model to model, so without a full specification of your card it is hard to say how much speed you can expect. 

    What type of microSD card are you using?

    Have you tried to change the card for a different one to see if this could improve the communication speed?

    Have you investigated if you could remove or compress some of the MPU data to reduce the amount of data that you need to store to the card?

    Best regards

  • I use SanDisk's 32GB SDHC card.
    Since there is no other SD card, I have not tried it.

    All MPU data is necessary and cannot be reduced.

  • Hi

    Do you have a specification for the flash chip used in the SanDisk card, so that you can verify the timing parameters?

    Best regards

  • Maybe solved
    Interrupted except f_write!

    Thank you for your cooperation

Reply Children