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

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

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

Reply
  • 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?

Children
Related