I’ve added a new pin function, “ADIN” that manages the ADC input channels, a proper initialization function for ADC1, an with a status LED on the main window, and an “ADC1 Setup” window.
I’ve also added an ADC reading function in “my_soft_adc.h” header from “spl_library” folder. Not yet committed in repository because I am not ready with the new code for SPI1, 2 and 3 peripherals.
In the following window, the PA0, PA1, PA4 and PB13 are set as ADC Input Channels
and the main window below shows an enabled LED for ADC1 button, which button you can press
to show the ADC1 Setup window where you can tune the peripheral (right now, only software triggered conversions are fully supported)
and finally, generating the code (not tested yet):
void vpc_adc1_init(void){
ADC_InitTypeDef ADC1_InitStruct;
ADC_CommonInitTypeDef ADC1_CommonStruct;
GPIO_InitTypeDef GPIO_InitStruct;
RCC_AHBPeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB, &GPIO_InitStruct);
ADC1_CommonStruct.ADC_Prescaler = ADC_Prescaler_Div1;
ADC_CommonInit(&ADC1_CommonStruct);
ADC1_InitStruct.ADC_Resolution = ADC_Resolution_12b;
ADC1_InitStruct.ADC_ScanConvMode = DISABLE;
ADC1_InitStruct.ADC_ContinuousConvMode = DISABLE;
ADC1_InitStruct.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC1_InitStruct.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_CC3;
ADC1_InitStruct.ADC_DataAlign = ADC_DataAlign_Right;
ADC1_InitStruct.ADC_NbrOfConversion = 1;
ADC_Init(ADC1, &ADC1_InitStruct);
ADC_Cmd(ADC1, ENABLE);
}
NOTE: The program is aware of your selection made in the Clock Setup window and will enable or not the HSI clock that is needed for the ADC peripheral (if I am right…).
Arrrg! My English! If you want to use ADC, HSI clock must be enabled. If you choose HSE or BYPASS as a clock source for your board, then the code that enables HSI is included. Otherwise, it is not necessary because HSI is already activated and running – now is better.



