Reconfigure GPIO as output after analog read
Posted: Tue Oct 11, 2022 12:10 pm
Hi,
to automatically configure firmware I need to read the voltage of a pin (GPIO13) that is normally used as output. Unfortunately it's not useful to read the logic level (same value for the two hardware configurations) so I need to use ADC.
The code is:
#define PIN_LED_RELAY2 13
int adc_raw;
ESP_ERROR_CHECK(adc1_config_width(ADC_WIDTH_BIT_DEFAULT));
ESP_ERROR_CHECK(adc2_config_channel_atten(ADC2_CHANNEL_4, ADC_ATTEN_11db));
vTaskDelay(100 / portTICK_PERIOD_MS);
adc2_get_raw(ADC2_CHANNEL_4, ADC_WIDTH_BIT_DEFAULT, &adc_raw);
printf("IO13: %d\n", adc_raw);
if (adc_raw > 1500)
nRelay = 2;
// reconfigure GPIO as output
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[PIN_LED_RELAY2], PIN_FUNC_GPIO);
gpio_set_direction(PIN_LED_RELAY2, GPIO_MODE_OUTPUT);
gpio_set_level(PIN_LED_RELAY3, 1);
But in this way setting or resetting GPIO13 has no effect while it works if I comment analog read section.
What can I do to reconfigure GPIO13 as output?
to automatically configure firmware I need to read the voltage of a pin (GPIO13) that is normally used as output. Unfortunately it's not useful to read the logic level (same value for the two hardware configurations) so I need to use ADC.
The code is:
#define PIN_LED_RELAY2 13
int adc_raw;
ESP_ERROR_CHECK(adc1_config_width(ADC_WIDTH_BIT_DEFAULT));
ESP_ERROR_CHECK(adc2_config_channel_atten(ADC2_CHANNEL_4, ADC_ATTEN_11db));
vTaskDelay(100 / portTICK_PERIOD_MS);
adc2_get_raw(ADC2_CHANNEL_4, ADC_WIDTH_BIT_DEFAULT, &adc_raw);
printf("IO13: %d\n", adc_raw);
if (adc_raw > 1500)
nRelay = 2;
// reconfigure GPIO as output
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[PIN_LED_RELAY2], PIN_FUNC_GPIO);
gpio_set_direction(PIN_LED_RELAY2, GPIO_MODE_OUTPUT);
gpio_set_level(PIN_LED_RELAY3, 1);
But in this way setting or resetting GPIO13 has no effect while it works if I comment analog read section.
What can I do to reconfigure GPIO13 as output?