Home > other >  STM32F1 serial ADC continuous conversion interrupt register read data based on single channel
STM32F1 serial ADC continuous conversion interrupt register read data based on single channel

Time:09-25



# include "adc. H"


Under-16 ADC_NUM=0;

Void adc_init (void)
{
RCC - & gt; APB2ENR |=1 & lt; <2;//open PA clock
GPIOA - & gt; CRL&=0 xffffff0f;
GPIOA - & gt; The CRL |=0 x00000000;//PA1 analog input

RCC - & gt; APB2ENR |=1 & lt; <9.//open ADC1 clock
RCC - & gt; APB2RSTR |=1 & lt; <9.//ADC1 reset
RCC - & gt; APB2RSTR & amp;=~ (1 & lt; <9);//stop ADC1 reset
RCC - & gt; CFGR&=~ (3 & lt; <14);//ADC1 divider coefficient reset
RCC - & gt; CFGR |=2 & lt; <14.//PCLK2 after 6 minutes and frequency as the ADC clock

ADC1 - & gt; CR1 & amp;=~ (0 xf & lt; <16);//work mode reset
ADC1 - & gt; CR1 |=0 & lt; <16.//independent work mode
ADC1 - & gt; CR1 & amp;=~ (1 & lt; <8);//not scan mode
ADC1 - & gt; CR1 |=1 & lt; <5;//interrupt
MY_NVIC_Init (1, 3, ADC1_2_IRQn, 2);//set the interrupt priority specific setting methods don't posted here
ADC1 - & gt; CR2 |=1 & lt; <1;//continuous mode
ADC1 - & gt; CR2 |=1 & lt; <20;//external trigger rule channel conversion mode
ADC1 - & gt; CR2 & amp;=~ (7 & lt; <17);
ADC1 - & gt; CR2 |=7 & lt; <17.//software control conversion
ADC1 - & gt; CR2 & amp;=~ (1 & lt; <11);//data right-aligned

ADC1 - & gt; SQR3 & amp;=0 xffffffe0;//the first conversion in a sequence of rules reset
ADC1 - & gt; SQR3 |=1.

ADC1 - & gt; SQR1 & amp;=~ (0 xf & lt; <20);
ADC1 - & gt; SQR1 |=0 & lt; <20;//a transformation rules in a sequence of
ADC1 - & gt; SMPR2 & amp;=~ (7 & lt; <3);
ADC1 - & gt; SMPR2 |=7 & lt; <3;//channel 1 cycle of sampling time 239.5

ADC1 - & gt; CR2 |=1 & lt; <0;//open ADC1 conversion
ADC1 - & gt; CR2 |=1 & lt; <3;//that can reset the calibration
While (ADC1 - & gt; CR2 & amp; 1<3);//waiting for the end of the calibration
ADC1 - & gt; CR2 |=1 & lt; <2;//open AD calibration
While (ADC1 - & gt; CR2 & amp; 1<2);//waiting for the end of the calibration

ADC1 - & gt; CR2 |=1 & lt; <22.//open rules conversion

}

Void ADC1_2_IRQHandler (void)
{
If (ADC1 - & gt; SR& (1 & lt; <1))
{
ADC_NUM=ADC1 - & gt; DR.
}
ADC1 - & gt; SR&=~ (1 & lt; <1);

}


The main function

Serial implementation function did not stick out, everyone should baidu

# include "sys. H"
# include "usart. H"
# include "delay. H"
# include "led. H"
# include "adc. H"


Int main (void)
{
Float VV=0;
Stm32_Clock_Init (9);//the system clock Settings
Delay_init (72);//delay initialization
Uart_init (72115, 200);//initialize serial port 115200
Led_init ();//the LED initialization
Adc_init ();//ADC initialization
While (1)
{
V. v.=3.3/4096 (float) ADC_NUM *;
Printf (" voltage value is - & gt; % 2 fv \ r \ n ", VV);
LED0=! LED0;
Delay_ms (200);
}
}
Time is hasty subsequent correct post again
  • Related