How to use registers for GPIO in ESP32

filo_gr
Posts: 109
Joined: Wed Jul 28, 2021 12:25 pm
Location: Italy

How to use registers for GPIO in ESP32

Postby filo_gr » Fri Sep 24, 2021 12:48 pm

Hello community,

I'd like to understand how to set GPIO of my ESP32 using registers instead of the ESP-IDF functions gpio_set_direction, gpio_set_level, gpio_get_level, etc...
I looked at the programming guide but I didn't find anything that explains this.
So I moved on the technical reference https://www.espressif.com/sites/default ... ual_en.pdf and in chapter 4 it talks about IO_MUX and GPIO Matrix (GPIO, IO_MUX).
However there aren't examples, then it's not clear what I should do to set up registers.
Is there anyone who has been able to use registers? Is it a good idea?

Thanks in advance,
Filippo
Filippo

User avatar
mbratch
Posts: 298
Joined: Fri Jun 11, 2021 1:51 pm

Re: How to use registers for GPIO in ESP32

Postby mbratch » Fri Sep 24, 2021 8:15 pm

If you're asking if it's a good idea, I'm wondering: why do you want to do it that way instead of using the provided API? The benefit of the API is that the code is a bit more portable (e.g., if you want to use it on a different MCU in the ESP32 family that might have a slightly different underlying register structure).


filo_gr
Posts: 109
Joined: Wed Jul 28, 2021 12:25 pm
Location: Italy

Re: How to use registers for GPIO in ESP32

Postby filo_gr » Mon Sep 27, 2021 6:16 am

mbratch wrote:
Fri Sep 24, 2021 8:15 pm
If you're asking if it's a good idea, I'm wondering: why do you want to do it that way instead of using the provided API?
The main answer is that I know Arduino Wiring pretty well, however I also know it limitates the features which you could have programming it at a low level language. I can use pinMode() for every pin, or I can program its registers in one fell swoop.
I see a lot of similarities between Arduino IDE's Wiring and ESP-IDF, that's why I'm so curious about it.
Very nice example, I'll look at it and I'll try to understand it.
Filippo

filo_gr
Posts: 109
Joined: Wed Jul 28, 2021 12:25 pm
Location: Italy

Re: How to use registers for GPIO in ESP32

Postby filo_gr » Mon Sep 27, 2021 7:16 am

From this library I notice that I can use the MACRO PIN_FUNC_SELECT(PIN_NAME, FUNC) to set 1 pin's modality. To do this I need the array of values specified on page 173 of the ESP32-S2 Technical Reference Manual https://www.espressif.com/sites/default ... ual_en.pdf (I think there is a similar table also for the ESP32, but I don't see the right addresses)..
However I noticed I can set only one pin at a time.
Is PIN_FUNC_SELECT a good MACRO also for more pins at a time?

Maybe I'm complicating my life, but I'd like to know if there is a chance to make it works.
Filippo

Who is online

Users browsing this forum: Corand and 100 guests