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

SD-Card writing blocks ADC

Hello,

I'm trying to write my ADC samples over spi on a sd card (Using SAADC like in the sdk 12 example with PPI and using fatfs like in the example in the sdk).

I open the file I want to write in only once in the beginning and close it in the end, not every time when I write in the file.

Everything works, but because I use timestamps after every sample I can see that everytime I call the f_write function, my ADC is blocked for a few miliseconds. The time where it's blocked depends on the amount of data I send.

I know that the disk_write function waits for the write done event (busy flag):

ret_code_t err_code = nrf_blk_dev_write_req(m_drives[drv].config.p_block_device, &req);
if (err_code == NRF_SUCCESS)
{
   while (m_drives[drv].busy)
    {


        m_drives[drv].config.wait_func();
    }

    if (m_drives[drv].last_result == NRF_BLOCK_DEV_RESULT_SUCCESS)
    {
        return RES_OK;
    }
	 
}
return RES_ERROR;

So I think this while loop is where my code blocks. I tried to delete the waiting part, going on with my sampling and checking before writing again if the device is still busy.

No error occurs, but when I read out my card on Pc the file is empty.

Is it somehow possible to go on sampling the ADC while writing on the SD card?

Regards Lea

  • Timer triggering SAADC sampling by PPI could be good solution.

  • Thank you, but I already trigger my SAADC sampling over a timer with PPI. I'm using TIMER1.

  • The problem is probably that the start task is manually triggered in the buffer_convert function, which I guess you are calling inside the saadc callback. To get continuous saadc measurements without any interruptions you should have a PPI channel between the end event and the start task of the saadc, like shown in the figure here.

    This should most likely work out of the box with the saadc driver, just set up the PPI channel. I have not tested this with the driver, but I know that it works from the peripheral point of view.

    Alternatively have a higher interrupt level on the saadc interrupt/callback. Configure this in nrf_drv_saadc_config_t->interrupt_priority.

  • Thank you. Setting the interrupt of the saadc to a higher level is a problem, because in the beginning my saadc interrupt had been higher or the same like my spi interrupt. In this case writing on the sd card didn't worked at all. The code got stuck in the config.wait_func() function I mentioned above which waited for the write done event, that never occured. So I set the interrupt priority of the saadc to 6 and of the spi to 3.

    I have now set a PPI channel between START Task and END Event of Saadc, but the problem remains. There is no sampling during the write process.

  • Where do you call the write function (f_write(..))? You should consider calling this in main context if you are calling it in interrupt context (inside an event handler/callback).

    Also, the interrupt priority is higher if the value is lower (0 is the highest priority, 7 is the lowest). You should use the APP_IRQ_PRIORITY_ to set the priority, see app_util_platform.h.

Related