A
A
Anatoly2016-07-03 09:57:28
Programming
Anatoly, 2016-07-03 09:57:28

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);

Next, I put a breakpoint in the interrupt:
void DMA1_Channel1_IRQHandler(void)
{
  HAL_DMA_IRQHandler(&hdma_adc1);
}

And, logically, on each interrupt IN_Buffer[0] and IN_Buffer[1] must be filled in turn. For unambiguous identification during a stop, I short the ADC pin to ground or power. But DMA for some reason updates the entire array as a whole, and not one by one.
UPD: Moreover, in the timer interrupt, on the trigger of which the ADC works, the entire buffer is also changed, and not one element at a time, as I expect:
void TIM3_IRQHandler(void)
{
  HAL_NVIC_ClearPendingIRQ(TIM3_IRQn);
  HAL_TIM_IRQHandler(&htim3);
}

Or DMA cannot be debugged in this way? I don't understand what am I doing wrong?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2016-07-03
@oWart

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 question

Ask a Question

731 491 924 answers to any question