内部间隙电压和温度传感器
void ADC_Init(void)
{
/* configure AVDD as reference voltage*/
SYS_UnlockReg();
SYS->VREFCTL |= 1<<4;
SYS_LockReg();
/* Enable EADC module clock */
CLK_EnableModuleClock(EADC_MODULE);
/* EADC clock source is HCLK(72MHz), set divider to 8, ADC clock is 72/8 MHz */
CLK_SetModuleClock(EADC_MODULE, 0, CLK_CLKDIV0_EADC(8));
// /* Configure the GPB9 for ADC analog input pins. */
// SYS->GPB_MFPH &= ~(SYS_GPB_MFPH_PB9MFP_Msk | SYS_GPB_MFPH_PB10MFP_Msk);
// SYS->GPB_MFPH |= SYS_GPB_MFPH_PB9MFP_EADC_CH6 | SYS_GPB_MFPH_PB10MFP_EADC_CH7;
// /* Disable the GPB9 digital input path to avoid the leakage current. */
// GPIO_DISABLE_DIGITAL_PATH(PB, BIT9);
// GPIO_DISABLE_DIGITAL_PATH(PB, BIT10);
/* Set the ADC internal sampling time, input mode as single-end and enable the A/D converter */
EADC_Open(EADC, EADC_CTL_DIFFEN_SINGLE_END);
EADC_SetInternalSampleTime(EADC, 6);
/* Configure the sample module 0 for analog input channel 6 and software trigger source.*/
// EADC_ConfigSampleModule(EADC, 16, EADC_SOFTWARE_TRIGGER, 16);
// EADC_ConfigSampleModule(EADC, 17, EADC_SOFTWARE_TRIGGER, 17);
SYS->IVSCTL |= SYS_IVSCTL_VTEMPEN_Msk;
EADC_ENABLE_SAMPLE_MODULE_INT(EADC, 0, 1<<16);//Enable ADINT0 sample module 16 interrupt .
EADC_ENABLE_SAMPLE_MODULE_INT(EADC, 1, 1<<17);//Enable ADINT1 sample module 17 interrupt.
/* Clear the A/D ADINT0 interrupt flag for safe */
EADC_CLR_INT_FLAG(EADC, 0x3);
/* Enable the sample module 0 interrupt. */
EADC_ENABLE_INT(EADC, 0x3);//Enable sample module A/D ADINT0 interrupt.
NVIC_EnableIRQ(ADC00_IRQn);
NVIC_EnableIRQ(ADC01_IRQn);
} |