Does the Esp32 support hardware based I2C or software bit-bang based I2C ?

ESP_Sprite
Posts: 9833
Joined: Thu Nov 26, 2015 4:08 am

Re: Does the Esp32 support hardware based I2C or software bit-bang based I2C ?

Postby ESP_Sprite » Wed Nov 23, 2016 3:10 am

As stated a whole bunch of times before: You can select the pin using the GPIO mux. Please, please, read up on the GPIO mux and how it works. The code you quote does not indicate any specific GPIO use, I2CEXT0_SDA_OUT_IDX etc are the signals you can route in the GPIO mux. Check the last example of include/driver/gpio.h for code to connect I2C0 to GPIO 21 and 22.

Ritesh
Posts: 1385
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: Does the Esp32 support hardware based I2C or software bit-bang based I2C ?

Postby Ritesh » Wed Nov 23, 2016 6:02 am

Hi,

Thanks for quick reply.

Just for clarification that please let me exact SDA and SCL GPIO Numbers as per GPIO Mux matrix if planning to use I2C0 or I2C1 for ESP32 as per below code snippet.

Code: Select all

if(i2c_num == 0) {
        SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG,DPORT_I2C_EXT0_CLK_EN);
        CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG,DPORT_I2C_EXT0_RST);
    } else {
        SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG,DPORT_I2C_EXT1_CLK_EN);
        CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG,DPORT_I2C_EXT1_RST);
    }
Let me know if you need any more informations regarding requirement from my side.
Regards,
Ritesh Prajapati

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Does the Esp32 support hardware based I2C or software bit-bang based I2C ?

Postby kolban » Wed Nov 23, 2016 6:27 am

The ESP32 is built on layers. At the lowest level there is hardware which exposes its controls at specific addresses in the address space. We set the bits there and the magic of the silicon logic in the processor does its stuff. This is all documented in the ESP32 Technical Reference manual that you can find here:

http://espressif.com/sites/default/file ... ual_en.pdf

Page 66 describes onwards this detail.

However ... and this is opinion ... very, very few project or products will actually need to code to this level. It would be like in Unix saying "ignore open, close, read and write ... and instead, twiddle the bits by using /dev/sda0". Instead, some folks (that I call the heroes) have studied these specifications (or written them themselves) and have encapsulated them in higher level libraries that are dramatically easier to consume. In the ESP-IDF, these are termed "drivers". As of the date of this posting, the driver for I2C hasn't yet been released ... but all indications are that it will be here by December 1st. Now imagine that the driver was available ... with all its documentation and high level functions ... would you use that or do you still see yourself dropping down to the lowest architectural levels?

If the answer is that you would use the drivers, then maybe you can work on other aspects of your project until the drivers become available. If you absolutely can't wait, then there is one more consideration ... and that is to use the drivers that are supplied with the Arduino environment for ESP32. Specifically, see

https://github.com/espressif/arduino-es ... -hal-i2c.c

This is a fully functioning driver that is available today that can be linked in with your ESP-IDF applications. It is likely (but that is a guess on my part) that this API will be distinct from the driver shipped with ESP-IDF 1.0 and if you use the Arduino driver ... you will likely want to change when ESP-IDF 1.0 ships (in about 8 days).

Notice that the API for the Arduino driver includes two API calls called:

i2cAttachSCL() and i2cAttachSDA()

each of which take the pin numbers you wish to use for the respective function.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Ritesh
Posts: 1385
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: Does the Esp32 support hardware based I2C or software bit-bang based I2C ?

Postby Ritesh » Wed Dec 14, 2016 4:24 am

ESP_igrr wrote:Probably not *all* the features, but most of them.

Regarding I2C: it is mentioned in the technical reference manual that I2C peripheral is connected to the GPIO mux. So you can route sda and scl pins to any GPIO (which can be output and which is in the correct power domain). Please check the technical reference manual...

For code samples, don't forget to check arduino-esp32 project, in particular various "hal" files. I2C implantation is among them.
Hi,

I have one quick question for you that I have just gone through GPIO MUX with basic overview not in details and i just want to know that is it ok if I select any free GPIO for I2C0 SDA and SCL clock line if you have any idea for I2C drivers which will be released by Espressif Systems soon?

Because, We are in product development phase in which we want to connect one sensor on I2C interface and we need to complete PCB Schematic within 2 days. That's why i want to know regarding I2C GPIO selection if you have any idea for that

Please let me know your input or feedback ASAP
Regards,
Ritesh Prajapati

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: Does the Esp32 support hardware based I2C or software bit-bang based I2C ?

Postby ESP_igrr » Thu Dec 15, 2016 2:38 am

Any output-capable GPIOs will work, as long as they are in the same power domain as the chip you are going to communicate with, and are not used for other functions in your design (i.e. flash, UART), and are compatible w.r.t. state at reset.
I suggest you to check "ESP32 pin list" document, in particular the "IO MUX" table, and "strapping pins" table. Also check power domain column: some pins are in the SDIO power domain, which may be 1.8V or 3.3V depending on what you need to power the flash chip.

Who is online

Users browsing this forum: Baidu [Spider], timokett and 133 guests