Home > other >  The conversion of stm32ADC
The conversion of stm32ADC

Time:10-02

Stm32ADC single channel transformation only two IO mouth can be normal use (1.2 can use channel), when use the channel 2 above, IO mouth unable to collect data, novice, bosses answer

CodePudding user response:

Check other channel pin have been occupied, had better send up code, or bad positioning problem

CodePudding user response:

 

# include "ADC. H"
{
ADC_InitTypeDef ADC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_ADC1, ENABLE);//e1? UADC1i ¨ mu ae plus or minus? O

RCC_ADCCLKConfig(RCC_PCLK2_Div6);

GPIO_InitStructure. GPIO_Pin=GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AIN;//? On? Ae? E? Oy??
GPIO_Init (GPIOA, & amp; GPIO_InitStructure);

ADC_DeInit (ADC1);

ADC_InitStructure. ADC_Mode=ADC_Mode_Independent;
ADC_InitStructure. ADC_ScanConvMode=DISABLE;
ADC_InitStructure. ADC_ContinuousConvMode=DISABLE;
ADC_InitStructure. ADC_ExternalTrigConv=ADC_ExternalTrigConv_None;
ADC_InitStructure. ADC_DataAlign=ADC_DataAlign_Right;
ADC_InitStructure. ADC_NbrOfChannel=1;
ADC_Init (ADC1, & amp; ADC_InitStructure);

ADC_Cmd (ADC1, ENABLE);
ADC_ResetCalibration (ADC1);
While (ADC_GetResetCalibrationStatus (ADC1));
ADC_StartCalibration (ADC1);
While (ADC_GetCalibrationStatus (ADC1));
ADC_SoftwareStartConvCmd (ADC1, ENABLE);
}


Under-16 Get_Adc (u8 ch)
{ADC_RegularChannelConfig (ADC1, ch. 1, ADC_SampleTime_239Cycles5);
ADC_SoftwareStartConvCmd (ADC1, ENABLE);
while(! ADC_GetFlagStatus (ADC1, ADC_FLAG_EOC));
Return ADC_GetConversionValue (ADC1);
}

//main program


# include "sys. H"
# include "delay. H"
# include "usart. H"
# include "ADC. H"
# include "LED. H"
# include "math. H"
# include "delay. H"
Int main (void)
{under-16 adcx;
Float t;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
Delay_init ();
Uart_init (115200);
LED_Init ();
Adc_Init ();
While (1)
{
Adcx=Get_Adc (ADC_Channel_2);
T=(float) adcx * (3.3/4096);
If (t<1)
LED0=1;
The else
LED0=0;
}
}

CodePudding user response:

Initialize the set when GPIO_InitStructure. GPIO_Pin=GPIO_Pin_2; Corresponding collection ADC_Channel_2 (adcx=Get_Adc (ADC_Channel_2);) There is no problem!

CodePudding user response:

How do you know if unable to collect data
Look your program without extracting data
In your main loop
Adcx=Get_Adc (ADC_Channel_2);
T=(float) adcx * (3.3/4096);
You which is the extraction of pin

CodePudding user response:

The
reference 4 floor eating steamed bread response:
how do you know if unable to collect data
Look your program without extracting data
In your main loop
Adcx=Get_Adc (ADC_Channel_2);
T=(float) adcx * (3.3/4096);
You which is the extraction of pin

PA2 pin ADC channel 2 is the corresponding PA2. Pin it

CodePudding user response:

How to solve the problem that the code untouched for three days

CodePudding user response:

Bosses, a new found, I tested all ADC1 channel, found that only PA2 a mouth cannot receive data, in the new board for the same

CodePudding user response:

Make sure your CPU have ADC1, 2 other mouth! ?
  • Related