Thursday, March 31, 2016

Understanding ESP8266 IO Pins

Original Content Source:

This is tricky and confusing. This biggest problem is your point of view. You can be considering the esp8266 chip itself, a module like the ESP-12 or ESP-12E, or the pins on the edge of a product like a NodeMCU board. On top of that, many pins can be mapped to multiple functions. And for yet more excitement, different software has given things different names. We have the GPIO numbers in the bare hardware. NodeMCU has assigned pin numbers (and made a significant change in them at one point in time). Arduino has yet another name/number scheme of its own. So ... you have been warned.

I am using mostly NodeMCU dev boards (of a recent vintage that adds some signals), but sometimes deal with bare ESP-12 modules, and I throw in the Sparkfun "Thing" dev board for extra variety.
The above GPIO pin allocation link is especially helpful. Along with this table:

This makes it clear why GPIO 6-11 are in general unavailable, they are connected to the flash chip! If the flash is connected in QIO mode (4 data lines), all 6 are unavailable. If the flash is connected in DIO mode (2 data lines), GPIO 9 and 10 can be used.
The 4 pins with "MT" in their names are part of an HSPI interface (Hardware SPI)

The bottom line

Here is part of a table from some C code I wrote. It is useful to me in showing the MUX names and NodeMCU aliases. In addition it shows what "extra stuff" is hooked up to the pins. Note that some pins cannot be used as they are connected to the flash and uart.
This is in "GPIO order".
    PERIPHS_IO_MUX_GPIO0_U,     /* 0 - D3 */
    PERIPHS_IO_MUX_U0TXD_U,     /* 1 - uart */
    PERIPHS_IO_MUX_GPIO2_U,     /* 2 - D4 - little LED on ESP-12E module */
    PERIPHS_IO_MUX_U0RXD_U,     /* 3 - uart */
    PERIPHS_IO_MUX_GPIO4_U,     /* 4 - D2 */
    PERIPHS_IO_MUX_GPIO5_U,     /* 5 - D1 */
    Z,     /* 6 - flash chip SPI */
    Z,     /* 7 - flash chip SPI */
    Z,     /* 8 - flash chip SPI */
    PERIPHS_IO_MUX_SD_DATA2_U,  /* 9  - D11 (SD2) (flash chip if QIO) */
    PERIPHS_IO_MUX_SD_DATA3_U,  /* 10 - D12 (SD3) (flash chip if QIO) */
    Z,     /* 11 - flash chip SPI */
    PERIPHS_IO_MUX_MTDI_U,      /* 12 - D6 */
    PERIPHS_IO_MUX_MTCK_U,      /* 13 - D7 */
    PERIPHS_IO_MUX_MTMS_U,      /* 14 - D5 */
    PERIPHS_IO_MUX_MTDO_U       /* 15 - D8 */
    ---    /* 16 - D0 - little LED on NodeMCU devkit board */

NodeMCU: pins and signals

A peek at the schematic shows that it is possible to connect 5 volt power to the Vin pin (it has the same connection as the USB 5 volt.
Below is a diagram of an ESP-12e module (which is what is mounted on the NodeMCU devel boards that I have). This is it, viewed from the top.

The silkscreen on my ESP-12e modules shows some differences:
REST is actually RST (reset)
CH_PD is labeled EN on my unit
TXD is labeled TXD0 on my unit
RXD is labeled RXD0 on my unit
Labeling RXD0 and TXD0 suggest there may be another uart; maybe so.
On many diagrams (and the silkscreen on many units) GPIO-4 and GPIO-5 are swapped. The above matches my silkscreen and experiment (see below) indicates this is correct.
The extra 6 pins on the bottom of the ESP-12e module are there and they are hooked up! They go to pins on the NodeMCU board that were previously marked "reserved", which is a nice bonus.

No comments:

Post a Comment