nadd
Member level 1
Hello everyone,
I'm trying to get ADC(DMA) data on the NucleoF303RE STM32 board. The sampling speed is 1Msamples/s. When I apply a sinus wave I see data losses on ADC data. I tried to read data with a serial port and save it to an sd card. Both of them have the same problem.
While saving to the sd card, I stopped ADC after the buffer is filled to see what's is the problem. There is no data loss when ADC is stopped after filling the buffer. But, I need continuous conversion, so it is not a solution for me. I guess the ADC uses the same buffer immediately, and saving data commands are not fast enough before ADC fills the buffer again.
Do you have any suggestions? Where am I doing wrong? or maybe any other algorithms?
Codes to save to the sd card I use:
Codes to read from the serial port I use:
I also tried to transfer data when the half buffer is filled, then transfer the second half when the full buffer is filled. But, It only uses the first half buffer with this code and keeps doing data losses.
I'm trying to get ADC(DMA) data on the NucleoF303RE STM32 board. The sampling speed is 1Msamples/s. When I apply a sinus wave I see data losses on ADC data. I tried to read data with a serial port and save it to an sd card. Both of them have the same problem.
While saving to the sd card, I stopped ADC after the buffer is filled to see what's is the problem. There is no data loss when ADC is stopped after filling the buffer. But, I need continuous conversion, so it is not a solution for me. I guess the ADC uses the same buffer immediately, and saving data commands are not fast enough before ADC fills the buffer again.
Do you have any suggestions? Where am I doing wrong? or maybe any other algorithms?
Codes to save to the sd card I use:
C:
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
// HAL_ADC_Stop_DMA(&hadc1);
for (int i = 0; i < ADC_BUF_LEN; i++) {
fres = f_printf(&fil, "%d\n", adc_buf[i]);
if (fres < 0) {
myprintf("f_printf error (%i)\r\n", fres);
while(1);
}
}
f_close(&fil);
f_mount(NULL, "", 0);
}
Codes to read from the serial port I use:
C:
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
for (int i = 0; i < ADC_BUF_LEN; ) {
myprintf("%i\r\n", adc_buf[i]);
i++;
}
}
I also tried to transfer data when the half buffer is filled, then transfer the second half when the full buffer is filled. But, It only uses the first half buffer with this code and keeps doing data losses.
C:
void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc) {
for (int i = 0; i < ADC_BUF_LEN/2; ) {
myprintf("%i\r\n", adc_buf[i]);
i++;
}
}
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
for (int i = ADC_BUF_LEN/2; i < ADC_BUF_LEN; ) {
myprintf("%i\r\n", adc_buf[i]);
i++;
}
}