ADC Example#
Introduction#
This example demonstrates the basic usage of the K230 ADC HAL: initializing the ADC, reading raw values from a specified channel, and converting them to voltage values based on the reference voltage.
Source code location: src/rtsmart/examples/peripheral/adc/test_adc.c
Example Behavior#
Supports command-line arguments to select the ADC channel
Supports selecting the reference voltage (only
1.8Vor3.6V)Outputs the raw value and converted voltage once per second
Supports Ctrl+C to exit and deinitialize the ADC
Key Interfaces#
drv_adc_init()drv_adc_read(channel)drv_adc_read_uv(channel, ref_uv)drv_adc_deinit()
Build and Run#
cd src/rtsmart/examples/peripheral/adc
make
Run:
./test_adc [channel] [ref_uv]
Parameter description:
channel: ADC channel number, range0..DRV_ADC_MAX_CHANNEL-1, default0ref_uv: Reference voltage (microvolts), only1800000or3600000are supported, defaultDRV_ADC_DEFAULT_REF_UV
Examples:
./test_adc
./test_adc 1 1800000
./test_adc 2 3600000
Output Example#
ADC Test Application
Reading channel 0 with reference 1.80V
Press Ctrl+C to stop...
Channel 0: Raw=0x123 ( 291), Voltage=1.0245V (1024500 uV)
Tip
For details on the ADC interface, please refer to the ADC API Documentation.
