ADC初始化:
void Open_Volume_Knob(void)
{
uint32_t ADC_Source_Clock_DIV;
/* Initial ADC Function Pin */
SYS->PA_L_MFP = (SYS->PA_L_MFP & ~SYS_PA_L_MFP_PA0_MFP_Msk) | SYS_PA_L_MFP_PA0_MFP_ADC_CH0;
GPIO_DISABLE_DIGITAL_PATH(PA, BIT0);
/* Safe for other unknown ADC device */
while(ADC_IS_BUSY(ADC));
SYS_UnlockReg();
/* Initial ADC Clock Source */
ADC_Source_Clock_DIV = _ADC_Source_Clock / ADC_Clock;
if(ADC_Source_Clock_DIV>256)
{
Open_Volume_Knob_Fail = TRUE;
ADC_Source_Clock_DIV = 256;
ADC_Clock = _ADC_Source_Clock / 256;
printf("\nADC Clock Initial Fail!\n");
}
else
{
Open_Volume_Knob_Fail = FALSE;
}
CLK_SetModuleClock(ADC_MODULE, CLK_CLKSEL1_ADC_S_HXT, CLK_ADC_CLK_DIVIDER(ADC_Source_Clock_DIV));
CLK_EnableModuleClock(ADC_MODULE);
SYS_LockReg();
/* Initial ADC Peripheral */
ADC_Open(ADC, ADC_INPUT_MODE_SINGLE_END, ADC_OPERATION_MODE_SINGLE_CYCLE, ADC_CH_0_MASK);
ADC_SET_RESOLUTION(ADC, ADC_RESSEL_12_BIT);
ADC_SET_REF_VOLTAGE(ADC, ADC_REFSEL_POWER);
ADC_CLR_INT_FLAG(ADC, ADC_ADF_INT);
ADC_POWER_ON(ADC);
}
|