/* Set the SDADC divider: The SDADC should run @6MHz */ /* If Sysclk is 72MHz, SDADC divider should be 12 */ RCC_SDADCCLKConfig(RCC_SDADCCLK_SYSCLK_Div8);
/* Select External reference: The reference voltage selection is available only in SDADC1 and therefore to select the VREF for SDADC2/SDADC3, SDADC1 clock must be already enabled */ SDADC_VREFSelect(SDADC_VREF_Ext );
/* Enter initialization mode */ SDADC_InitModeCmd(SDADC3, ENABLE); SDADCTimeout = 30; /* wait for INITRDY flag to be set */ while(SDADC_GetFlagStatus(SDADC3, SDADC_FLAG_INITRDY) == RESET );
// if(SDADCTimeout == 0) // { // /* INITRDY flag is not set */ // return 1; // }
/* Analog Input configuration conf0: use differential mode and gain = 4 */ SDADC_AINStructure.SDADC_InputMode = SDADC_InputMode_SEZeroReference; SDADC_AINStructure.SDADC_Gain = SDADC_Gain_1 ; SDADC_AINStructure.SDADC_CommonMode = SDADC_CommonMode_VSSA; SDADC_AINStructure.SDADC_Offset = 0; SDADC_AINInit(SDADC3, SDADC_Conf_0, &SDADC_AINStructure);
/* Enable DMA transfer for injected conversions */ //SDADC_DMAConfig(SDADC3, SDADC_DMATransfer_Injected, ENABLE); /* select MPX2102_SDADC channel 6 to use conf0 */ SDADC_ChannelConfig(SDADC3, SDADC_Channel_6, SDADC_Conf_0);
/* configure calibration to be performed on conf0 */ SDADC_CalibrationSequenceConfig(SDADC3, SDADC_CalibrationSequence_1); /* start MPX2102_SDADC Calibration */ SDADC_StartCalibration(SDADC3); /* Set calibration timeout: 5.12 ms at 6 MHz in a single calibration sequence */ SDADCTimeout = 4*30720; /* wait for MPX2102_SDADC Calibration process to end */ while(SDADC_GetFlagStatus(SDADC3, SDADC_FLAG_EOCAL) == RESET); }
在main中 一直读取返回值 while(1) { if(SDADC_GetFlagStatus(SDADC3, SDADC_FLAG_JEOC) != RESET) { /* Get the converted value */ ChannelIndex=SDADC_Channel_6; InjectedConvData = SDADC_GetInjectedConversionValue(SDADC3, &ChannelIndex); } } 并且上面SDADC_GetInjectedConversionValue函数的通道参数选择不能直接用SDADC_Channel_6 不知所以然。。