sunil_kasar
Newbie level 6
Hi all,
I am new to STM32F429 board. I wrote a code for ADC-DMA2 implementation. I have configured 4 channels PA4,PA5,PA6 and PA7 for ADC1 and when I change voltage at one pin, it's effect is influencing on other three pins also(ADC values at other 3 pins are also changing). below is the code. Kindly give me suggestions to get rid from this problem.
I am new to STM32F429 board. I wrote a code for ADC-DMA2 implementation. I have configured 4 channels PA4,PA5,PA6 and PA7 for ADC1 and when I change voltage at one pin, it's effect is influencing on other three pins also(ADC values at other 3 pins are also changing). below is the code. Kindly give me suggestions to get rid from this problem.
Code:
SINT8 Str_ADC_Count[10];
UINT16 ADC_Count_u16 = 0;
UINT16 ADC_values_au16[CH_TOTAL_NUM_E];
static void DMA_Config(void)
{
DMA_InitTypeDef DMA_InitStructure;
DMA_DeInit(DMA2_Stream0);
DMA_InitStructure.DMA_Channel = DMA_Channel_0;
DMA_InitStructure.DMA_PeripheralBaseAddr = (UINT32)&ADC1->DR;
DMA_InitStructure.DMA_Memory0BaseAddr = (UINT32)&ADC_values_au16[0];
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = CH_TOTAL_NUM_E;
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_Disable;
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 DMA2_Init(void)
{
RCC_Configuration_DMA();
DMA_Config();
}
static void RCC_Configuration(void)
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
}
static void GPIO_Configuration()
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3; // channel_0 PA0
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void ADC1_Init(void)
{
ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
RCC_Configuration();
GPIO_Configuration();
ADC_DeInit();
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; // Orig dis
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
ADC_CommonInit(&ADC_CommonInitStructure);
ADC_StructInit(&ADC_InitStructure);
ADC_InitStructure.ADC_Resolution = ADC_Resolution_10b;
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_NbrOfConversion = 4;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_56Cycles);
ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 2, ADC_SampleTime_56Cycles);
ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 3, ADC_SampleTime_56Cycles);
ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 4, ADC_SampleTime_56Cycles);
ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);
ADC_DMACmd(ADC1, ENABLE);
ADC_Cmd(ADC1, ENABLE);
ADC_SoftwareStartConv(ADC1);
}
void delay_short()
{
UINT32 delayCnt = 0;
for(delayCnt = 0; delayCnt < 100000; delayCnt++)
{;}
}
void delay_long()
{
UINT32 delayCnt = 0;
for(delayCnt = 0; delayCnt < 10000000; delayCnt++)
{;}
}
int main(void)
{
UINT32 i = 0;
DMA2_Init();
ADC1_Init();
USART1_Init();
Serial_PutString("ADC Init complete\n", USART1);
Serial_PutString("Usart Init complete\n", USART1);
while(1)
{
for(i = 0; i < 4; i++)
{
sprintf((char*)Str_ADC_Count, "%d, \n",ADC_values_au16[i]);
Serial_PutString(Str_ADC_Count, USART1);
delay_short();
}
Serial_PutString(" ;", USART1);
delay_long();
}
}
Last edited by a moderator: