1 |
/* ADC1 init function */
|
2 |
void MX_ADC1_Init(void)
|
3 |
{
|
4 |
LL_ADC_InitTypeDef ADC_InitStruct = {0};
|
5 |
LL_ADC_REG_InitTypeDef ADC_REG_InitStruct = {0};
|
6 |
LL_ADC_CommonInitTypeDef ADC_CommonInitStruct = {0};
|
7 |
|
8 |
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
9 |
|
10 |
/* Peripheral clock enable */
|
11 |
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_ADC12);
|
12 |
|
13 |
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA);
|
14 |
/**ADC1 GPIO Configuration
|
15 |
PA0 ------> ADC1_IN1
|
16 |
*/
|
17 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_0;
|
18 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
|
19 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
20 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
21 |
|
22 |
/* ADC1 interrupt Init */
|
23 |
NVIC_SetPriority(ADC1_2_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
|
24 |
NVIC_EnableIRQ(ADC1_2_IRQn);
|
25 |
|
26 |
/** Common config
|
27 |
*/
|
28 |
ADC_InitStruct.Resolution = LL_ADC_RESOLUTION_12B;
|
29 |
ADC_InitStruct.DataAlignment = LL_ADC_DATA_ALIGN_RIGHT;
|
30 |
ADC_InitStruct.LowPowerMode = LL_ADC_LP_MODE_NONE;
|
31 |
LL_ADC_Init(ADC1, &ADC_InitStruct);
|
32 |
|
33 |
ADC_REG_InitStruct.TriggerSource = LL_ADC_REG_TRIG_SOFTWARE;
|
34 |
ADC_REG_InitStruct.SequencerLength = LL_ADC_REG_SEQ_SCAN_DISABLE;
|
35 |
ADC_REG_InitStruct.SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE;
|
36 |
ADC_REG_InitStruct.ContinuousMode = LL_ADC_REG_CONV_SINGLE;
|
37 |
ADC_REG_InitStruct.DMATransfer = LL_ADC_REG_DMA_TRANSFER_NONE;
|
38 |
ADC_REG_InitStruct.Overrun = LL_ADC_REG_OVR_DATA_PRESERVED;
|
39 |
LL_ADC_REG_Init(ADC1, &ADC_REG_InitStruct);
|
40 |
|
41 |
LL_ADC_SetGainCompensation(ADC1, 0);
|
42 |
LL_ADC_SetOverSamplingScope(ADC1, LL_ADC_OVS_DISABLE);
|
43 |
LL_ADC_DisableDeepPowerDown(ADC1);
|
44 |
LL_ADC_EnableInternalRegulator(ADC1);
|
45 |
ADC_CommonInitStruct.CommonClock = LL_ADC_CLOCK_ASYNC_DIV1;
|
46 |
ADC_CommonInitStruct.Multimode = LL_ADC_MULTI_INDEPENDENT;
|
47 |
LL_ADC_CommonInit(__LL_ADC_COMMON_INSTANCE(ADC1), &ADC_CommonInitStruct);
|
48 |
LL_ADC_EnableIT_EOC(ADC1);
|
49 |
LL_ADC_DisableIT_EOS(ADC1);
|
50 |
/** Configure Regular Channel
|
51 |
*/
|
52 |
LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_1);
|
53 |
LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_1, LL_ADC_SAMPLINGTIME_2CYCLES_5);
|
54 |
LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_1, LL_ADC_SINGLE_ENDED);
|
55 |
}
|