STM32 ADC conversion interrupt read

Publisher:SereneJourneyLatest update time:2018-09-22 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The ADC interrupt reading method is suitable for low-frequency ADC acquisition, while high-frequency AD acquisition must use DMA.

The initialization function of ADC interrupt reading only adds an interrupt configuration file compared to the direct reading method in the previous article. The code is as follows:

static void ADC_GPIO_Config(void)

{

  GPIO_InitTypeDef GPIO_InitStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //ʹÄÜPB,PE¶Ë¿ ÚʱÖÓ

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_1;

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AIN;

GPIO_Init(GPIOA, &GPIO_InitStructure);

}

static void ADC_Mode_Config(void)

{

  ADC_InitTypeDef ADC_InitStructure;

//ADC_GPIO_Config();

RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);

ADC_DeInit(ADC1);

ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;

ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;

ADC_InitStructure.ADC_ScanConvMode=DISABLE;

ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;

ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

ADC_InitStructure.ADC_NbrOfChannel=ADC_Channel_1;

ADC_Init(ADC1,&ADC_InitStructure);

RCC_ADCCLKConfig(RCC_PCLK2_Div8); 

ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_239Cycles5);

ADC_ITConfig(ADC1,ADC_IT_EOC,ENABLE);

  ADC_Cmd(ADC1,ENABLE);

ADC_ResetCalibration(ADC1);

while(ADC_GetResetCalibrationStatus(ADC1));

ADC_StartCalibration(ADC1);

while(ADC_GetCalibrationStatus(ADC1));

ADC_SoftwareStartConvCmd(ADC1,ENABLE);

}

static void ADC_NVIC_Config()

{

NVIC_InitTypeDef NVIC_InitStructure;

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);

       NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

}

void ADC_InitConfig(void)

{

ADC_NVIC_Config();

       ADC_GPIO_Config();

ADC_Mode_Config();

}

The red part above is the code that needs to be added. Analyzing the above code, it actually allows ADC interrupts and sets the interrupt priority.

I won’t post the actual effect pictures, the codes have all been tested. By the way, there is still an interrupt service function that has not been posted.

void ADC1_2_IRQHandler(void)

{

      if(ADC_GetITStatus(ADC1,ADC_IT_EOC) == SET)

{

 adcconverdata=ADC_GetConversionValue(ADC1);

}

ADC_ClearITPendingBit(ADC1,ADC_IT_EOC);

}


Keywords:STM32 Reference address:STM32 ADC conversion interrupt read

Previous article:STM32 ADC single conversion DMA read
Next article:STM32 ADC single conversion example

Recommended ReadingLatest update time:2024-11-23 02:10

STM32 JScope debugging
J-Scope is a software launched by SEGGER that can analyze data in real time and display it graphically while the target MCU is running. Let's learn about J-Scope together. In the previous four documents, we introduced the method of MCU outputting information to the debugging terminal. Today, we will introduce a more
[Microcontroller]
STM32 JScope debugging
stm32 implements printf redirection to LCD display
   Hey, I have been learning stm32 for a while. I used to struggle with a problem, the variable parameters of the (USART) serial port. I finally solved it by looking up a book on C language. I wrote a USART_printf() function that imitates the printf of C language and implements variable parameter processing. I feel a l
[Microcontroller]
STM32 timer detailed explanation ----- shadow register, pre-loaded register
Timer The STM32F10xxx series of 32-bit MCUs have a rich set of timer resources, including advanced control timers, general timers, and basic timers. In addition, there are system tick timers, real-time clocks, and watchdogs that can implement timing functions. The introduction of these timers occupies 1/5 of the STM32
[Microcontroller]
stm32 storage structure & memory map
1 STM32 system architecture     To deeply understand the memory of STM32, you need to first know the system structure of STM32. Figure 1 is a block diagram of the STM32 system structure. According to the description in the STM32 Reference manual (RM0008), as shown in the figure:     You can learn about the com
[Microcontroller]
stm32 storage structure & memory map
STM32 PWM waveform output configuration summary
1. TIMER classification: There are 11 timers in STM32, of which TIM6 and TIM7 are basic timers; TIM2, TIM3, TIM4, and TIM5 are general timers; TIM1 and TIM8 are advanced timers, as well as 2 watchdog timers and 1 system tick timer. The system tick timer is the SysTick described above. Timer Counter resolution Cou
[Microcontroller]
STM32 PWM waveform output configuration summary
STM32 timer for external pulse counting
Because stm32f103c8 is used as the main controller to control the car, the speed of the car is input by two photoelectric encoders (one on the left and one on the right). Therefore, the external clock trigger mode (TIM-ETRClockMode2Config) is considered.         After trying for a long time, I found that TIM1 could
[Microcontroller]
Queues and stacks based on STM32
Use ESP8266 to receive data transmitted from the cloud. The data sent from the cloud may be several groups of data sent at the same time, and the lower computer can only process them one by one. Therefore, it is necessary to establish a buffer array to receive cloud data and then process them one by one -- queue. queu
[Microcontroller]
Queues and stacks based on STM32
Four IO output modes of STM32
1. Normal push-pull output (GPIO_Mode_Out_PP): Application: Generally used in 0V and 3.3V applications. The circuit passes through two P_MOS and N_MOS tubes, which are responsible for pulling up and pulling down current. Usage: Direct use Output level: The low level of push-pull output is 0V and the high level is 3.3V
[Microcontroller]
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号