Page 1 of 1

Strange capture of I2C on logic analyzer

Posted: Mon Jul 17, 2017 9:06 am
by avsej 
Hi, During debugging code interacting with DS3231 over I2C I noticed that my Saleae analyzer cannot decode I2C signals.

I've minimized example to the following (just send address) to make sure analyzer works:

Code: Select all

#include "freertos/FreeRTOS.h"

#include "esp_system.h"

#include "driver/gpio.h"
#include "driver/i2c.h"

#define DS3231_ADDR 0x68
#define ACK_CHECK_EN 0x1

#define SDA_PIN 18
#define SCL_PIN 19

void app_main(void)
{
    i2c_config_t conf;
    conf.mode = I2C_MODE_MASTER;
    conf.sda_io_num = SDA_PIN;
    conf.scl_io_num = SCL_PIN;
    conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
    conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
    conf.master.clk_speed = 100000;
    i2c_param_config(I2C_NUM_0, &conf);
    i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0);

    while (true) {
        esp_err_t rc;
        i2c_cmd_handle_t cmd = i2c_cmd_link_create();
        i2c_master_start(cmd);
        i2c_master_write_byte(cmd, (DS3231_ADDR << 1) | I2C_MASTER_WRITE, ACK_CHECK_EN);
        i2c_master_stop(cmd);
        rc = i2c_master_cmd_begin(I2C_NUM_0, cmd, 10 / portTICK_PERIOD_MS);
        i2c_cmd_link_delete(cmd);
        printf("address=0x%02x, rc=%d (0x%02x)\n", DS3231_ADDR, rc, rc);

        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
}
It output success like:

Code: Select all

address=0x68, rc=0 (0x00)
But analyzer does not show address sent
Selection_125.png
Selection_125.png (17.83 KiB) Viewed 12773 times
Wiring
20170717_115355.jpg
20170717_115355.jpg (159.3 KiB) Viewed 12773 times

Re: Strange capture of I2C on logic analyzer

Posted: Mon Jul 17, 2017 10:08 pm
by WiFive
One question is why are you using 5v supply instead of 3v3?

Re: Strange capture of I2C on logic analyzer

Posted: Mon Jul 17, 2017 10:34 pm
by rudi ;-)
like WiFive mentioned, use 3.3V as VCC cause ESP32 is 3.3V
here is the datasheet of DS3231,
side 2: the VCC is tolerant from 2.3V .. 5.5V, and typically 3.3V

FYI:
if you use an Arduino and DS3231 Breakout Board you can connect the DS3231 to the Arduino by 5V if the Arduino is a 5V,
otherside if the Arduino is 3.3V then you must use 3.3V for the VCC of DS3231 same like ESP32.

best wishes
rudi ;-)

Re: Strange capture of I2C on logic analyzer

Posted: Mon Jul 17, 2017 11:57 pm
by flashpackets
First, your signal integrity is poor. Your oscillograph shows cross coupling signal lines at the edges. This is a symptomatic of improperly terminated I2C lines. Do both the SCL and SDA lines have pullup resistor? If not try connecting a resistor from each line to +3V3. Normally you can use a resistor whose value is between 1.2 K to 4.7 K. The specific value is not critical, but it must of the two lines MUST have a pullup.

Re: Strange capture of I2C on logic analyzer

Posted: Tue Jul 18, 2017 7:46 am
by avsej 
With 3v3 situation is not better.
Selection_126.png
Selection_126.png (25.01 KiB) Viewed 12736 times
Regarding pullup, I thought that configuring it in ESP should be enough, no?

Code: Select all

    conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
    conf.scl_pullup_en = GPIO_PULLUP_ENABLE;

Re: Strange capture of I2C on logic analyzer

Posted: Tue Jul 18, 2017 8:01 am
by ESP_Sprite
For I2C, normally, the internal pull-ups are NOT enough. They are some tens of Ks, while I2C requires pull-ups more in the order of 4.7K'ish or lower.

Re: Strange capture of I2C on logic analyzer

Posted: Tue Jul 18, 2017 8:07 am
by WiFive
The board shown should have 4.7k pullups built in. There must be other signal coupling through breadboard, jig, etc...

Do you get same with your devkitc board?

Re: Strange capture of I2C on logic analyzer

Posted: Tue Jul 18, 2017 2:47 pm
by avsej 
Yes, same with devkitc, even when I connect it with jumper wires directly.
20170718_174505.jpg
20170718_174505.jpg (185.1 KiB) Viewed 12681 times

Re: Strange capture of I2C on logic analyzer

Posted: Tue Jul 18, 2017 3:52 pm
by avsej 
Okay. My problem has been solved :)

The test clips didn't give good connection. Once I connected without them, everything in capture became clear and without any glitches.

Thank you.