当前位置:网站首页>STM32 ADC acquisition via DMA (HAL Library)

STM32 ADC acquisition via DMA (HAL Library)

2022-06-22 16:45:00 Wax gourd~

One . Preface

 Please add a picture description

ADC Refers to analog-to-digital conversion , That is, converting analog signals into digital signals . The signal essence of the world is analog signal , Such as speed 、 temperature 、 voice , In essence, they are simulated . However, the electronic devices running on microcontrollers and microprocessors cannot directly read or interpret these analog values , Because they are only in 0 and 1 Up operation . So we need to convert these analog values into 0 and 1, So that microcontrollers and microprocessors can understand them . This is what we call the conversion of analog signals into digital signals . And ADC The corresponding is DAC, That is, to convert digital signals into analog signals .

Two . CubeMX To configure

development environment :Keil 、 CubeMX
Software version :5.31 、6.2.1
Using chips :STM32F103C8T6
development language :C

CubeMX The configuration is very simple :Analog->ADCx->INx .


Select multi-channel acquisition here , choice ADC1 , Check IN1 IN2 . The configuration is as follows :

  • Because it is a multi-channel acquisition , To be opened Scan Conversion Mode Scanning mode .
  • Multiple reads are required , So it turns on Continuous Conversion Mode Continuous conversion mode .
  • Optional Rank, to IN1、IN2 Select the appropriate sampling channel and sampling period .

add to DMA passageway , Change the mode to Circular Circulation patterns , So every time DMA After successful transmission, the next transmission will be started .

3、 ... and . ADC Read

Start the function :

HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length)

take ADC Used for reading the remote lever : The essence of the remote lever is a potentiometer , adopt ADC The remote pole can be obtained by collecting the changed voltage X、Y Remote lever value of axis . Follow the above configuration , In the generated Keil Add the following code to the project to get the collected remote rod value .


uint16_t Joystick_ADC[2];

HAL_ADC_Start_DMA(&hadc1,(uint32_t*)&Joystick_ADC,2);


Be careful : If open ADC Of DMA It is possible that the main function cannot continue to run after receiving because the set sampling period is too short , Trigger frequently DMA Accept the interruption . Can be in CubeMX Zhongba Rank Middle channel Sampling period Samplink Time Make it longer , Close test effectively .

原网站

版权声明
本文为[Wax gourd~]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206221524162084.html