用stm32f10x_adc.c中的函数租谨羡调用一下就可以了
提醒一下,在调用ADC_Init之前先把42脚配成AN功能。
然后用
AD_value = ADC_GetConversionValue(ADC1)就晌码可以了。
给你一段参考的弊拍
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent
ADC_InitStructure.ADC_ScanConvMode = DISABLE
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right
ADC_InitStructure.ADC_NbrOfChannel = 1
ADC_Init(ADC1, &ADC_InitStructure)
ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_13Cycles5)
/* Configure high and low analog watchdog thresholds */
ADC_AnalogWatchdogThresholdsConfig(ADC1, 0x0fff, 0x0000)
/* Configure channel8 as the single analog watchdog guarded channel */
ADC_AnalogWatchdogSingleChannelConfig(ADC1, ADC_Channel_0)
/* Enable analog watchdog on one regular channel */
ADC_AnalogWatchdogCmd(ADC1, ADC_AnalogWatchdog_SingleRegEnable)
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE)
ADC_ResetCalibration(ADC1)
/* Check the end of ADC1 reset calibration register */
while(ADC_GetResetCalibrationStatus(ADC1))
/* Start ADC1 calibaration */
ADC_StartCalibration(ADC1)
/* Check the end of ADC1 calibration */
while(ADC_GetCalibrationStatus(ADC1))
/* Start ADC1 Software Conversion */
ADC_SoftwareStartConvCmd(ADC1, ENABLE)
AD_value = ADC_GetConversionValue(ADC1)
可以,但是有种情况,当输出设置成开漏输出,并且配置输出肢御寄存器为高(实际是高组态),只有这种配置下可以当作输入用,读取输入的电平,例如型友I2C;其他情况下也可以读取管脚状态,读出的电平是实卜饥槐际的输出电平。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)