Skip to content

I2C Wire.write() always sets first bit after address to 1 #6255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
6 tasks done
TuxRobotics opened this issue Jul 4, 2019 · 2 comments
Closed
6 tasks done

I2C Wire.write() always sets first bit after address to 1 #6255

TuxRobotics opened this issue Jul 4, 2019 · 2 comments

Comments

@TuxRobotics
Copy link

TuxRobotics commented Jul 4, 2019

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: ESP-12e
  • Core Version: 6c5269a
  • Development Env: Arduino IDE 1.8.5
  • Operating System: Linux 4.15.0-45-generic

Settings in IDE

  • Module: Wemos D1 mini r2
  • Flash Mode: ?
  • Flash Size: 4MB, 2MB SPIFFS
  • lwip Variant: v2 Higher Bandwidth
  • Reset Method: ck
  • Flash Frequency: ?
  • CPU Frequency: 160MHz
  • Upload Using: SERIAL
  • Upload Speed: 115200

Problem Description

  1. The Wire library always sets the first bit of the first data byte after an address. The example sketch below is copied directly out of the examples, with the only modification being the addresses and data sent.

  2. (Possibly related?) After the STOP is sent, there is an extra negative pulse on the clock line.

The circuit:
The "Wemos D1 mini r2" is connected to an Adafruit CAP1188 board, and I have added pull up resistors. The board responds to reads with valid data, so I have verified the circuit is correct.
Pinout:
D1 => SCK
D2 => SDA

MCVE Sketch

#include <Wire.h>
#include <PolledTimeout.h>

#define SDA_PIN 4
#define SCL_PIN 5
const int16_t I2C_MASTER = 0x42;
const int16_t I2C_SLAVE = 0x56 >>1;

void setup() {
  Wire.begin(0x03);
  Wire.setClock(400000);  // use 400 kHz I2C
}

byte x = 0;

void loop() {
  using periodic = esp8266::polledTimeout::periodic;
  static periodic nextPing(1000);

  if (nextPing) {
    Wire.beginTransmission(I2C_SLAVE);
    Wire.write((uint8_t)0);        // sends one byte **The most significant bit is always 1**
    Wire.write((uint8_t)0);        // sends one byte (correct)
    Wire.endTransmission();    // stop transmitting

    x++;
  }
}

Debug Messages

Runs normally, but first bit of the data byte is always set:

image

Modifying the code to write any other value for the first data byte results in the first bit always being set. A

A few more examples:

  ...
    Wire.beginTransmission(I2C_SLAVE);
    Wire.write((uint8_t)0xAA);        
    Wire.write((uint8_t)0); 
    Wire.endTransmission();
 ...

Produces:
image

  ...
    Wire.beginTransmission(I2C_SLAVE);
    Wire.write((uint8_t)0x66);        
    Wire.write((uint8_t)0); 
    Wire.endTransmission();
 ...

Produces:
image

And here is a shot with the analog channels enabled to show the ramp rate looks good on each line:

image

Thanks!

@TuxRobotics TuxRobotics changed the title I2C I2C Wire.write() always sets first bit after address to 1 Jul 4, 2019
@TuxRobotics
Copy link
Author

Avoided the issue by using brzo i2c library instead.

@devyte
Copy link
Collaborator

devyte commented Jul 5, 2019

@TuxRobotics beware brzo, it is GPL, unlike our core. My understanding is that it's ok to use with our core only for personal use, and can't be distributed, because we rely on closed source prebuilt libs that aren't ours, and are therefore incompatible with any GPL.

About the issue, I'm rather surprised that nobody has seen it before. Is there any chance you could investigate our lib and try to find a fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants