I2C startup issue

Paul L

Member
I’m having communication errors with the first I transmission. If I immediately send the same message again it is fine.

I noticed that the signal isn’t pulled down properly at first. Here is a screenshot:

IMG_2901.jpeg


I’ve checked for grounding issues, and even added additional grounding with no change.

I’ve tried DSE pad settings of 1 and 2,

I’m using the teensy4_i2c library.

Any ideas?
 
I'm using 2K pull up resistors.

This simplified code exhibits the same issue, though I'm not sure it's the code (though I've been wrong before):


Code:
#include <Arduino.h>
#include <i2c_device.h>


enum class Switch_Digital : uint16_t {
  Address = 0x0023,
  SWITCH_BATT_ENABLE_0 = 0x0001,
  SWITCH_GND_ENABLE_0 = 0x0002,
  SWITCH_BATT_ENABLE_1 = 0x0004,
  SWITCH_GND_ENABLE_1 = 0x0008,
  SWITCH_BATT_ENABLE_2 = 0x0800,
  SWITCH_GND_ENABLE_2 = 0x0400,
  SWITCH_BATT_ENABLE_3 = 0x0200,
  SWITCH_GND_ENABLE_3 = 0x0100
};
void rawDiagRead(const char* DevName, I2CDevice dev)
{
 
    uint8_t portval;
  dev.read(0x06, &portval, true);
Serial.printf("%s Port 0x06 = 0x%0.2X\n",DevName,portval);
dev.read(0x07, &portval, true);
Serial.printf("%s Port 0x07 = 0x%0.2X\n",DevName,portval);
  dev.read(0x02, &portval, true);
Serial.printf("%s Port 0x02 = 0x%0.2X\n",DevName,portval);
  dev.read(0x03, &portval, true);
Serial.printf("%s Port 0x03 = 0x%0.2X\n",DevName,portval);
  dev.read(0x00, &portval, true);
Serial.printf("%s Port 0x00 = 0x%0.2X\n",DevName,portval);
  dev.read(0x01, &portval, true);
Serial.printf("%s Port 0x01 = 0x%0.2X\n",DevName,portval);
}
I2CMaster& master = Master;
I2CDevice Switch_Digital_Ex = I2CDevice(master, (uint8_t)Switch_Digital::Address, _BIG_ENDIAN);
void setup() {

master.set_internal_pullups(InternalPullup::disabled);
master.set_pad_control_configuration(IOMUXC_PAD_ODE | IOMUXC_PAD_DSE(2) | IOMUXC_PAD_SPEED(1) | IOMUXC_PAD_HYS);
master.begin(100 * 1000U);

}
void loop() {

while(true)
{
rawDiagRead("Switch -----", Switch_Digital_Ex);
delay(1000);
}


}
 
Last edited:
Sometimes the Teensy is SO FAST that it starts communicating with external ICs before they are ready.
Perhaps put a delay of a second or so in SetUp.

By the way it makes your code much easier to read if you enclose it between CODE tags using the </> button.
You see it makes a world of difference!
Code:
#include <Arduino.h>
#include <i2c_device.h>


enum class Switch_Digital : uint16_t {
    Address = 0x0023,
    SWITCH_BATT_ENABLE_0 = 0x0001,
    SWITCH_GND_ENABLE_0 = 0x0002,
    SWITCH_BATT_ENABLE_1 = 0x0004,
    SWITCH_GND_ENABLE_1 = 0x0008,
    SWITCH_BATT_ENABLE_2 = 0x0800,
    SWITCH_GND_ENABLE_2 = 0x0400,
    SWITCH_BATT_ENABLE_3 = 0x0200,
    SWITCH_GND_ENABLE_3 = 0x0100
};
void rawDiagRead(const char* DevName, I2CDevice dev)
{

    uint8_t portval;
    dev.read(0x06, &portval, true);
    Serial.printf("%s Port 0x06 = 0x%0.2X\n", DevName, portval);
    dev.read(0x07, &portval, true);
    Serial.printf("%s Port 0x07 = 0x%0.2X\n", DevName, portval);
    dev.read(0x02, &portval, true);
    Serial.printf("%s Port 0x02 = 0x%0.2X\n", DevName, portval);
    dev.read(0x03, &portval, true);
    Serial.printf("%s Port 0x03 = 0x%0.2X\n", DevName, portval);
    dev.read(0x00, &portval, true);
    Serial.printf("%s Port 0x00 = 0x%0.2X\n", DevName, portval);
    dev.read(0x01, &portval, true);
    Serial.printf("%s Port 0x01 = 0x%0.2X\n", DevName, portval);
}
I2CMaster& master = Master;
I2CDevice Switch_Digital_Ex = I2CDevice(master, (uint8_t)Switch_Digital::Address, _BIG_ENDIAN);
void setup() {

    master.set_internal_pullups(InternalPullup::disabled);
    master.set_pad_control_configuration(IOMUXC_PAD_ODE | IOMUXC_PAD_DSE(2) | IOMUXC_PAD_SPEED(1) | IOMUXC_PAD_HYS);
    master.begin(100 * 1000U);

}
void loop() {

    while (true)
    {
        rawDiagRead("Switch -----", Switch_Digital_Ex);
        delay(1000);
    }


}
 
maybe “start up” wasn’t the right word.

The issue happens at the start of every one second loop.

Another thing I noticed is that SDA looks fine, only SCL has the ramping issue, as shown below:

IMG_2903.jpeg
 
I connected a thicker ground wire to the ground between 3.3v and 5V, then to the first ground pin on the other side, then to the another ground, one at a time with no success.

Installed a new Teensy 4.1, with the same result.

Measure the resistance between SCL and its pull-up and then SDA to its pull-up; both are less than 1 ohm.

I removed an I2C accelerator chip from my circuit - no change.
 
What I2C device are you actually trying to communicate to?
Do you happen to have a circuit schematic? And perhaps photo's of your setup?

Paul
 
Problem resolved.

I decided to shotgun the problem and just start removing components. The issue was caused by one of the daughter boards in my system.

So while I don’t know the root cause yet, I plan to leave the offending board unplugged and work on higher priority parts of the system.

Thanks for the suggestions.
 
Back
Top