Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By drmpf
#24442 The reference docs suggest using I2C with GPIO0 and GPIO2 on the ES8266-01.
Are these pins true open Drain, if not then I2C use is limited.
User avatar
By martinayotte
#24458 This is really depends on the code you're using in your application.
For example, if you are using the i2c_master given in SDK example, the GPIO are initialize accordingly as describe in the init function :

Code: Select all/******************************************************************************
 * FunctionName : i2c_master_gpio_init
 * Description  : config SDA and SCL gpio to open-drain output mode,
 *                mux and gpio num defined in i2c_master.h
 * Parameters   : NONE
 * Returns      : NONE
*******************************************************************************/

In the Arduino IDE core, there is similar initialization :
Code: Select all#define SDA_LOW()   (GPES = (1 << twi_sda)) //Enable SDA (becomes output and since GPO is 0 for the pin, it will pull the line low)
#define SDA_HIGH()  (GPEC = (1 << twi_sda)) //Disable SDA (becomes input and since it has pullup it will go high)
User avatar
By drmpf
#24469 great thanks for that,
Here also is a reply from Ivan

"Due to lack of documentation regarding pin circuits from Espressif it’s really hard to say whats going on inside the chip. However I did some tests and it looks like ESP8266 pins do have an open-drain output mode. In Arduino you can enable it by calling pinMode(pin, OUTPUT_OPEN_DRAIN); on the pin of your choice. This mode was used in the original version of our software I2C code.
However we had issues from people forgetting about external pull up resistors, so the code has changed a bit recently. Instead of changing pin output register when banging the bits, we now change pin mode register. The pin is switched between INPUT_PULLUP and OUTPUT modes, which makes it either a weak pull up or a strong pull down (output register has 0 written into it in advance).

In the special case of GPIO0 and GPIO2 you will still need external pull up resistors because these pins are used for bootstrapping. If either of these pins is low at boot, the sketch will not start.
So if you are constrained to an ESP-01, you have an option of using any combination of GPIO0, GPIO1, GPIO2, GPIO3, with a caveat that two of these pins are used for UART by default, and two other are used for bootstrapping. Personally I have used GPIO0 and GPIO2 for I2C on ESP-01 quite successfully."
User avatar
By martinayotte
#24474
igrr wrote:Personally I have used GPIO0 and GPIO2 for I2C on ESP-01 quite successfully."

Yes, that's what I used since several months with external pullups for the Boot mode along with a push button for the UpLoads.