小学生
最后登录1970-1-1
在线时间 小时
注册时间2023-3-15
|
麻烦帮忙看下这个程序哪里有问题,就是EXIT 11 引脚,我用的是PA11 ADC采集引脚我用的是PA1
void TIM_event_exit(void)
{
//PA1浮空输入
/*----------------------------------------------------------------------*/
GPIO_InitTypeDef GPIO_Init_Def;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_Init_Def.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Init_Def.GPIO_Pin=GPIO_Pin_11;
GPIO_Init(GPIOA,&GPIO_Init_Def);
//打开映射时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
//选择用作 EXTI 线的 GPIO 引脚(EXTICR)EXTICR[3]
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource11);
//映射到AFIO->MAPR-》ADC1_ETRGREG(ADC1规则转换外部触发与EXTI11相连)
GPIO_PinRemapConfig(GPIO_Remap_ADC1_ETRGREG, ENABLE);
//EXTI初始化
EXTI_InitTypeDef EXTI_InitStructure;
EXTI_InitStructure.EXTI_Line=EXTI_Line11;
EXTI_InitStructure.EXTI_LineCmd=ENABLE;
EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Event;
EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Rising;
EXTI_Init(&EXTI_InitStructure);
}
void three_ADC_dma_init_111()
{
//PA1模拟输入
/*----------------------------------------------------------------------*/
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE ); //使能ADC1通道时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; //模拟输入引脚
GPIO_Init(GPIOA, &GPIO_InitStructure);
//ADC时钟+初始化+其他配置
/*----------------------------------------------------------------------*/
ADC_InitTypeDef ADC_InitStruct;
RCC_APB2PeriphClockCmd (RCC_APB2Periph_ADC1, ENABLE );
ADC_InitStruct.ADC_Mode = ADC_Mode_Independent;
ADC_InitStruct.ADC_ScanConvMode = DISABLE;
ADC_InitStruct.ADC_ContinuousConvMode = DISABLE;
ADC_InitStruct.ADC_ExternalTrigConv = ADC_ExternalTrigConv_Ext_IT11_TIM8_TRGO;
ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStruct.ADC_NbrOfChannel = 1;
ADC_Init(ADC1, &ADC_InitStruct);
//外部触发命令使能Trig
ADC_ExternalTrigConvCmd(ADC1,ENABLE);
//重新设置时钟
RCC_ADCCLKConfig(RCC_PCLK2_Div8);
//设置指定ADC的规则组通道,一个序列,采样时间
ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_239Cycles5 ); //ADC1,ADC通道,采样时间为239.5周期
//ADC1中断
ADC_ITConfig( ADC1,ADC_IT_EOC,ENABLE);
//NVIC初始化
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn; //使能按键WK_UP所在的外部中断通道
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01; //抢占优先级1,
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x03; //子优先级3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道
NVIC_Init(&NVIC_InitStructure);
//ADC1启用
ADC_Cmd(ADC1, ENABLE);
//ADC校准
/*----------------------------------------------------------------------*/
//使能复位校准
ADC_ResetCalibration(ADC1);
//等待复位校准结束
while(ADC_GetResetCalibrationStatus(ADC1));
// ADC开始校准
ADC_StartCalibration(ADC1);
// 等待校准完成
while(ADC_GetCalibrationStatus(ADC1));
}
uint16_t ADC_CurrentValue = 0;
void ADC1_2_IRQHandler(void)
{
if(ADC_GetITStatus(ADC1,ADC_IT_EOC)!=RESET)
{
ADC_CurrentValue = (uint16_t)ADC1->DR;
}
}
int main (void)
{
float ADC_RealValue = 0.0;
led_init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
delay_init();
USART_Config();//串口打开、usart_DMA关闭、DMA没开
three_ADC_dma_init_111();
TIM_event_exit();
while(1)
{
ADC_RealValue = (float)ADC_CurrentValue/4096*3.3 + 0.005;
printf("ADC_CurrentValue = %d \r\n", ADC_CurrentValue);
printf("ADC_RealValue = %.2f V \r\n", ADC_RealValue);
delay_ms(1000);
}
|
|