Page 1 of 2

trying to read an ADC GPIO

Posted: Thu Jun 21, 2018 7:56 pm
by mzimmers
...the docs make it seem fairly straightforward, so I must be doing it wrong. BATTERY_EN_NBR refers to an output pin that tells the batter controller to output its voltage level (to pin GPIO35). I assert the enable pin, do the ADC stuff, and clear the enable pin (to prevent further battery drawdown).

Code: Select all

#define BATTERY_EN_NBR (GPIO_NUM_32)
int voltage;
...
ESP_ERROR_CHECK(gpio_set_level(BATTERY_EN_NBR, 1));
ESP_ERROR_CHECK(adc1_config_width(ADC_WIDTH_BIT_10));
ESP_ERROR_CHECK(adc1_config_channel_atten(ADC1_CHANNEL_7, ADC_ATTEN_DB_11));
voltage = adc1_get_raw(ADC1_CHANNEL_7);
ESP_LOGI(TAG, "battery voltage is %x.", voltage);
ESP_ERROR_CHECK(gpio_set_level(BATTERY_EN_NBR, 0));
I run this in a loop, and get pure 0s in my voltage variable. Where might I be botching this?

Re: trying to read an ADC GPIO

Posted: Thu Jun 21, 2018 10:52 pm
by kolban
I'd suggest wiring GPIO 35 directly to 3.3V and see if the output is other than 0. That will eliminate half the logic as a problem.

Re: trying to read an ADC GPIO

Posted: Thu Jun 21, 2018 11:15 pm
by WiFive
Did you configure gpio32 as a gpio (normally a 32k crystal pin) and enable its output driver?

Re: trying to read an ADC GPIO

Posted: Thu Jun 21, 2018 11:37 pm
by mzimmers
No, I didn't...oops. So, disable pullup/pushdown/interrupts, set as output and call gpio_config()?

I'm not sure what it means to enable the output driver.

Thanks...

Re: trying to read an ADC GPIO

Posted: Fri Jun 22, 2018 3:09 am
by WiFive
Configuring it as an output is the same

Re: trying to read an ADC GPIO

Posted: Fri Jun 22, 2018 4:19 am
by mikemoy
There is a post here by rudi ;-) that talks about it:
viewtopic.php?f=12&t=1408&p=6568&hilit=gpio32#p6568

Specifically here in that post:
you need first to clear the base bits if you want to use the GPIO32 and GPIO33 as the general GPIO

Code: Select all

REG_CLR_BIT(RTC_IO_XTAL_32K_PAD_REG, RTC_IO_X32P_MUX_SEL); /* gpio32 route to digital io_mux */
REG_CLR_BIT(RTC_IO_XTAL_32K_PAD_REG, RTC_IO_X32N_MUX_SEL); /* gpio33 route to digital io_mux */

Re: trying to read an ADC GPIO

Posted: Fri Jun 22, 2018 3:20 pm
by mzimmers
Thanks for the help...the suggestions seem to have gotten it working.

Re: trying to read an ADC GPIO

Posted: Fri Jun 22, 2018 8:31 pm
by mzimmers
Except...

...it turns out that I need to keep GPIO 32 as is...changing its configuration causes problem with the clock.

So, before I go picking another GPIO at random, is there a master list somewhere that explains which GPIOs are pre-allocated, and which are free? I couldn't find this information in the page on GPIOs.

Thanks...

Re: trying to read an ADC GPIO

Posted: Fri Jun 22, 2018 11:32 pm
by kolban
This is the page I normally go to:

http://esp-idf.readthedocs.io/en/latest ... /gpio.html

If it needs updating with new findings, post about it.

Re: trying to read an ADC GPIO

Posted: Sun Jun 24, 2018 3:48 pm
by mzimmers
Hi, Neil - I don't think that page necessarily needs updating. I was just hoping that there would be a location where all the pertinent information for GPIOs (including any use by the ESP32 module itself, for example GPIO32 which evidently is the input to the RTC). We chose GPIO32 for our application use because our HW guy didn't know it was pre-allocated. So, the question is, where do we go to see if another pin we choose is free or allocated?