ADC Manager Mode
This sample code guide is designed to help users easily and comprehensively understand ADC sample. This sample demonstrates how ADC samples data by ADC manager. This sample uses one shot mode of the ADC peripheral to measure voltage on VBAT and VADP by ADC manager.
Requirements
For hardware requirements, please refer to the Requirements.
Wiring
Connect Lithium-ion battery to EVB.
Connect VADP to 5V of EVB.
Configurations
The following macros can be configured to modify the sampling period.
#define TEST_CYCLE (3)
The following macros can be configured to modify the number of samples per sampling cycle.
#define TEST_COUNT (100)
The entry function is as follows, call this function in
main()
to run this sample code. For more details, please refer to the Initialization.adc_manager_demo();
Building and Downloading
For building and downloading, please refer to the Building and Downloading.
Experimental Verification
Press the Reset button on the EVB board, ADC samples every 100ms, there are three sampling cycles, and each sampling cycle samples 100 times. Once ADC sampling is finished, the raw data collected and the converted voltage values will be printed in Debug Analyzer.
adc_cb: seq xxx, adc_data[0] xxx, adc_data[1] xxx
Code Overview
This section introduces the code and process description for initialization and corresponding function implementation in the sample. When the internal charger is enabled, it is necessary to use ADC manager mode for ADC sampling.
Source Code Directory
For project directory, please refer to Source Code Directory.
Source code directory:
sdk\src\sample\io_demo\adc\adc_manger\adc_manager_demo.c
.
Initialization
The initialization flow of ADC sampling in one shot mode by ADC manager is shown in the following figure.

ADC One Shot Sampling by ADC Manager Mode
Initialize the ADC peripheral:
Define the
ADC_InitTypeDef
typeADC_InitStruct
, and callADC_StructInit()
to pre-fillADC_InitStruct
with default values.Modify the
ADC_InitStruct
parameters as needed. The ADC initialization parameter configuration is shown in the table below.Call
adc_mgr_register_req()
to request for a channel in ADC manager and initialize the ADC peripheral.
ADC Initialization Parameters ADC Hardware Parameters
Setting in the
ADC_InitStruct
VariablesADC
Sample Time
Bit Map
0x0003
Schedule Index
Index 0 is set to
INTERNAL_VBAT_MODE
.Index 1 is set to
INTERNAL_VADPIN_MODE
.Call
adc_mgr_enable_req()
to enable the specific ADC manager channel for sampling.
Functional Implementation
Callback Handle
When ADC sampling is completed, ADC manager callback function will be executed. ADC manager callback handle flow is shown in the following figure.

ADC Manager Callback Handle Flow
Call
adc_mgr_read_data_req()
to read ADC sampling raw data of the specific ADC manager channel.