cancel
Showing results for 
Search instead for 
Did you mean: 

ADC 1 channel with circular DMA of 16 bytes: array [0] stay at '0'

lclor
Associate III

Hello,

I have an issue and until now didn't find the solution :

Using ADC2, one channel IN12, triggered by timer every 100µs, using circular DMA sized of 16 half-words, the array [0] value is always 0, the array's index used by DMA is from 1 to 16, not 0 to 15. See below screen shots :

lclor_0-1759301515100.png 

lclor_1-1759301548256.png

lclor_2-1759301607776.png

code : 

volatile uint16_t _v_Adc2Values [18]; // Define to 18 to see the shift

HAL_ADC_Start_DMA (&hadc2, (uint32_t *) _v_Adc2Values, 16);
HAL_TIM_Base_Start_IT (&htim15);

result :

lclor_3-1759302377277.png

When I starts my software this morning to make the screen shots, the 1st start, I have not the issue, the values comes from 0 to 15 in array. Then I restarted my software several times, and all these tries the array result was shifted like the screen shot.

Thank for your help.

Best regards,

Laurent

 

 

 

 

 

 

6 REPLIES 6
Ozone
Principal II

I think the DMA settings are missing in your description.

> Then I restarted my software several times, and all these tries the array result was shifted like the screen shot.

Does "restart" mean a reset without power cycle ?
Perhaps you inadvertendly change the DMA settings somewhere.
I would check and compare the relevant DMA register contents for both cases, i.e. before and after a restart.

lclor
Associate III

yes restart is without power cycle.

I do again the same test : power off, power on, launch in debug and run, and this time, the array is shifted.

 

> ... the array is shifted.

Not exactly. The values have shifted within the array.

Which indicates the DMA target address has changed.

lclor
Associate III

I would like to say that values are written by DMA in array from index 1 to 16 instead of 0 to 15.

 

However you like to frame is not the main point.

DMA is a relatively simple mechanism.
In this case, it is a defined number of 16-bit transfers from a fixed source to an auto-incremented target address.
After the defined number of word transfers are done, the DMA transfer is finished.
In circular mode, which I suppose is in effect here, these whole procedure restarts with the next ADC_EOC / EOS event, and at the initial target address.

The transfer size, number of transfers and initial target address have to be configured by your code.
If the memory layout at the target address changed, the DMA configuration must have changed.

While Cube/HAL tries to hide most of the inner workings of the MCU peripherals, an in-depth study of the MCU's RM becomes unavoidable sooner or later.

lclor
Associate III

DMA register CMAR is correct, it's the _v_Adc2Values [0] address.

 

lclor_0-1759307511623.png

lclor_1-1759307542305.png