-->
Page 1 of 1

ESP8266 GPIO registers confusion

PostPosted: Sat May 07, 2022 5:26 pm
by Erling
AVR have DDRx for pin configure (direction), PORTx for setting output and PINx for reading input.
ARM (at least STM32) have GPIOx_CRL (and GPIOx_CRH, or GPIOx_MODER) for pin configure (direction), GPIOx_ODR (and alternatively GPIOx_BSRR and GPIOx_BRR for atomic operations) for setting output and GPIOx_IDR for reading input.
PIC (at least PIC16F877A) have TRISx for pin configure (direction) and PORTx for both setting output and reading input.

What stands for those functions in ESP8266? I'm reading technical reference I had downloaded from Espressif website and I can't get a proper grasp at that.

Configure pin (direction)
Section 2.2.2 lists GPIO_ENABLE output register (and its two companions GPIO_ENABLE_W1TS and GPIO_ENABLE_W1TC for atomic operations) which enables the output. It doesn't state explicitly that disabling the output configures a pin as an input. Does doing so configure a pin as an input?

Configure pin (function)
Section 2.2.1 states that it's not enough to just choose a GPIOx and set its direction, instead I have to define its function number first. PERIPHS_IO_MUX_x register is mentioned in regard to this role. But first, this register isn't listed in Appendix 1 (GPIO registers), and secondly, where are the function numbers listed?

Setting output
Okay, this one looks clear. Section 2.2.2 lists GPIO_OUT output register (and its two companions GPIO_OUT_W1TS and GPIO_OUT_W1TC for atomic operations).

Reading input
Section 2.2.3 mentions GPIO input register, but doesn't name it. Is GPIO_IN_DATA from Appendix 1 impied? And why make input read register writable (section 2.2.3 mentions it as r / w)?

Re: ESP8266 GPIO registers confusion

PostPosted: Tue May 24, 2022 9:47 am
by eriksl
Just forget the way the AVR C compilers present them. DDR(x) and PORT(x) are macro's that in the end simply refer to (data) memory addresses. I don't think many CPU's have had specific I/O instructions since the Z80.

On the ESP8266 it works exacly the same, just not obscured by such macro's (but by other macro's, that's another story).

To make a gpio "read" or "write" set a bit in the designated register, to write a gpio, write a bit in the other designated register and to read a gpio, read the bit there. It's all very simple.