Answer the question
In order to leave comments, you need to log in
Why is the ring buffer with ADC values already full in the DMA half interrupt on the STM32 HAL?
Hello.
I am slowly mastering the STM32F103 and ran into such a disaster. Through Stm32CubeMX, I configure the ADC to work in a cyclic mode via DMA on a timer trigger. Everything seems to be working. But DMA, as you know, generates interrupts when the buffer is half full (checked the setting register, it is on) and when it is full. Judging by the time intervals, it is. Below are excerpts from the code, trying to organize a ring buffer:
#define FRAME_SIZE 10
__IO int16_t IN_Buffer[2][FRAME_SIZE];
HAL_ADC_Start_DMA(&hadc1,(uint32_t*)&IN_Buffer[0],FRAME_SIZE*2);
void DMA1_Channel1_IRQHandler(void)
{
HAL_DMA_IRQHandler(&hdma_adc1);
}
void TIM3_IRQHandler(void)
{
HAL_NVIC_ClearPendingIRQ(TIM3_IRQn);
HAL_TIM_IRQHandler(&htim3);
}
Answer the question
In order to leave comments, you need to log in
1. Try reducing the data sampling rate.
2. Try to increase the number of samples in the buffer, as you may simply not have time to respond to an interrupt with a small buffer size. More precisely, the handler will start, but the moment of interruption may already come when the buffer is full.
3. An interrupt will indeed be generated when the buffer is half full.
Try another quick output to the console - then it will be clear exactly what happened where.
upd:
By the way, do interrupts work for half the transmission and the full one? There is a suspicion..
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question