DMA and ADC on the STM32F2xx
Trying to stuff multiple channels of ADC3 into a DMA, but am unsure of how the DMA address gets incremented. Is this done automatically behind the scenes and I don't have to worry, or am I missing a setup? I didn't see an explanation of how DMA_InitStructure.DMA_MemoryInc works. Any help here is appreciated.
I will also be double buffering, what is the best way to trigger the DMA_ISR after the last conversion?I expect theADC_Zone_ADC buffer to have 8 Half words stuffed into it.
My setup follows
: void ADC_DMA_Config(void){ DMA_InitTypeDef DMA_InitStructure; DMA_InitStructure.DMA_Channel = DMA_Channel_0; DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADC_Zone_ADC; DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&ADC2->DR; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; DMA_InitStructure.DMA_BufferSize = 8; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; DMA_Init(DMA2_Stream0, &DMA_InitStructure);DMA_Cmd(DMA2_Stream0, ENABLE);
void ADC_Setup_Zone_ADC(void){ GPIO_InitTypeDef GPIO_InitStructure; ADC_InitTypeDef ADC_InitStructure; ADC_CommonInitTypeDef ADC_CommonInitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC3, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE); GPIO_InitStructure.GPIO_Pin= GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5
|GPIO_Pin_6
|GPIO_Pin_7|
GPIO_Pin_8|
GPIO_Pin_9|
GPIO_Pin_10
; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; GPIO_Init(ADC_ZONE_MON_PORT, &GPIO_InitStructure); ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent; ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2; ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles; ADC_CommonInit(&ADC_CommonInitStructure); ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfConversion = 1; ADC_Init(ADC3, &ADC_InitStructure); ADC_RegularChannelConfig(ADC3,ADC_Channel_9, 1, ADC_SampleTime_15Cycles); ADC_RegularChannelConfig(ADC3,ADC_Channel_5, 2, ADC_SampleTime_15Cycles); ADC_RegularChannelConfig(ADC3,ADC_Channel_14, 3, ADC_SampleTime_15Cycles); ADC_RegularChannelConfig(ADC3,ADC_Channel_6, 4, ADC_SampleTime_15Cycles); ADC_RegularChannelConfig(ADC3,ADC_Channel_15, 5, ADC_SampleTime_15Cycles); ADC_RegularChannelConfig(ADC3,ADC_Channel_7, 6, ADC_SampleTime_15Cycles); ADC_RegularChannelConfig(ADC3,ADC_Channel_4, 7, ADC_SampleTime_15Cycles); ADC_RegularChannelConfig(ADC3,ADC_Channel_8, 8, ADC_SampleTime_15Cycles); ADC_Cmd(ADC3, ENABLE); ADC_SoftwareStartConv(ADC3);}