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?
Reconfigure GPIO as output after analog read
Re: Reconfigure GPIO as output after analog read
Code: Select all
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);
gpio_set_level(PIN_LED_RELAY3, 1);
try...
gpio_reset_pin(PIN_LED_RELAY2);
gpio_set_direction(PIN_LED_RELAY2, GPIO_MODE_OUTPUT);
gpio_set_level(PIN_LED_RELAY2, 1);
Re: Reconfigure GPIO as output after analog read
Solved:
it's necessary to call
rtc_gpio_deinit(PIN_LED_RELAY3);
In this way the pin is connected again to GPIO Matrix instead of RTC Matrix.
it's necessary to call
rtc_gpio_deinit(PIN_LED_RELAY3);
In this way the pin is connected again to GPIO Matrix instead of RTC Matrix.
Who is online
Users browsing this forum: No registered users and 116 guests