Store ADC's data stream without losses
Hello,
I am working on a project in which I have to store the data from my ADC (in continuous mode with DMA) on a SD card (with FATFS and SDMMC1) without losses. I try to use a ping pong buffer but when I want to change the bufferinwhich the ADC store values I have to stop my adc and restart it with the good buffer in parameter. Thus I lose a lots of data because of that.
Do you have a better solution to this matter ?
I also use my SD card in 1 bit mode because when I want to use it in 4 bits mode I have the RXOverrun flag. Fatfs is not configure to work with DMA because I don't know how to do it.
***EDIT 1***
I tryed to use a pointer in second parameter of HAL_ADC_Start_DMA() but it never write in the second buffer enven if my pointer is set at the 2nd buffer's adress.
Thank you for your help.
Best regards
Mathieu
Here is my main function
res= f_mount(&fs, "0:", 1);
if (res == FR_OK){
HAL_GPIO_TogglePin(LD1_GPIO_Port, LD1_Pin);
}
res = f_open(&SDFile, "test.bin", FA_CREATE_ALWAYS|FA_WRITE);
HAL_ADC_Start_DMA(&hadc1, (uint32_t *)raw, LENGTH);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
int i = 0, time = 0;
while (1)
{
if (flag1){ // this flag is set in Adc convcplt callback
if (!time) {
HAL_ADC_Stop_DMA(&hadc1);
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)baw, LENGTH);
res = f_write(&SDFile, raw, sizeof(raw),(void * ) &wr);
time = 1;
}
else {
HAL_ADC_Stop_DMA(&hadc1);
HAL_ADC_Start_DMA(&hadc1, (uint32_t * )raw, LENGTH);
res = f_write(&SDFile, baw, sizeof(baw),(void * ) &wr);
time = 0;
}
i++;
flag1=0;
}
if (i ==3){
//res = f_write(&SDFile, raw, sizeof(raw), &wr);
f_close(&SDFile);
while(1){
HAL_GPIO_TogglePin(LD3_GPIO_Port, LD3_Pin);
HAL_Delay (500);
}
}
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}