cancel
Showing results for 
Search instead for 
Did you mean: 

(STM32F4 Discovery) Problem Adding manually ADC (using DMA) after Generate it with Stm32CubeMX

bram_labs
Associate II
Posted on November 23, 2016 at 16:46

 

 

The original post was too long to process during our migration. Please click on the attachment to read the original post.
6 REPLIES 6
valentin
Senior
Posted on November 24, 2016 at 04:32

Do you also set the corresponding pin to AF?

And how doesn't it work, does it only measure the first 10 channels and ignores the newly added 11th?
bram_labs
Associate II
Posted on November 24, 2016 at 05:49

Nah, i didn't wanna set the Pin using STM32CubeMX (re-set the pin). But i didn't know how to set the pin INSIDE the main.c. Could you please help me sir, how to do it ?

And for your second question, when i added 1 more ADC like i did in the picture in my question, the ADC seems like attach to the value of previous ADC (Ex. i have 11 ADC to read and i wanted to add 1 more ADC to read. Then i put my potentiometer at the 12'th ADC, in this case, this is ADC_buffer[11]. Then the value of ADC_buffer[10] seems like attached to the ADC_buffer[11]. If i change the potentiometer at the ADC_buffer[11], the ADC reading for ADC_buffer[10] also change even though i didn't put potentiometer for ADC_buffer[10]. And i dunno why this would happen. But the value isn't EXACTLY the same, just different about 25 - 50).

valentin
Senior
Posted on November 25, 2016 at 06:02

You've just got to set the pin to analog, that'll tell the ADC to take control - if it is configured accordingly.

e.g:

GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pin = BTN_IN_1_Pin | BTN_IN_2_Pin | BTN_IN_3_Pin | BTN_IN_4_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

Modify to whatever names you have for your pins + port 🙂
bram_labs
Associate II
Posted on November 25, 2016 at 16:50

Hello Sir 🙂

Okay, i'll try it later. And also, i'm wondering. Why there's no initialiazation for ADC PIN when generating it with STMCubeMX ? There's only information about clock, resolution, data alignment etc. such us here :

 /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
 */
 hadc1.Instance = ADC1;
 hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
 hadc1.Init.Resolution = ADC_RESOLUTION_12B;
 hadc1.Init.ScanConvMode = ENABLE;
 hadc1.Init.ContinuousConvMode = ENABLE;
 hadc1.Init.DiscontinuousConvMode = DISABLE;
 hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
 hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
 hadc1.Init.NbrOfConversion = 12;
 hadc1.Init.DMAContinuousRequests = ENABLE;
 hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
 if (HAL_ADC_Init(&hadc1) != HAL_OK)
 {
 Error_Handler();
 }

But, there's no information about the ADC PIN that we've already set in STMCubeMX.

/**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)

*/

hadc1.Instance = ADC1;

hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;

hadc1.Init.Resolution = ADC_RESOLUTION_12B;

hadc1.Init.ScanConvMode = ENABLE;

hadc1.Init.ContinuousConvMode = ENABLE;

hadc1.Init.DiscontinuousConvMode = DISABLE;

hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;

hadc1.Init.NbrOfConversion = 12;

hadc1.Init.DMAContinuousRequests = ENABLE;

hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;

if (HAL_ADC_Init(&hadc1) != HAL_OK)

{

Error_Handler();

}

valentin
Senior
Posted on November 27, 2016 at 19:54

if you set the ''separate .c/.h'' switch in prefs, the pin config happens in the peripheral's .c file.

/**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)

*/

hadc1.Instance = ADC1;

hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;

hadc1.Init.Resolution = ADC_RESOLUTION_12B;

hadc1.Init.ScanConvMode = ENABLE;

hadc1.Init.ContinuousConvMode = ENABLE;

hadc1.Init.DiscontinuousConvMode = DISABLE;

hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;

hadc1.Init.NbrOfConversion = 12;

hadc1.Init.DMAContinuousRequests = ENABLE;

hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;

if (HAL_ADC_Init(&hadc1) != HAL_OK)

{

Error_Handler();

}

bram_labs
Associate II
Posted on November 28, 2016 at 10:02

So, you mean these one should be left check or uncheck Sir ?

0690X000006037jQAA.jpg

Oh, okay, thank you very much sir, i've tried it and it separates the configuration into file .c (Ex. adc.c .... main.c ..... gpio.c ....etc.)

Btw, if i just want to add the ADC port, i just need to change the configuration in adc.c right ? Oh yeah, and btw, does it need to be reconfigured in 'main.c' after i applied some change in 'adc.c' ?