It takes time to write to the SDHC card

Hello!

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!

--------------------------------

Append

・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

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

  • Hi

    How long does it take you to fill the 512-byte buffer?

    If you sample the ADC at 1000 Hz I would expect you to spend much more than 18ms to fill the 512 byte buffer?

    Regarding your comment that flash operation takes time with SoftDevice, keep in mind that this refers to writing to the internal flash. When you write to an external flash you don't have this issue, the only question is how long time it takes to transfer the data over the SPI, and how long the external flash needs to process the data. 

    What clock speed is the SPI running at?

    Best regards
    Torbjørn

  • 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
    Torbjørn

  • 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.

Related