stm32f103 ADC Configuration _stm32

Source: Internet
Author: User


#include "stm32f10x.h" U16 Adcconvertedvalue;
	int main () {gpio_inittypedef m_gpio_inittypedef;
	 
	Adc_inittypedef adc_initstructure; Rcc_apb2periphclockcmd (Rcc_apb2periph_gpioa | rcc_apb2periph_gpiob,enable)/Open APB2 clock, GPIO are hung on the APB2 m_gpio_inittypedef.gpio_pin = gpio_pin_14 |
	gpio_pin_7;	M_gpio_inittypedef.gpio_mode = gpio_mode_out_pp;	Push-Pull output m_gpio_inittypedef.gpio_speed = Gpio_speed_2mhz;				Speed 2M Gpio_init (gpiob,&m_gpio_inittypedef);
	GPIO initialization m_gpio_inittypedef.gpio_pin = gpio_pin_6;
	M_gpio_inittypedef.gpio_mode = Gpio_mode_ain;
	M_gpio_inittypedef.gpio_speed = Gpio_speed_2mhz;				Gpio_init (GPIOA,&M_GPIO_INITTYPEDEF);
	Gpio initialization of Rcc_adcclkconfig (RCC_PCLK2_DIV2); Rcc_apb2periphclockcmd (RCC_APB2PERIPH_ADC1 |	  Rcc_apb2periph_gpioa, ENABLE);  Open the ADC1 APB2 clock adc_initstructure.adc_mode = adc_mode_independent;		ADC1 and ADC2 work in independent mode Adc_initstructure.adc_scanconvmode = DISABLE;	ADC works in single channel mode adc_initstructure.adc_continuousconvmode = ENABLE; ADC work in single mode adc_initstructure.adc_externaltrigconv = Adc_externaltrigconv_none;	The conversion is triggered by the software rather than by the external trigger adc_initstructure.adc_dataalign = Adc_dataalign_right;
	ADC Data Right-aligned adc_initstructure.adc_nbrofchannel = 1;


	Adc_init (ADC1, &adc_initstructure);
	Adc_regularchannelconfig (ADC1, Adc_channel_6, 1, adc_sampletime_28cycles5);				Adc_itconfig (adc1,adc_it_eoc,enable);			  Open Conversion End Interrupt Adc_cmd (ADC1, ENABLE);		 Enable ADC1 Converter while (1) {Adc_softwarestartconvcmd (ADC1, enable); Enable ADC1 software conversion startup function while (! Adc_getflagstatus (ADC1, ADC_FLAG_EOC));			Wait for conversion to end if (Adcconvertedvalue > 1800) {gpio_writebit (gpiob,gpio_pin_7, Bit_set);
		Clear Gpb_7 Light LEDs} else if (Adcconvertedvalue <) {Gpio_writebit (gpiob,gpio_pin_14, Bit_set); else {gpio_writebit (gpiob,gpio_pin_14 |
		Gpio_pin_7, Bit_reset);
    }} void Adc1_irqhandler () {adcconvertedvalue = Adc_getconversionvalue (ADC1);			Gpio_writebit (gpiob,gpio_pin_14, Bit_reset); Clear Gpb_14 Light led Adc_clearitpendiNgbit (ADC1,ADC_IT_EOC); }


can be converted, but cannot enter the interrupt, do not know where the configuration error





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.