STM32ADC conversion interrupt read

Publisher:创意狂想Latest update time:2018-10-06 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:STM32ADC conversion interrupt read

Previous article:STM32ADC single conversion DMA read
Next article:STM32ADC single conversion example

Recommended ReadingLatest update time:2024-11-16 21:31

STM32—USART
Preface: Recently, I am debugging the USART configuration program of the STM32L152 chip to realize the STM32 serial port printing function. This article summarizes the usage of the STM32L152 chip USART. Hardware platform: STM32L152 Software platform: keil v5+cubeMX Function library: HAL library 1: usart initia
[Microcontroller]
Thoughts on STM32 port initialization
Problem Description: When working on a BCM project, I found a problem. That is, at the moment of power-on, I found that the light flickered. From the phenomenon, it should be the default value of the port during the initialization process of the BCM controller that caused the external light to flicker. problem solved:
[Microcontroller]
New STMicroelectronics Demonstration Board Helps Advanced Industrial and Consumer Electronics Manufacturers Accelerate Dual-Motor Design
Highly integrated motor controller STSPIN32G4 relies on the STM32 ecosystem to accelerate product development cycle May 31, 2024, China - STMicroelectronics' EVSPIN32G4-DUAL demonstration board can control the operation of two motors with only one highly integrated motor driver STSPIN32G4, acceler
[Industrial Control]
New STMicroelectronics Demonstration Board Helps Advanced Industrial and Consumer Electronics Manufacturers Accelerate Dual-Motor Design
Some issues about STM32 inexplicable crashes
Problem Description ZET6 runs the ucosII system. Sometimes it freezes during operation. After hardware debugging, it is found that this problem is caused by the delay function. There is no problem with the delay function, and this problem occurs occasionally. Troubleshooting After the crash, the pointer points to
[Microcontroller]
STM32 low power settings
      Two months ago, I worked on a low-power project in the company. Now the lowest power consumption is less than 10uA, and the average power consumption is about 40uA, which is up to standard. Because it is a company product, it is not convenient to post the code and schematic diagram. This product is a small module
[Microcontroller]
stm32.cube(四)——HAL.ADC
1. Adc characteristics 1.1 Adc Overview The Adc of Stm32 has 12-bit precision, with 16 external channels and 2 internal channels. A/D conversion of different channels can be performed in single, continuous, scan or intermittent mode. Its other features include support for analog watchdog and DMA. 1.2 Adc initializat
[Microcontroller]
How to draw a schematic diagram of an STM32 microcontroller in a formal way
A common sense about STM32F1 series microcontrollers: From the above figure, we can see that according to the size of the Flash memory, STM32F1 is divided into 4 types, namely "low density", "medium density", "high density", "ultra-high density", and "interconnected type". The FLASH size of the STM32F103VET6 we use
[Microcontroller]
How to draw a schematic diagram of an STM32 microcontroller in a formal way
STM32 timer initialization interrupt problem
     When using the update interrupt of the STM32 timer, it is found that in some cases, an interrupt is immediately entered as long as the timer is turned on. To be precise, as long as the update interrupt enable bit is enabled, an update interrupt is immediately responded to . In other words, as long as the relevant
[Microcontroller]
STM32 timer initialization interrupt problem
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号