不知道为什么会卡在while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC));
没转换完?大佬们给看看吧
ADC.c
[mw_shl_code=c,true]#include "ADC.h"
#include "delay.h"
void ADC1_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_ADC1,ENABLE);
RCC_ADCCLKConfig(RCC_PCLK2_Div6);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_Init(GPIOA,&GPIO_InitStructure);
ADC_DeInit(ADC1);
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_NbrOfChannel = 1;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_Init(ADC1,&ADC_InitStructure);
ADC_Cmd(ADC1,ENABLE);
ADC_ResetCalibration(ADC1);
while(ADC_GetResetCalibrationStatus(ADC1));
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1));
}
u16 Get_ADC1(u8 times)
{
float ADC1_temp;u8 i;
ADC_RegularChannelConfig(ADC1,ADC_Channel_1,1,ADC_SampleTime_239Cycles5);
ADC_SoftwareStartConvCmd(ADC1,ENABLE);
ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
for(i=times;i>1;i--)
{
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC));
ADC1_temp += ADC_GetConversionValue(ADC1);
delay_ms(5);
ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
}
return (ADC1_temp/times);
}
[/mw_shl_code]
main.c
[mw_shl_code=c,true]#include "stm32f10x.h"
#include "usart.h"
#include "ADC.h"
#include "led.h"
#include "sys.h"
#include "delay.h"
int main(void)
{
u16 average_ADC1;
ADC1_Init();
Led_Init();
uart_init(115200);
delay_init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
while(1)
{
Led0_Delay(500,500);
average_ADC1 = Get_ADC1(10);
delay_ms(10);
printf("average_ADC1:%d
",average_ADC1);
}
}
// GPIO_InitTypeDef GPIO_InitStructure;
[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
是的,战舰
我的想法是刷新标志位,这样下次累加的是又一次转换得到的值
这个函数是怎么写的
一周热门 更多>