Connecting two ESP32s via I2C

fodgeri
Posts: 11
Joined: Mon Apr 08, 2019 1:36 pm

Connecting two ESP32s via I2C

Postby fodgeri » Mon Apr 29, 2019 7:58 pm

Hello,

Is there any solution to connect two or more esp32s via cable on i2c protocol? Unfortunately, the UART connection did not work for us because it was really unreliable e.g: when we restarted one esp device it caused a restart on the second device too.

Are the any other solutions (except I mentioned above) to connect two esp32s via cable?

Thank you for your help,
Gary

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

Re: Connecting two ESP32s via I2C

Postby ESP_Sprite » Tue Apr 30, 2019 1:36 am

Yes, you can set one as an I2C master and another one as an I2C slave. However, I'd look into what's going on with the UART restarting your 2nd ESP32 first... there's no intrinsic hardware-based way that can happen, so there's either a fault in your software or in your external hardware, and there's a good chance these carry over to an I2C-based solution as well.

fodgeri
Posts: 11
Joined: Mon Apr 08, 2019 1:36 pm

Re: Connecting two ESP32s via I2C

Postby fodgeri » Tue Apr 30, 2019 6:35 am

Thank you for your quick reply! We did everything like in examples. Connected the rx/tx pins on the devices, initialize the UART1 ports, and we monitored the UART0.

This is the initialization:

Code: Select all

void init() {
    const uart_config_t uart_config = {
        .baud_rate = 115200,
        .data_bits = UART_DATA_8_BITS,
        .parity = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE
    };
    uart_param_config(UART_NUM_1, &uart_config);
    uart_set_pin(UART_NUM_1, TXD_PIN, RXD_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
    // We won't use a buffer for sending data.
    uart_driver_install(UART_NUM_1, RX_BUF_SIZE * 2, 0, 0, NULL, 0);
}
The connection working but it is really unreliable. Sometimes the devices randomly restarting, and as I mentioned earlier it does not matter what code is in the second device (we tried with getting started wifi example) if it restarts, the first device restarts too. It transmits something on the TX pin that triggers the restart on the first device.

Gary

Who is online

Users browsing this forum: No registered users and 82 guests