Hello.
I am trying to write code to read data using saadc and write the sampled data in a micro SD card using fatfs.
I started from the fatfs example and initialized and configured the saadc exactly as in saadc example except that I changed the timer to sample 120 samples at every 1 ms.
I configured a queue to received the sampled data. I store the data in the queue at every call to the saadc callback:
void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
{
if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
{
ret_code_t err_code;
err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAMPLES_IN_BUFFER);
APP_ERROR_CHECK(err_code);
if(done < NUMBER_OF_PACKETS){
err_code = byte_queue_write(p_event->data.done.p_buffer, SAMPLES_IN_BUFFER * 2);//If data cannot be written to queue
done++;
}
else{
NRF_LOG_INFO("DONE WRITING TO THE FILE");
}
}
}
In the while loop, if there is data in the queue, I try to get it and save it in the file on the SD card:
while (true)
{
//__WFE();
if(!(byte_queue_read(saadc_source, sizeof(saadc_source)))){
unit16_2_uint8(saadc_source, saadc_destination);
NRF_LOG_INFO("Writing to file " FILE_NAME "...");
ff_result = f_open(&file, FILE_NAME2, FA_READ | FA_WRITE | FA_OPEN_APPEND);
if (ff_result != FR_OK)
{
NRF_LOG_INFO("Unable to open or create file: " FILE_NAME ".");
}
ff_result = f_write(&file, saadc_destination, sizeof(saadc_destination) - 1, (UINT *) &bytes_written);
if (ff_result != FR_OK)
{
NRF_LOG_INFO("Write failed\r\n.");
}
else
{
NRF_LOG_INFO("%d bytes written.", bytes_written);
}
(void) f_close(&file);
}
}
However, the f_open() function always returns FR_NOT_ENABLED
And the device ends up stuck here:
This error seems to happen in this location at the file ff.c:
However, If I call the function fatfs_example() I can save the example file NORDIC.TXT without any errors.
Would anyone happen to know what could be causing the error?
Thank you.
