Chapter 2. API Reference
Note For any given channel, this function must be called before the first time adc1_get_raw() is called
for that channel.
Note This function can be called multiple times to configure multiple ADC channels simultaneously. You may
call adc1_get_raw() only after configuring a channel.
Return
• ESP_OK success
• ESP_ERR_INVALID_ARG Parameter error
Parameters
• channel: ADC1 channel to configure
• atten: Attenuation level
esp_err_t adc1_config_width(adc_bits_width_t width_bit)
Configure ADC1 capture width, meanwhile enable output invert for ADC1. The configuration is for all channels
of ADC1.
Return
• ESP_OK success
• ESP_ERR_INVALID_ARG Parameter error
Parameters
• width_bit: Bit capture width for ADC1
int adc1_get_raw(adc1_channel_t channel)
Take an ADC1 reading from a single channel.
Note ESP32: When the power switch of SARADC1, SARADC2, HALL sensor and AMP sensor is turned
on, the input of GPIO36 and GPIO39 will be pulled down for about 80ns. When enabling power
for any of these peripherals, ignore input from GPIO36 and GPIO39. Please refer to section 3.11 of
‘ECO_and_Workarounds_for_Bugs_in_ESP32’for the description of this issue. As a workaround, call
adc_power_acquire() in the app. This will result in higher power consumption (by ~1mA), but will re-
move the glitches on GPIO36 and GPIO39.
Note Call adc1_config_width() before the first time this function is called.
Note For any given channel, adc1_config_channel_atten(channel) must be called before the first time this
function is called. Configuring a new channel does not prevent a previously configured channel from
being read.
Return
• -1: Parameter error
• Other: ADC1 channel reading.
Parameters
• channel: ADC1 channel to read
esp_err_t adc_set_data_inv(adc_unit_t adc_unit, bool inv_en)
Set ADC data invert.
Return
• ESP_OK success
• ESP_ERR_INVALID_ARG Parameter error
Parameters
• adc_unit: ADC unit index
• inv_en: whether enable data invert
esp_err_t adc_set_clk_div(uint8_t clk_div)
Set ADC source clock.
Return
• ESP_OK success
Parameters
• clk_div: ADC clock divider, ADC clock is divided from APB clock
esp_err_t adc_set_data_width(adc_unit_t adc_unit, adc_bits_width_t width_bit)
Configure ADC capture width.
Return
• ESP_OK success
Espressif Systems 219
Submit Document Feedback
Release v4.4