Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] STM32F429 ADC DMA problem

Status
Not open for further replies.

sunil_kasar

Newbie level 6
Newbie level 6
Joined
May 6, 2015
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
India
Visit site
Activity points
125
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.


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:

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).


how you are feeding input to ADC? how you are varying it? If feeding input from externally to ADC means, provide the circuit.
 

Dear hobbyckts,

with the help of a pot I am varying ADC input. I have connected one pin of pot to 3V, second to ground and one more to one ADC channel. and when I change voltage at one pin of channel, it is effecting other 3 channel results also.
 

Do you follow Typical connection diagram using the ADC which is mentioned in the datasheet and have you calculated the value of RAIN by using the formula? Do you use BGA package IC?
 

@ hobbyckts,

1. Please clarify what is RAIN? Also the formula that you are referring, please let me know where to find this information.
2. Ours is not BGA. It is LQFP144.

- - - Updated - - -

Hello hobbyckts,

Now I have configured PA0,PA1,PA2 and PA3 pins for ADC channels.

1. When I connect POT at PA0 and vary the voltage, all other 3 pin's voltage too getting varied.

2. When I connect POT to PA1, and vary voltage, voltage at PA2 and PA3 too getting varied. And Voltage at PA0 is unaffected.

3. When I connect POT to PA2 and vary voltage, the voltage at PA3 too getting varied. And voltage at PA0 and PA1 is unaffected.

4. When I connect POT to PA3 and vary voltage, the voltage at PA3 is getting varied and rest are fine(unaffected).

Can you figure out why is this happening? I have attached code for your convenience.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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();
    }    
}



Thanking you.
 
Last edited by a moderator:

I Corrected a problem in your function “void DMA2_Init(void)”
"RCC_Configuration_DMA();"this function is not definition.
I think it should be changed to "RCC_Configuration();"
than,I defined CH_TOTAL_NUM_E is 4.
I downloaded your code to my STM32F407 DISCOVERY BOARD,
I connected PA0 PA2 to VDD,connected PA1,PA3 to GND.
It Runs OK,Debug printed value of array ADC_values_au16.
I think the problem maybe on your hardware.
(I don't have stm32f429 board,so I used STM32F407 board,but them are similar) test.jpg
 
Hi,

2. When I connect POT to PA1, and vary voltage, voltage at PA2 and PA3 too getting varied. And Voltage at PA0 is unaffected.

3. When I connect POT to PA2 and vary voltage, the voltage at PA3 too getting varied. And voltage at PA0 and PA1 is unaffected.

This seems like crosstalk caused by a multiplexing input channels. Is your input impedance at each channel low enough?
And is there enough time after changing (Mux) Input and before starting conversion?

What ADC type is it? Hopefully not a delta sigma..

Klaus
 
@ hobbyckts,

1. Please clarify what is RAIN? Also the formula that you are referring, please let me know where to find this information.
2. Ours is not BGA. It is LQFP144.


Refer figure no:51 at the page 157 along with notes provided even the formula for the resistor RAIN is provided at the page no:154.
The circuit shown in page 157 is how you need to feed the input as per the specification and not connecting directly to ADC input. I guess this is were you are doing some mistake. Check for it
 
Hi gaoguanyixh, klausST and hobbyckts,
Thank you for your suggestions.
I connected PA0 to POT, and PA1,PA2, PA3 to 3V. It is working fine. The result is normal. The unconnected pins are floating and responding
to crosstalk from the pot signal pin. After Putting a low impedance signal concurrently on all 4 pins, the "problem" will magically disappears.

Once again thanks a lot.
 

Always instead of leaving pins open better to connect on ground.

That Sound's cool. Thanks for sharing the method you have used for correction.

Mark this thread as solved so that it will be useful for the peoples whoever facing the same issue.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top