Beetwise

ESP32 GPIO register calculator

An ESP32 GPIO register holds one bit for each pin, so bit n belongs to GPIO n.

GPIO_ENABLE_W1TS sets the bits you write and leaves the rest, so it needs no read.

GPIO_ENABLE_W1TC clears the bits you write in the same way.

Try an ESP32 GPIO register in the bit editor

GPIO 18 and GPIO 19 selected, which is 0xC0000. Edit the expression or select a bit to flip it.

31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
0x000C0000
hex · 32 bits
binary
0b00000000000011000000000000000000
value
786432

An ESP32 GPIO register step by step

Select GPIO 18 and GPIO 19:

  1. The mask for GPIO 18 is 1 << 18, which is 0x40000.
  2. The mask for GPIO 19 is 1 << 19, which is 0x80000.
  3. Apply OR to combine them: 0x40000 | 0x80000 gives 0xC0000.
  4. Write that value to GPIO_ENABLE_W1TS to drive both pins as outputs.

The write-one-to-set and write-one-to-clear registers

The write-one-to-set and write-one-to-clear registers
RegisterEffect of a 1Effect of a 0
GPIO_OUT_W1TSDrive the pin highLeave the pin
GPIO_OUT_W1TCDrive the pin lowLeave the pin
GPIO_ENABLE_W1TSEnable the output driverLeave the pin
GPIO_ENABLE_W1TCDisable the output driverLeave the pin
GPIO_INThe pin reads highThe pin reads low

Where an ESP32 GPIO register is used

A write-one-to-set register removes the read and the change, so an interrupt cannot break it.

A fast pin toggle in firmware writes W1TS and W1TC rather than the output register.

A pin above 31 lives in the second register of the pair, with the position less 32.

An ESP32 GPIO register: points to note

  • GPIO 32 and above use the registers with the suffix 1, at the position of the pin less 32.
  • A write of 0 to a W1TS register does nothing. It never clears a bit.
  • Several ESP32 pins are input only, and an output enable has no effect on them.
  • Several pins hold the boot mode, so a write at start-up changes how the chip starts.

The full bit editor

The full editor holds many values, evaluates expressions across them, and reads live values from a serial port.

Open this value in the full editor

Questions about an ESP32 GPIO register

Which bit belongs to GPIO 18?
Bit 18, because these registers hold one bit for each pin. The mask is 1 << 18.
Why use W1TS rather than the output register?
A write to W1TS sets the bits you name and leaves the rest, so it needs no read and no lock.
How do I reach GPIO 33?
Use the register with the suffix 1 and the position 1, because 33 less 32 gives 1.