PORT_Init(PORTC, PIN6, PORTC_PIN6_SDADC_CH0P, 0); //PC.6 => SDADC.CH0P
PORT_Init(PORTC, PIN7, PORTC_PIN7_SDADC_CH0N, 0); //PC.7 => SDADC.CH0N
PORT_Init(PORTC, PIN4, PORTC_PIN4_SDADC_CH1P, 0); //PC.4 => SDADC.CH1P
PORT_Init(PORTC, PIN5, PORTC_PIN5_SDADC_CH1N, 0); //PC.5 => SDADC.CH1N
PORT_Init(PORTC, PIN2, PORTC_PIN2_SDADC_CH3P, 0); //PC.2 => SDADC.CH3P
PORT_Init(PORTC, PIN3, PORTC_PIN3_SDADC_CH3N, 0); //PC.3 => SDADC.CH3N
PORT_Init(PORTD, PIN0, PORTD_PIN0_SDADC_CH4P, 0); //PD.0 => SDADC.CH4P
PORT_Init(PORTD, PIN1, PORTD_PIN1_SDADC_CH4N, 0); //PD.1 => SDADC.CH4N
PORT_Init(PORTB, PIN14,PORTB_PIN14_SDADC_CH5P,0); //PB.14=> SDADC.CH5P
PORT_Init(PORTB, PIN15,PORTB_PIN15_SDADC_CH5N,0); //PB.15=> SDADC.CH5N
SDADC_initStruct.clk_src = SDADC_CLKSRC_HRC_DIV8;
SDADC_initStruct.channels = SDADC_CH2;
SDADC_initStruct.out_cali = SDADC_OUT_CALIED;
SDADC_initStruct.refp_sel = SDADC_REFP_AVDD;
SDADC_initStruct.trig_src = SDADC_TRIGSRC_SW;
SDADC_initStruct.Continue = 0; //非连续模式,即单次模式
SDADC_initStruct.EOC_IEn = 0;
SDADC_initStruct.OVF_IEn = 0;
SDADC_initStruct.HFULL_IEn = 0;
SDADC_initStruct.FULL_IEn = 0;
SDADC_Init(SDADC, &SDADC_initStruct); //配置SDADC
SDADC_Config_Set(SDADC, SDADC_CFG_A, SDADC_CFG_GAIN_1, 1, 1);
SDADC_Config_Cali(SDADC, SDADC_CFG_A, SDADC_CALI_COM_GND, 0);
SDADC_Config_Sel(SDADC, SDADC_CFG_A, SDADC_CH0 | SDADC_CH1 | SDADC_CH2);
SDADC_Config_Set(SDADC, SDADC_CFG_B, SDADC_CFG_GAIN_1, 0, 0);
SDADC_Config_Cali(SDADC, SDADC_CFG_B, SDADC_CALI_COM_GND, 0);
SDADC_Config_Sel(SDADC, SDADC_CFG_B, SDADC_CH3 | SDADC_CH4 | SDADC_CH5);
SDADC_Open(SDADC); //使能SDADC
while(1==1)
{
SDADC_Start(SDADC);
while((SDADC->STAT & SDADC_STAT_EOC_Msk) == 0);
SDADC->STAT = 1 << SDADC_STAT_EOC_Pos;
res = SDADC_Read(SDADC, &chn);
printf("%6d,", res);
for(i=0; i<800; i++); //此延时是必须的,缩短后可能导致SDADC不工作
}
}
例子中ADC转换用的是什么引脚,采样电压正端接哪个引脚,负端接哪个引脚 |