cancel
Showing results for 
Search instead for 
Did you mean: 

How to enable multi ADC using STM32F407ZG?

dhinesh
Associate
Posted on February 22, 2015 at 06:43

I am using 2 ADC's ,

1. for Touch Panel (ADC1)

2. another for getting input from potentiometer (ADC3)

Earlier Touch Panel program was working fine, when I implemented by initializing ADC3, there is a conflict, so the Touch Panel is not working. Is it possible to initialize separately? How to enable multi ADC ?

#stm32f407zg #stm-touch #adc
3 REPLIES 3
Posted on February 22, 2015 at 14:36

Suggest the following initialization order

RCC Clocks

GPIO Pins

NVIC

DMA

ADC Common

ADC1

ADC3

Enable DMA

Start Conversion

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on February 23, 2015 at 04:09

// STM32F4 ADC1&3 - sourcer32@gmail.com
// (C) Copyright 2014-2015, All Rights Reserved
#include <
stdio.h
>
#include <
stdlib.h
>
#include <
string.h
>
#include ''stm32f4_discovery.h''
//******************************************************************************
__IO uint16_t uhADC3ConvertedValue = 0;
__IO uint16_t uhADC1ConvertedValue = 0;
static void ADC3_CH13_DMA_Config(void)
{
ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
DMA_InitTypeDef DMA_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable ADC3, DMA2 and GPIO clocks ****************************************/
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2 | RCC_AHB1Periph_GPIOC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC3, ENABLE);
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = 1;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
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_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
// ADC3 DMA2 Stream 0 Channel 2
DMA_InitStructure.DMA_Channel = DMA_Channel_2;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&ADC3->DR;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&uhADC3ConvertedValue;
DMA_Init(DMA2_Stream0, &DMA_InitStructure);
DMA_Cmd(DMA2_Stream0, ENABLE);
// ADC1 DMA2 Stream 4 Channel 0
DMA_InitStructure.DMA_Channel = DMA_Channel_0;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&ADC1->DR;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&uhADC1ConvertedValue;
DMA_Init(DMA2_Stream4, &DMA_InitStructure);
DMA_Cmd(DMA2_Stream4, ENABLE);
/* Configure ADC3 Channel13 pin as analog input ******************************/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; // PC3 ADC123_IN13
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* ADC Common Init **********************************************************/
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);
/* ADC3 Init ****************************************************************/
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
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);
/* ADC1 Init ****************************************************************/
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC3 regular channel13 configuration *************************************/
ADC_RegularChannelConfig(ADC3, ADC_Channel_13, 1, ADC_SampleTime_480Cycles);
ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 1, ADC_SampleTime_480Cycles);
/* Enable DMA request after last transfer (Single-ADC mode) */
ADC_DMARequestAfterLastTransferCmd(ADC3, ENABLE);
ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);
/* Enable ADC3 & ADC1 DMA */
ADC_DMACmd(ADC3, ENABLE);
ADC_DMACmd(ADC1, ENABLE);
/* Enable ADC3 & ADC1 */
ADC_Cmd(ADC3, ENABLE);
ADC_Cmd(ADC1, ENABLE);
/* Start ADC3 and ADC1 Software Conversion */
ADC_SoftwareStartConv(ADC3);
ADC_SoftwareStartConv(ADC1);
}
//******************************************************************************
int main(void)
{
ADC3_CH13_DMA_Config();
while(1); // Don't want to exit
}
//******************************************************************************
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf(''Wrong parameters value: file %s on line %d

'', file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
//******************************************************************************

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
dhinesh
Associate
Posted on February 23, 2015 at 10:02

Thanks for the suggestion and example, let me try and let you know.