ADC1库函数版本,用的原子哥的板子,ADC 1 channel1转换结果一直是0,或者根本没有转换,附上程序,求指教。
[mw_shl_code=c,true]#include "stm32f10x.h"
#include "delay.h"
#include "sys.h"
#include "uart.h"
#include "led.h"
#include "lcd.h"
#include "RCC.h"
#define KEY0 PAin(13) //PA13
#define KEY1 PAin(15) //PA15
#define KEY2 PAin(0) //PA0 WK_UP
#define ADC1_DR_Address ((u32)0x4001244C)
volatile u16 ADCConvertedValue; // AD convert value
//
void ADC1_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
// ????IO??
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_Init(GPIOA,&GPIO_InitStructure);
// ????GPIO?±??
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
// ????ADC?±??
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);
RCC_ADCCLKConfig(RCC_PCLK2_Div8);
// ????ADC
ADC_DeInit(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_1, 1, ADC_SampleTime_55Cycles5);
/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
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));
ADC_SoftwareStartConvCmd(ADC1,ENABLE);
}
//
void DMA_ADC1_Init(void)
{
DMA_InitTypeDef DMA_InitStructure;
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (u32) &ADCConvertedValue;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 1;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
/* Enable DMA1 channel1 */
DMA_Cmd(DMA1_Channel1, ENABLE);
}
//
int main(void)
{
RCC_Init();
delay_init(72); //???±??????
Usart1_Init(9600);
LED_Init();
LCD_Init();
LCD_ShowString(0,16,"This is a demo that shows the Peripherals!");
LCD_ShowString(0,48,"AD Value:");
DMA_ADC1_Init();
ADC1_Init();
while (1)
{
LED0 = 1;
LED1 = 0;
delay_ms(100);
LCD_ShowNum(72,48,ADCConvertedValue,4,16);
LED0 = 0;
LED1 = 1;
delay_ms(100);
LCD_ShowNum(72,48,ADCConvertedValue,4,16);
}
}
[/mw_shl_code]
屏幕显示:AD Value:0 |