本帖最后由 grissiom 于 2011-11-17 10:44 编辑
直接上代码:
- #include <rtthread.h>
- #include "stm32f10x.h"
- void adc_entry(void *param)
- {
- uint16_t adv = 0;
- GPIO_InitTypeDef gpio_conf;
- ADC_InitTypeDef adc_conf;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | \
- RCC_APB2Periph_ADC2 | \
- RCC_APB2Periph_GPIOA,
- ENABLE);
- RCC_ADCCLKConfig(RCC_PCLK2_Div6);
- GPIO_StructInit(&gpio_conf);
- gpio_conf.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
- gpio_conf.GPIO_Mode = GPIO_Mode_AIN;
- GPIO_Init(GPIOA, &gpio_conf);
- ADC_StructInit(&adc_conf);
- adc_conf.ADC_Mode = ADC_Mode_Independent;
- adc_conf.ADC_ScanConvMode = DISABLE;
- adc_conf.ADC_ContinuousConvMode = DISABLE;
- adc_conf.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
- adc_conf.ADC_DataAlign = ADC_DataAlign_Right;
- adc_conf.ADC_NbrOfChannel = 1;
- ADC_Init(ADC1, &adc_conf);
- /* ADC1 regular channels configuration */
- ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 1, ADC_SampleTime_28Cycles5);
- /* Enable ADC1 DMA */
- ADC_Cmd(ADC1, ENABLE);
- /* Enable ADC1 reset calibration register */
- ADC_ResetCalibration(ADC1);
- /* Check the end of ADC1 reset calibration register */
- while(ADC_GetResetCalibrationStatus(ADC1))
- ;
- /* Start ADC1 calibration */
- ADC_StartCalibration(ADC1);
- /* Check the end of ADC1 calibration */
- while(ADC_GetCalibrationStatus(ADC1))
- ;
- while (1) {
- rt_thread_delay(10);
- ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
- ADC_SoftwareStartConvCmd(ADC1, ENABLE);
- while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) != SET)
- ;
- adv = ADC_GetConversionValue(ADC1);
- rt_kprintf("got adv: %d\n\r", adv);
- }
- }
管脚电压应该是 3.27V 左右,但是读数总是 2300 …… 请问软件哪里写错了?……
多谢~;)
|