我一直在网上阅读很多内容来确定我的代码中什么不起作用,但似乎我的代码中的 ADC 转换从未开始......不管我做什么,EOC 标志始终保持为 0,我目前正在出主意。使 ADC 工作应该很简单,但由于某种原因,我完全无法使其工作。
如果有人能告诉我我的错误似乎在哪里,我将不胜感激。我正在使用 STM32L100CR-Discovery。
/* Standard includes. */
#include "stm32l1xx.h"
#include "stm32l1xx_rcc.h"
#include "stm32l1xx_gpio.h"
#include "stm32l1xx_exti.h"
#include "stm32l1xx_syscfg.h"
#include "stm32l1xx_spi.h"
#include "stm32l1xx_adc.h"
#include "stdio.h"
#include "misc.h"
void ADC_Initialization (void)
{
ADC_DeInit( ADC1);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
ADC_InitTypeDef ADC_InitStruct;
ADC_InitStruct.ADC_ContinuousConvMode = DISABLE;
ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStruct.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_CC2;
ADC_InitStruct.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStruct.ADC_NbrOfConversion = 1;
ADC_InitStruct.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStruct.ADC_ScanConvMode = DISABLE;
ADC_Init(ADC1, &ADC_InitStruct);
ADC_CommonInitTypeDef ADC_CommonInitStruct;
ADC_CommonInitStruct.ADC_Prescaler = ADC_Prescaler_Div1;
ADC_CommonInit(&ADC_CommonInitStruct);
ADC_Cmd(ADC1, ENABLE);
ADC_BankSelection(ADC1, ADC_Bank_A);
ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 1, ADC_SampleTime_4Cycles);
ADC_TempSensorVrefintCmd (ENABLE);
}
int Read_ADC(void)
{
ADC_SoftwareStartConv(ADC1);
int statut = ADC_GetSoftwareStartConvStatus(ADC1);
printf("%d", statut);
ADC_EOCOnEachRegularChannelCmd(ADC1, ENABLE);
while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
int valeur = ADC_GetConversionValue(ADC1);
return valeur;
}
int main(void)
{
ADC_Initialization();
int ADC_Valeur = 0;
while(1)
{
ADC_Valeur = Read_ADC();
printf("%d", ADC_Valeur);
}
}
提前致谢!