Strange capture of I2C on logic analyzer

avsej 
Posts: 4
Joined: Mon May 15, 2017 8:33 am

Strange capture of I2C on logic analyzer

Postby avsej  » Mon Jul 17, 2017 9:06 am

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 12735 times
Wiring
20170717_115355.jpg
20170717_115355.jpg (159.3 KiB) Viewed 12735 times

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Strange capture of I2C on logic analyzer

Postby WiFive » Mon Jul 17, 2017 10:08 pm

One question is why are you using 5v supply instead of 3v3?

User avatar
rudi ;-)
Posts: 1729
Joined: Fri Nov 13, 2015 3:25 pm

Re: Strange capture of I2C on logic analyzer

Postby rudi ;-) » Mon Jul 17, 2017 10:34 pm

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 ;-)
Attachments
DS3231.pdf
(361.01 KiB) Downloaded 751 times
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

flashpackets
Posts: 8
Joined: Tue Jun 27, 2017 10:39 pm

Re: Strange capture of I2C on logic analyzer

Postby flashpackets » Mon Jul 17, 2017 11:57 pm

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.

avsej 
Posts: 4
Joined: Mon May 15, 2017 8:33 am

Re: Strange capture of I2C on logic analyzer

Postby avsej  » Tue Jul 18, 2017 7:46 am

With 3v3 situation is not better.
Selection_126.png
Selection_126.png (25.01 KiB) Viewed 12698 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;

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

Re: Strange capture of I2C on logic analyzer

Postby ESP_Sprite » Tue Jul 18, 2017 8:01 am

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.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Strange capture of I2C on logic analyzer

Postby WiFive » Tue Jul 18, 2017 8:07 am

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?

avsej 
Posts: 4
Joined: Mon May 15, 2017 8:33 am

Re: Strange capture of I2C on logic analyzer

Postby avsej  » Tue Jul 18, 2017 2:47 pm

Yes, same with devkitc, even when I connect it with jumper wires directly.
20170718_174505.jpg
20170718_174505.jpg (185.1 KiB) Viewed 12643 times

avsej 
Posts: 4
Joined: Mon May 15, 2017 8:33 am

Re: Strange capture of I2C on logic analyzer

Postby avsej  » Tue Jul 18, 2017 3:52 pm

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.

Who is online

Users browsing this forum: No registered users and 383 guests