2023-03-02 06:40 PM
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.
ADC is 12 bits and 1M samples/s.
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:
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:
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.
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++;
}
}
And, I tried with DMA USART:
len=sizeof(BUFFER_SIZE);
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)buffer1, len);
HAL_UART_Transmit_DMA(&huart2, buffer, len);
My max baud rate is 2000000 for USART.
2023-04-04 12:17 PM
New Thread
https://community.st.com/s/question/0D53W00002DAj1vSAD/fatfs-writing-cmdsfprintf-slows-down-adc