RTC GPIO Functions Not Working

slaughterjim
Posts: 12
Joined: Tue Sep 14, 2021 6:39 pm

RTC GPIO Functions Not Working

Postby slaughterjim » Thu Dec 02, 2021 12:13 am

[Codebox=c file=Untitled.c][/Codebox]

Hardware being used is a Heltec Lora 32(V2) board under Arduino.

Started using GPIO 36 & GPIO 39 as inputs from a Reed Switch.
Was using RTC_GPIO functions. Could not get any inputs, high to low. Using external pullups.
Switched to RTC_GPIO 12 & 13 as inputs, no external pullups but using internal pullups.
Some sample RTC code:
rtc_gpio_deinit(GPIO_NUM_12);
rtc_gpio_deinit(GPIO_NUM_13);
rtc_gpio_set_direction(GPIO_NUM_12, RTC_GPIO_MODE_INPUT_ONLY);
rtc_gpio_set_direction(GPIO_NUM_13, RTC_GPIO_MODE_INPUT_ONLY);
rtc_gpio_pullup_en(GPIO_NUM_12);
rtc_gpio_pullup_en(GPIO_NUM_13);
Was not able to get input transition from Reed Switch.

Decided to switch to GPIO output and toggle GPIO 12. RTC_GPIO functions did not work trying to toggle the outputs on RTC_GPIO 12.

The following does toggles the output
I switched to pinMode() and digitalWrite().
Some code:
pinMode(GPIO_NUM_12,OUTPUT);
delay(200);
while (1) {
digitalWrite(12, HIGH); // sets the digital pin 13 on
delay(1000); // waits for a second
digitalWrite(12, LOW); // sets the digital pin 13 off
delay(1000); // waits for a second
}

The RTC_GPIO functions do not work! Am I missing something setting up to use these RTC Functions?
I need to be able to wake up from Deep Sleep using RTC_GPIO inputs.
What am I missing?
I have not tried to use the pinMode and digitalWrite in my code base to get inputs from Reed Switch. That's next.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: RTC GPIO Functions Not Working

Postby WiFive » Thu Dec 02, 2021 3:12 am

Why are you calling rtc_gpio_deinit instead of rtc_gpio_init

slaughterjim
Posts: 12
Joined: Tue Sep 14, 2021 6:39 pm

Re: RTC GPIO Functions Not Working

Postby slaughterjim » Thu Dec 02, 2021 3:06 pm

I am specifying the GPIO pin as a digital input, not an analog input.I saw this method in some example code on the forum.
I take it I should call rtc_gpio_init.
Will try this.

slaughterjim
Posts: 12
Joined: Tue Sep 14, 2021 6:39 pm

Re: RTC GPIO Functions Not Working

Postby slaughterjim » Thu Dec 02, 2021 3:14 pm

I found the function in a esp32 document and the wording indicates it is for analog pin:
esp_err_trtc_gpio_init(gpio_num_tgpio_num)
Init a GPIO as RTC GPIO.
This function must be called when initializing a pad for an analog function.

So I did not think it applied for digital pin.

slaughterjim
Posts: 12
Joined: Tue Sep 14, 2021 6:39 pm

Re: RTC GPIO Functions Not Working

Postby slaughterjim » Mon Dec 06, 2021 5:05 am

I tried rtc_gpio_init().
I still do not get an output.
I also called the function to see if GPIO_NUM_12 was an RTC GPIO. It returned TRUE.
Stuck on this one.

felmue
Posts: 70
Joined: Mon Nov 16, 2020 2:55 pm

Re: RTC GPIO Functions Not Working

Postby felmue » Mon Dec 06, 2021 8:00 am

Hello @slaughterjim
Hardware being used is a Heltec Lora 32(V2) board under Arduino.

since you are using Arduino. May I ask why you are trying to use any of the gpio* functions directly? What am I missing here?

I suggest you check out this example on how to setup deep sleep using Arduino functions: https://randomnerdtutorials.com/esp32-d ... p-sources/?

Thanks
Felix

slaughterjim
Posts: 12
Joined: Tue Sep 14, 2021 6:39 pm

Re: RTC GPIO Functions Not Working

Postby slaughterjim » Tue Dec 07, 2021 3:37 pm

The Arduino functions seemed like the way to go. I have never gotten the inputs or my output test to work.
I switched to pinMode(). I am able to generate a GPIO (pin 12) wakeup from deep sleep.
Things go bad after this first wakeup, but I am working that issue.
I am reading the document that was referenced. Thanks.

slaughterjim
Posts: 12
Joined: Tue Sep 14, 2021 6:39 pm

Re: RTC GPIO Functions Not Working

Postby slaughterjim » Tue Dec 07, 2021 5:07 pm

When I wake from esp_deep_sleep_start() using ext0, what do I need to do in my code?
Do I need to do a pinMode again? Do I need to enable pullup's again?
Initial setup I am using:
pinMode(GPIO_NUM_12,INPUT_PULLUP);
pinMode(GPIO_NUM_13,INPUT_PULLUP);

I determine the wakeup source and go process either GPIO 12 or GPIO 13. Only 1 GPIO will wake up so I am using ext0 since I need a LOW (going HIGH to LOW).
esp_sleep_enable_ext0_wakeup(GPIO_NUM_12, LOW);

I can wake up once correctly. Seems I am not setting something before I go back to sleep?
I cannot find anything in the document that was specified in previous response.
Thanks.

slaughterjim
Posts: 12
Joined: Tue Sep 14, 2021 6:39 pm

Re: RTC GPIO Functions Not Working

Postby slaughterjim » Tue Dec 07, 2021 7:16 pm

Ok I found this function esp_deep_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_AUTO);
Will try it.

Who is online

Users browsing this forum: Majestic-12 [Bot] and 96 guests