2016-11-23 07:46 AM
2016-11-23 07:32 PM
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?2016-11-23 08:49 PM
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).2016-11-24 09:02 PM
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 :)
2016-11-25 07:50 AM
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();
}
2016-11-27 10:54 AM
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();
}
2016-11-28 01:02 AM
So, you mean these one should be left check or uncheck Sir ?
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' ?