ESP32-S3 gpio_set_level() problem

username
Posts: 529
Joined: Thu May 03, 2018 1:18 pm

ESP32-S3 gpio_set_level() problem

Postby username » Thu May 26, 2022 8:55 pm

I started a project for the ESP32-S3 using PlatformIO for Arduino (as they do not support IDF yet).
I am using the ESP32-S3-DevKitC-1 v1.0.

In that project I am using pin 41 tied to my scope to check performance on some functions which worked just fine.

pinMode (40, OUTPUT); // Set Up pin for Timing On scope

digitalWrite(40, LOW); // Signal start of function call
updateOLED(); // Function we are timing
digitalWrite(40, HIGH); // Signal end of call


I preferer to work in ESP-IDF as you get more control over things than in Arduino.
So I installed ESP_IDF v4.4.1 and copied files over and just had to tweak a few lines like above to be compatible with IDF.

gpio_set_direction(40, GPIO_MODE_OUTPUT); // Set Up pin for Timing On scope

gpio_set_level(40, LOW); // Signal start of function call
updateOLED(); // Function we are timing
gpio_set_level(40, HIGH); // Signal end of call

But I get nothing on the pin 40. I then tried 41 and still nothing. I then went back to platromIO, re-flashed and pin 40 worked fine, I then changed it to 41 and that worked fine as well.

AM I doing something wrong to which v4.4.1 does not work for pins higher than 32? Or should I have installed from the master branch when using ESP32-S3 ?

savage
Posts: 23
Joined: Mon Jul 15, 2019 9:24 pm

Re: ESP32-S3 gpio_set_level() problem

Postby savage » Fri May 27, 2022 2:36 pm

Are you measuring the output on your scope? In the off chance you are using gpio_get_level(40), that function will always return 0 if the gpio is set to output.

Otherwise, from what I can see, Arduino's pinMode() makes a call to gpio_config(), which does a few more things than gpio_set_direction(), notably first resetting the pin and configuring the iomux. If you call

Code: Select all

gpio_reset_pin(40)
before gpio_set_direction, does that fix the problem?

username
Posts: 529
Joined: Thu May 03, 2018 1:18 pm

Re: ESP32-S3 gpio_set_level() problem

Postby username » Fri May 27, 2022 3:01 pm

CODE: SELECT ALL

gpio_reset_pin(40)
before gpio_set_direction, does that fix the problem?
Honestly, when I read your response I though to myself I have been using ESP-IDF for years now and have never needed to use gpio_reset_pin(), to make a GPIO pin work properly. There's no way that is the issue. I decided to give your suggestion a try. It worked!

I then went a few steps further as this bothered me.
I tried the following pins without using gpio_reset_pin(). 15,35,36,37,38,39,40,41,42. The only pins that worked out of these was 15,35,36,37,38. I could only get 39,40,41, 42 to work using gpio_reset_pin().

I wonder why this is...

In any event I thank you for the time you took to reply with the solution!

ESP_Sprite
Posts: 9713
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32-S3 gpio_set_level() problem

Postby ESP_Sprite » Sat May 28, 2022 1:44 am

Likely because most ESP-IDF GPIO calls (except gpio_config and gpio_reset_pin) don't touch the GPIO matrix, so pins that are configured as IO for a peripheral (UART, JTAG, USB, ...) will only work as GPIOs after a call that does reset the pins to GPIOs.

savage
Posts: 23
Joined: Mon Jul 15, 2019 9:24 pm

Re: ESP32-S3 gpio_set_level() problem

Postby savage » Sat May 28, 2022 8:06 pm

@ESP_Sprite, any chance the documentation for gpio_set_direction() can be updated to note this behavior? It is very unintuitive that gpio_set_direction() does not always result in an input or output pin. There is already a note under gpio_reset_pin(), but I would not think to do a "reset" for pins that have not been set before (at least not by me) and did not notice the GPIO matrix comment there until after I went poking around the IDF source code.

Who is online

Users browsing this forum: No registered users and 28 guests