Michael R

STM32F1 ADC DMA swaps data

Discussion created by Michael R on Apr 5, 2018
Latest reply on Apr 17, 2018 by Michael R

I'm reading two channels (internal temperature + analog PIN) from the on-chip ADC via DMA. I'm using the ST32CubeMX to define the channels and create the initialization code (for a FreeRTOS project). Then, I'm starting the acquisition via

return (HAL_ADC_Start_DMA(&hadc1, (uint32_t *)adc->rawValues, 2) == HAL_OK)

and reading the two channels' data from adc->rawValues (it's int16_t rawValues[2];).

This works well for a while (hours), then all of a sudden the data are swapped. The two values are rather far apart, so I can certainly say that now adc->rawValues[0] is the second channel's data and adc->rawValues[1] is the first channel's data.

 

The µC is idle (i.e. running the same main event loop and timers again and again) when the swap happens.

So far, I haven't seen it swap back.

 

Can this be explained by me doing something wrong? And how can I further debug what's happening?

 

The ADC related configuration from the project file:

ADC1.Channel-0\#ChannelRegularConversion=ADC_CHANNEL_TEMPSENSOR
ADC1.Channel-1\#ChannelRegularConversion=ADC_CHANNEL_9
ADC1.ContinuousConvMode=DISABLE
ADC1.DataAlign=ADC_DATAALIGN_RIGHT
ADC1.DiscontinuousConvMode=DISABLE
ADC1.EnableAnalogWatchDog=false
ADC1.EnableRegularConversion=ENABLE
ADC1.ExternalTrigConv=ADC_SOFTWARE_START
ADC1.IPParameters=Rank-0\#ChannelRegularConversion,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,NbrOfConversionFlag,EnableAnalogWatchDog,DataAlign,ScanConvMode,ContinuousConvMode,DiscontinuousConvMode,EnableRegularConversion,NbrOfConversion,ExternalTrigConv,InjNumberOfConversion,master,Rank-1\#ChannelRegularConversion,Channel-1\#ChannelRegularConversion,SamplingTime-1\#ChannelRegularConversion
ADC1.InjNumberOfConversion=0
ADC1.NbrOfConversion=2
ADC1.NbrOfConversionFlag=1
ADC1.Rank-0\#ChannelRegularConversion=1
ADC1.Rank-1\#ChannelRegularConversion=2
ADC1.SamplingTime-0\#ChannelRegularConversion=ADC_SAMPLETIME_13CYCLES_5
ADC1.SamplingTime-1\#ChannelRegularConversion=ADC_SAMPLETIME_13CYCLES_5
ADC1.ScanConvMode=ADC_SCAN_ENABLE
ADC1.master=1
Dma.ADC1.0.Direction=DMA_PERIPH_TO_MEMORY
Dma.ADC1.0.Instance=DMA1_Channel1
Dma.ADC1.0.MemDataAlignment=DMA_MDATAALIGN_HALFWORD
Dma.ADC1.0.MemInc=DMA_MINC_ENABLE
Dma.ADC1.0.Mode=DMA_NORMAL
Dma.ADC1.0.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD
Dma.ADC1.0.PeriphInc=DMA_PINC_DISABLE
Dma.ADC1.0.Priority=DMA_PRIORITY_LOW
Dma.ADC1.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority
Dma.Request0=ADC1
Dma.RequestsNb=1

Outcomes