Direct IO Port Manipulation

User avatar
Fuzzyzilla
Posts: 22
Joined: Sun Apr 23, 2017 3:19 am

Direct IO Port Manipulation

Postby Fuzzyzilla » Wed Apr 26, 2017 1:25 am

Hello!
I'm new to the ESP32 (Haven't even gotten one yet, to be honest) and I was wondering about manipulating the digital ports.
The ESP32 Technical Reference, It talks about this topic.

However, It seems like each GPIO has it's own register. Is this correct?
IO_MUX_GPIO2_REG | Configuration register for pad GPIO2 | 0x3FF49040 | R/W
IO_MUX_GPIO0_REG | Configuration register for pad GPIO0 | 0x3FF49044 | R/W
etc...
The reason I want to do this is:
-Speed -- I'm using 8080 Parallel communications, so changing 10 pins in one cycle would be nice!
-Size -- Not a big deal, but a consideration nonetheless!

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

Re: Direct IO Port Manipulation

Postby ESP_Sprite » Wed Apr 26, 2017 2:05 am

The GPIOs have a configuration register each, but the value is set using 4 32-bit registers, namely GPIO_OUT_W1TS/W1TC and GPIO_OUT1_W1TS/W1TC. You use the GPIO_OUT_* register to modify GPIO0-31, you use GPIO_OUT1_* to modify GPIO32 and higher. When you write an 1 in a bit in a W1TC register, you'll make the GPIOs associated with these bits low, when you write an 1 in a bit position in a W1TS register, you make the corresponding GPIO high. (W1TC = Write 1 To Clear, W1TS = Write 1 To Set.) For both registers, any GPIO written 0 does not change.

User avatar
Fuzzyzilla
Posts: 22
Joined: Sun Apr 23, 2017 3:19 am

Re: Direct IO Port Manipulation

Postby Fuzzyzilla » Wed Apr 26, 2017 2:24 am

Thank you!

So I can either directly change them with GPIO_OUT0_REG or use W1TS and W1TC to set/reset?
Cool! Thank you :)

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

Re: Direct IO Port Manipulation

Postby ESP_Sprite » Wed Apr 26, 2017 7:42 am

Ah yes, using OUT0 is also an option, but it's usually not recommended because it's not atomic.

miljume
Posts: 5
Joined: Thu Dec 14, 2017 8:39 am

Re: Direct IO Port Manipulation

Postby miljume » Thu Dec 14, 2017 8:48 am

Hello!

Can someone tell me how to do this programatically?

I am using arduino and trying to assign a binary value to GPIO_OUT_W1TS to set 4 pins at the same time but I cant manage without errors

If I do this with ATMEGA328 in arduino I will just use

Code: Select all

PORTD = B10101000; 
to manipulate pins

How do I do this with ESP32?

ESPpeter
Posts: 4
Joined: Mon Dec 04, 2017 12:49 pm

Re: Direct IO Port Manipulation

Postby ESPpeter » Sat Dec 23, 2017 1:34 pm

"How do I do this with ESP32?"

const uint8_t ledPin = 2 ;
pinMode(ledPin,OUTPUT) ;
digitalWrite(ledPin,1); // (*((volatile uint32_t *) (0x3ff44000 + 0x8 ))) ^= 1 << 2 ;
digitalWrite(ledPin,0); // (*((volatile uint32_t *) (0x3ff44000 + 0xC))) ^= 1 << 2 ;

User avatar
urbanze
Posts: 301
Joined: Sat Jun 10, 2017 9:55 pm
Location: Brazil

Re: Direct IO Port Manipulation

Postby urbanze » Sun Dec 24, 2017 5:06 pm

You can use REG_WRITE macro, defined in soc.h. In this site, show how to blink an LED with registers like GPIO_OUT_W1TS_REG.

Note: Translate from (Portuguese (BR)) to English or any.
https://portal.vidadesilicio.com.br/man ... res-esp32/

jbowser
Posts: 1
Joined: Tue Feb 06, 2018 11:29 am

Re: Direct IO Port Manipulation

Postby jbowser » Tue Feb 06, 2018 11:56 am

Sorry for hijacking this thread, but I think my question is in line with the title.
I'm also interested in direct port manipulation and mostly in reading multiple pin states at the same time (for reading a rotary encoder).

The following code is used to store the states of pin 2 and 3.

Code: Select all

reading = PIND & 0xC;
How would I change this to read for example pin 15 and 16 on an esp32?
In the TRM I found the following:
4.2.3 Simple GPIO Input
The GPIO_IN_REG/GPIO_IN1_REG register holds the input values of each GPIO pad.
The input value of any GPIO pin can be read at any time without configuring the GPIO Matrix for a particular
peripheral signal. However, it is necessary to configure the xx_FUN_IE register for pad X, as shown in Section
4.2.2.
Where I'm guessing the 15th and 16th bit int GPIO_IN_REG would contain the states of those pins, but what do I have to do with "xx_FUN_IE"?

Who is online

Users browsing this forum: No registered users and 108 guests