cancel
Showing results for 
Search instead for 
Did you mean: 

L073: ADC & DMA, strange buffer "shift" in CIRCULAR mode

LCE
Principal II

Heyho,

strange things happening that I'd like to understand for a STM32L073 (Nucleo for now).

Setup on a L073 @ 32MHz:

- ADC is clocked by PCLK/4
- ADC prescaler = 2 -> divide by 4 -> 2 MHz
- 12 bit right aligned
- ref V = VDDA = 3.3V
- hardware oversampling + shift is used (great feature!)
- 7 ADC channels sequenced
- DMA, with buffer for 8 samples per channel -> u16AdcDmaBuf[56]

 

In non-circular mode (CIRC neither set in DMA- nor in AD-registers), after each DMA's transfer complete interrupt, DMA and ADC are restarted, everything is as it should be, and as it is set in the sequencing registers.

Here's what the DMA buffer looks like, and all this makes sense:
buffer[0] = 2031 is the DAC output set to 2047,
buffer[1] & buffer[2] = 4095 are connected to VDDA -> 4095 ok,
buffer[5] is internal VREF = 1.2V -> perfect,
buffer[6] is internal temperature sensor -> ~24°C -> perfect

1) ADC & DMA: not circular

DmaBuf
[00] 2031 4095 4095 1926 3083 1524 0604
[07] 2031 4095 4095 1926 3083 1524 0604
[14] 2031 4095 4095 1927 3081 1525 0604
[21] 2031 4095 4095 1925 3081 1525 0605
[28] 2031 4095 4095 1926 3081 1525 0605
[35] 2031 4095 4095 1926 3081 1525 0605
[42] 2031 4095 4095 1926 3081 1525 0605
[49] 2031 4095 4095 1926 3081 1526 0605
     DAC2 PWR5 PWR3 SNSA SNS5 REFI TMPI

registers:
ADC1->
ISR 0000000B
IER 00000000
CR  10000005
         REGEN
         START
         EN
CFGR1 = 00003001
         CONT
         OVRMOD
         right aligned
         DMAEN

DMA1_Channel1->
CCR 0000358B
         EN
         TCIE
         TEIE
         MINC
         MSIZE = 1 = 16b
         PSIZE = 1 = 16b

 

Now (all before ADC / DMA start) I turn on circular mode in ADC1->CFGR1 |= DMACFG, 
and in DMA1_Channel1->CCR |= CIRC.
And now I still get some nice AD values, but the buffer has shifted by 1, compare to above:

2) ADC & DMA: CIRCular mode

DmaBuf
[00] 0602 2031 4095 4095 1926 3085 1525
[07] 0602 2031 4095 4095 1926 3084 1525
[14] 0602 2031 4095 4095 1925 3083 1525
[21] 0602 2031 4095 4095 1927 3084 1525
[28] 0602 2031 4095 4095 1926 3084 1525
[35] 0602 2031 4095 4095 1926 3084 1525
[42] 0602 2031 4095 4095 1926 3083 1525
[49] 0602 2031 4095 4095 1926 3084 1525
     DAC2 PWR5 PWR3 SNSA SNS5 REFI TMPI

registers:
ADC1->
ISR 0000000B
IER 00000000
CR  10000005
         REGEN
         START
         EN
CFGR1 = 00002003
         CONT
         right
         12b
         DMACFG = CIRC
         DMAEN

DMA1_Channel1->
CCR 000035AB
         EN
         TCIE
         TEIE
         CIRCular
         MINC
         MSIZE = 1 = 16b
         PSIZE = 1 = 16b

 

Note: register dumps are from running application

What am I missing? Been checking all registers, DS, RM, feels like I have overseen one bit or so...

 

Thanks in advance!

11 REPLIES 11
LCE
Principal II

ADC is started last:


...

/* +++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* start prep & start */

	/* DMA1_Channel1_IRQn interrupt configuration */
	NVIC_SetPriority(DMA1_Channel1_IRQn, NVIC_IRQ_PRIO_DMA_ADC);
	NVIC_EnableIRQ(DMA1_Channel1_IRQn);

	/* enable DMA */
	DMA1_Channel1->CCR |= DMA_CCR_EN;

	/* enable VREFINT & temperature sensor */
	ADC1_COMMON->CCR |= ( ADC_CCR_TSEN | ADC_CCR_VREFEN );

	/* ADC enable */
	ADC1->CR |= ADC_CR_ADEN;
	/* ADC START */
	ADC1->CR |= ADC_CR_ADSTART;
}

​

 

LCE
Principal II

offline for today, thanks so far !