Blue Bridge Cup [Internet of Things] Road from zero foundation to national award: 15. Dual-channel ADC of expansion module
Section 1 Hardware Interpretation
The ADC of STM32 is 12-bit, extended to 16-bit by hardware oversampling, and the analog-to-digital converter is embedded in the STM32L071xx device. There are 16 external channels and 2 internal channels (temperature sensor, voltage reference). Three channels, PA0, PA4 and PA5 are fast channels, while the others are standard channels.
The ADC performs conversions in single or scan mode. In scan mode, conversions are automatically performed on a selected set of analog inputs.
The ADC frequency is independent of the MCU frequency, allowing maximum sampling, even at low MCU speeds, at a rate of 1.14MSPS. The ADC power consumption is extremely low.
Section 2 CubeMX Configuration
Click ADC to enable IN8 IN9, then enable Discontinuous, and then label them. PB0 is AIN2 (the second knob) and PB1 is AIN1 (the first knob).
Section 3 Code Writing
Write the adcread function.
Create data and value arrays, read twice and convert and store them in the value array, and close adc after reading. Swap
the first two digits of adc_value.
Create a float pointer in the main function to read the array.