2018-06-19 08:50 PM
I am using a STM32F303v with 2 ADC regular channels in cotinuous mode with a DMA and would like continuous conversion to take place in order to enable a stream of data.
Base on the setup of my DMA and ADC below, I am unable to perform continuous conversion. On further debugging, I found that the very first conversion is successful and then the ADSTART bit is set back to 0. If I manually set ADSTART=1, the conversion starts, DMA does the transfer when it finishes and then ADSTART goes back to 0. Please help.
DMAy_x
=
DMA1_Channel1;
DMA_InitStructure.
DMA_M2M
=
DMA_M2M_Disable;
DMA_InitStructure.
DMA_MemoryBaseAddr
=
(
uint32_t
)dest;
DMA_InitStructure.
DMA_DIR
=
DMA_DIR_PeripheralSRC;
DMA_InitStructure.
DMA_Mode
=
DMA_Mode_Circular;
DMA_InitStructure.
DMA_Priority
=
DMA_Priority_High;
DMA_InitStructure.
DMA_PeripheralDataSize
=
DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.
DMA_MemoryDataSize
=
DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.
DMA_MemoryInc
=
DMA_MemoryInc_Enable;
DMA_InitStructure.
DMA_PeripheralInc
=
DMA_PeripheralInc_Disable;
DMA_InitStructure.
DMA_BufferSize
=
2;
// in data unit
DMA_InitStructure.
DMA_PeripheralBaseAddr
=
(
uint32_t
)
&
ADCx->
DR
;
DMA_Init
(DMAy_x,
&
DMA_InitStructure);
DMA_Cmd
(DMAy_x, ENABLE);
ADCx = ADC1;
ADC_Cmd
(ADCx, DISABLE);
while
(ADCx->
CR
&
ADC_CR_ADEN);
ADC_DeInit
(ADCx);
ADC_InitTypeDef ADC_InitStructure;
ADC_StructInit
(
&
ADC_InitStructure);
ADC_InitStructure.
ADC_ContinuousConvMode
=
ENABLE;
ADC_InitStructure.
ADC_DataAlign
=
ADC_DataAlign_Right;
ADC_InitStructure.
ADC_Resolution
=
ADC_Resolution_12b;
ADC_InitStructure.
ADC_NbrOfRegChannel
=
2;
ADC_InitStructure.
ADC_ExternalTrigEventEdge
=
ADC_ExternalTrigEventEdge_None;
ADC_InitStructure.
ADC_ExternalTrigConvEvent
=
ADC_ExternalTrigConvEvent_0;
ADC_InitStructure.
ADC_OverrunMode
=
ENABLE;
ADC_InitStructure.
ADC_AutoInjMode
=
DISABLE;
ADC_Init
(ADCx,
&
ADC_InitStructure);
// Set up ADC channels
for
(
uint16_t
i
=
0
; i
<
nPins;
++
i)
{
// make them regular channels with rank i +1, sample time is 19 ADC cycles
ADC_RegularChannelConfig
(ADCx, PIN_MAP[pinNames[i]].
adcChannel
, i
+
1
, ADC_SAMPLE_TIME);
}
ADC_DMAConfig
(ADCx, ADC_DMAMode_Circular);
ADC_DMACmd
(ADCx, ENABLE);
// Enable everything
ADC_Cmd
(ADCx, ENABLE);
while
(
!
(
ADC_GetFlagStatus
(ADCx, ADC_FLAG_RDY)));
ADC_StartConversion
(ADCx);
#stm32f303 #dma-adc-stm32f303 #stm32f303-adcSolved! Go to Solution.
2018-06-20 12:03 PM
The bug was in this line
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
It should be
ADC_InitStructure.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Enable;
2018-06-20 12:03 PM
The bug was in this line
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
It should be
ADC_InitStructure.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Enable;