找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

帖子
查看: 2703|回復: 3
收起左側

STM32F373的ADC采樣問題,必須采樣轉換2次才有數據,什么原因?

[復制鏈接]
ID:588726 發(fā)表于 2019-7-23 15:42 | 顯示全部樓層 |閱讀模式
本帖最后由 abnsl 于 2019-7-23 15:45 編輯

STM32F373的ADC采樣問題,必須采樣轉換2次才有數據,什么原因?

void AI_ADCInit(void)
{

GPIO_InitTypeDef GPIO_InitStruct;
ADC_InitTypeDef ADC_InitStruct;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
RCC_ADCCLKConfig(RCC_PCLK2_Div6);//72M/6=12, ADC²ÉÑù×î¸ßƵÂÊ14MHz      
   
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AN;
//GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
//GPIO_InitStruct.GPIO_OType=GPIO_OType_PP;
//GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStruct);
//=======================================

ADC_DeInit(ADC1);   
ADC_StructInit(&ADC_InitStruct);

/* initialize the ADC_ScanConvMode member */
  ADC_InitStruct.ADC_ScanConvMode = DISABLE;
  /* Initialize the ADC_ContinuousConvMode member */
  ADC_InitStruct.ADC_ContinuousConvMode = DISABLE;
  /* Initialize the ADC_ExternalTrigConv member */
  ADC_InitStruct.ADC_ExternalTrigConv =ADC_ExternalTrigConv_T19_TRGO;
  /* Initialize the ADC_DataAlign member */
  ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right;
  /* Initialize the ADC_NbrOfChannel member */
  ADC_InitStruct.ADC_NbrOfChannel = 1;
  ADC_Init(ADC1,&ADC_InitStruct);   


void AI_excute(void)
{
    uint16_t i=0,j=0,num=0;

    if((num=Order[1]&0x02))
    {
        printf("AI2 in !\r\n");
        ADC_RegularChannelConfig(ADC1,ADC_Channel_3,1,ADC_SampleTime_239Cycles5);
   
    ADC_Cmd(ADC1,ENABLE);
   
    ADC_ResetCalibration(ADC1);
  while(ADC_GetResetCalibrationStatus(ADC1));
  ADC_StartCalibration(ADC1);
  while(ADC_GetCalibrationStatus(ADC1));
        
    ADC_Cmd(ADC1,ENABLE);//使能第二次
   
    ADC_ClearFlag(ADC1,ADC_FLAG_STRT);
    ADC_SoftwareStartConv(ADC1);
    while(ADC_GetFlagStatus(ADC1,ADC_FLAG_STRT));
    while(ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC));
    Aivalue=ADC_GetConversionValue(ADC1);
    delay_nms(200);
   
    Aivalue=(Aivalue/4096)*3.3;
    ADC_ClearFlag(ADC1,ADC_FLAG_EOC);//ADC_FLAG_EOC/ADC_FLAG_STR

    printf("AI2 value is %f !\r\n",Aivalue);//--------------到這里輸出還是0 ,這一次采樣值為0


ADC_ClearFlag(ADC1,ADC_FLAG_STRT);
    ADC_SoftwareStartConv(ADC1);
    while(ADC_GetFlagStatus(ADC1,ADC_FLAG_STRT));
    while(ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC));
    Aivalue=ADC_GetConversionValue(ADC1);
    delay_nms(200);
   
    Aivalue=(Aivalue/4096)*3.3;//-------------------到這里采樣就正常了,考慮過是否是采樣時間延時不夠,但好像不是這個問題。




}
   


回復

使用道具 舉報

ID:588726 發(fā)表于 2019-7-23 15:44 | 顯示全部樓層
void AI_ADCInit(void)
{

GPIO_InitTypeDef GPIO_InitStruct;
ADC_InitTypeDef ADC_InitStruct;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
RCC_ADCCLKConfig(RCC_PCLK2_Div6);//72M/6=12, ADC²ÉÑù×î¸ßƵÂÊ14MHz         
       
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AN;
//GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
//GPIO_InitStruct.GPIO_OType=GPIO_OType_PP;
//GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStruct);
//=======================================

ADC_DeInit(ADC1);       
ADC_StructInit(&ADC_InitStruct);

/* initialize the ADC_ScanConvMode member */
  ADC_InitStruct.ADC_ScanConvMode = DISABLE;
  /* Initialize the ADC_ContinuousConvMode member */
  ADC_InitStruct.ADC_ContinuousConvMode = DISABLE;
  /* Initialize the ADC_ExternalTrigConv member */
  ADC_InitStruct.ADC_ExternalTrigConv =ADC_ExternalTrigConv_T19_TRGO;
  /* Initialize the ADC_DataAlign member */
  ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right;
  /* Initialize the ADC_NbrOfChannel member */
  ADC_InitStruct.ADC_NbrOfChannel = 1;
  ADC_Init(ADC1,&ADC_InitStruct);       

這是初始化內容
回復

使用道具 舉報

ID:588726 發(fā)表于 2019-8-9 16:12 | 顯示全部樓層
沒有人回答?
回復

使用道具 舉報

ID:588726 發(fā)表于 2019-11-25 21:48 | 顯示全部樓層
還沒有解決
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表