I'm starting to develop with the ESP32-S2, and I have many doubts about how to control the GPIO directly through the registers (I'm used to working like this with atmega328p chips).
My goal is to set the GPIOS as inputs and outputs, read the state of the pin and change its logic state through registers, I don't want to use the functions in C, gpio_set_direction, gpio_set_level and gpio_get_level.
Atmega328p used registers like DDRD, PORTD and PIND. I expected to find equivalent registers in the ESP32-S2 datasheet or a similar path, but I can't find the necessary information for that, so below I'm leaving my specific questions.
1° - How do I define by the registers that the GPIO38 will be an input or output?
2° - How do I set by registers that the GPIO38 will go to the high or low logical state?
Configure GPIO by Registers - ESP32-S2
-
- Posts: 9729
- Joined: Thu Nov 26, 2015 4:08 am
Re: Configure GPIO by Registers - ESP32-S2
You probably want to look at the TRM, chapter 5.
To setup direction etc, I'd advise you to use the driver, as those calls are generally not time sensitive and can be a bit more complicated than an AVR wrt detaching from peripherals. For level setting, you can use the w1ts and w1tc registers to poke the IO directly. E.g. to make pin 38 high:
To setup direction etc, I'd advise you to use the driver, as those calls are generally not time sensitive and can be a bit more complicated than an AVR wrt detaching from peripherals. For level setting, you can use the w1ts and w1tc registers to poke the IO directly. E.g. to make pin 38 high:
Code: Select all
GPIO.out1_w1ts = ((uint32_t)1 << (38-32));
-
- Posts: 13
- Joined: Tue Nov 01, 2022 8:32 pm
Re: Configure GPIO by Registers - ESP32-S2
Thanks for your reply friend!ESP_Sprite wrote: ↑Tue Nov 01, 2022 11:52 pmYou probably want to look at the TRM, chapter 5.
To setup direction etc, I'd advise you to use the driver, as those calls are generally not time sensitive and can be a bit more complicated than an AVR wrt detaching from peripherals. For level setting, you can use the w1ts and w1tc registers to poke the IO directly. E.g. to make pin 38 high:Code: Select all
GPIO.out1_w1ts = ((uint32_t)1 << (38-32));
I was just reading the technical references in chapter 5 and came across "GPIO_PINn_REG". But for those who are coming from Atmega, using this register seemed really complicated, mainly because I didn't find any code example configuring this register.
I'm looking to use these register functions, because I'm migrating a code from an Atmega328p that simulates an i2c slave to a dsp device, the Atmega code used register manipulation to make the LOW and HIGH of the SDA (even this code only works using this technique for the SDA). I thought that to migrate this code to esp32-s2 I should just use the C functions to transcribe this code, but it doesn't work. I have the same code that was transcribed for esp8266, using the register technique and it worked perfectly.
Do you have any code example to set gpio as input or output by the register?
-
- Posts: 9729
- Joined: Thu Nov 26, 2015 4:08 am
Re: Configure GPIO by Registers - ESP32-S2
Probably easier to set the pin to GPIO_MODE_INPUT_OUTPUT_OD using the driver, that way you don't have to switch input/output at all.
Who is online
Users browsing this forum: No registered users and 97 guests