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

WRITE AND READ SAADC DATA WITH FDS

nrf52832  S132  v6.1.1

i want to write saadc data in flash, so i call "write_to_flash" function in "void saadc_callback(nrf_drv_saadc_evt_t const * p_event)"

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
{
int product;
uint16_t val;
uint8_t value;
ret_code_t err_code;
product = channel3_enabled*8 + channel2_enabled*4 + channel1_enabled*2 + channel0_enabled;
if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
{
static uint8_t data_array[SAMPLES_IN_BUFFER*2];
err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAMPLES_IN_BUFFER);
APP_ERROR_CHECK(err_code);
uint8_t i;
printf("\r\nADC event number:%d \r\n", (int)m_adc_evt_counter);
for (i = 0; i < SAMPLES_IN_BUFFER; i++)
{
data_array2[i]=p_event->data.done.p_buffer[i];
val = p_event->data.done.p_buffer[i];
printf("%d\r\n",val);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

sizeof(data_array3)  is 240, so every record in flash is 60 words,

virtual page is 3;

virtual page size 1024;

then i stop adc and read data when flash is full, i get 32 records ,every record only contains 16 or 19  or ......words ,less than 60 words.

if everythng is correct, i can get 32 records and 60 words in every record;

the following is my read_from_flash() function

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void read_from_flash()
{
//±£´æÃØÔ¿µÄÁîÅÆÇåÁã
fds_find_token_t tok = {0};
ret_code_t rc;
rc = fds_record_find(CONFIG_FILE, CONFIG_REC_KEY, &desc, &tok);//¶ÔÓ¦KEY¼Ç¼²éÕÒÊý¾Ý
NRF_LOG_INFO("record_id:%8x",desc.record_id);
NRF_LOG_INFO("p_record:%8x",desc.p_record);
if (rc == FDS_SUCCESS)
{
/* A config file is in flash. Let's update it. */
fds_flash_record_t config = {0};
/* Open the record and read its contents. */
rc = fds_record_open(&desc, &config);
APP_ERROR_CHECK(rc);
NRF_LOG_INFO("Found Record ID = %d",desc.record_id);
NRF_LOG_INFO("Data = ");
data = (uint32_t *)config.p_data;
static uint8_t data_array_send[4];
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

it's called by a timer.

so what's the problem about "read data less than written data" ?

Any suggestion will be appreciated.