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:
- The mask for GPIO 18 is 1 << 18, which is 0x40000.
- The mask for GPIO 19 is 1 << 19, which is 0x80000.
- Apply OR to combine them: 0x40000 | 0x80000 gives 0xC0000.
- Write that value to GPIO_ENABLE_W1TS to drive both pins as outputs.
The write-one-to-set and write-one-to-clear registers
| Register | Effect of a 1 | Effect of a 0 |
|---|---|---|
| GPIO_OUT_W1TS | Drive the pin high | Leave the pin |
| GPIO_OUT_W1TC | Drive the pin low | Leave the pin |
| GPIO_ENABLE_W1TS | Enable the output driver | Leave the pin |
| GPIO_ENABLE_W1TC | Disable the output driver | Leave the pin |
| GPIO_IN | The pin reads high | The 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 editorQuestions 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.