I'm working on a project where I have to communicate to several devices over I2C using a Genuino 101. Now I'm trying to get data off the bus but wire.available() stays at 0, even though my trace clearly shows there's data being sent.

 i2c trace

with the following timings

enter image description here


Because the wire is never available my readbuf will always be empty.

Rdbuf[0] is: 0 Hex is: 0
Rdbuf[1] is: 0 Hex is: 0

I'm using the following code to read from the I2C bus.

void i2cRead(unsigned char device, unsigned char memory, int len, unsigned char * rdBuf) {
  ushort memstart = memory;
  bool available = true;;
  while (len > 0 && available) {
    available = false;
    ushort blockSize;
    /*If the number of bytes is smaller than the block size, read that size*/
    (len < RD_BLCK_SIZE) ? blockSize = len : blockSize = RD_BLCK_SIZE;
    //send i2c START command
    //Write memory address
    //send i2c STOP command
    Wire.requestFrom(static_cast<int>(device), blockSize,true);
    //Request blockSize bytes from the device
    /* for every byte in the response add that byte to the read buffer */
    while (Wire.available() && (len != 0)) {
      available = true;
      rdBuf[memory - memstart] = Wire.read();

I'm not quite sure what I'm doing wrong, any help would be much appreciated.


Below is an image of the current (minimal) setup. On the left there's the board with the ADC and multiplexer visible.

Arduino setup

The third set of wires goes to my protocol analyzer.

  • It seems that a delay(1) between Wire.endTransmission and Wire.requestFrom is necessary for ... reasons. – user31481 Oct 26 '17 at 18:37

You want to get the resulting code working, but you should do small minimal tests.

Start with the i2c scanner.
Connect only one sensor, and if it is detected, add more sensors.

How long are the wires, and what is the value of the pullup resistors ?
Perhaps you have too many modules with sensors, and the total pullup value it too low. The I2C bus is specified for maximum 3mA pull down current.

Do you have a more common 3.3V Arduino board ? For example the Arduino Due or the Arduino Zero ?

  • hey jot, i have the code working on a different sensor, i2c scanner gives me all the sensors, and i can sucessfully read these sensors. the only difference here is that i have this sensor connected via a logic-level converter, converting the 3.3v signals into 5v signals. i have an arduino uno i could test with, but this is part of a bigger project, in which we're using the bluetooth component of the 101. the wires are all 30cm DuPont wires, they're pulled up to 5v with 10kOhm resistors – Ron Jun 27 '17 at 15:01
  • The I2C bus is 3.3V, with a level shifter is for a 5V sensor ? Did you connect the high side (sometimes called HV) to the sensor side, and did you apply the 3.3V and the 5V to the level shifter ? Use seperate wires, not a flat ribbon cable. When SDA and SCL are next to each other in a flat ribbon cable, then they cause crosstalk. The i2c scanner detect a sensor by a ACK to its I2C address. Then you should be able to get that same ACK in a small test sketch. Perhaps the sensor has to be woken to be able to return data ? Is that a normal sensor, or a microcontroller with clock puls stretching ? – Jot Jun 27 '17 at 15:27
  • The sensor i'm currently trying to reach is a 10-bit adc, so far it's always just worked when we try to get data from it, in the packet log you can see that it responds with valid data. i'm currently using a adafruit level shifter on a breadboard. 3.3v peripherals and the 101 on one side, and my 5v peripherals(Io expander/adc) on the other. currently the sda and scl are next to eachother on the breadboard, ill try with a few pins in between to see if crosstalk is the issue, a raspberry pi connected on the 5v side can talk to all the periperals, so i believe the circuit ought to be fine – Ron Jun 27 '17 at 15:35
  • A Raspberry Pi is 3.3V and it must be connected to the 3.3V side of the I2C bus. And you did apply 3.3V and 5V to the level shifter ? You really should test the problem with the absolute minimum. Remove everything that is not needed from the I2C bus and make a very small test sketch. Perhaps the timing of the Arduino 101 Wire library is in conflict the with sensor. You could, for example, add a delay of 1ms after Wire.endTransmission. – Jot Jun 27 '17 at 18:46
  • thats what i find odd, the raspberry pi works on both sides, but the genuino works on neither. i'll do a test with the bare minimum attached tomorrow and i'll see what's going wrong. thanks for your ideas so far – Ron Jun 27 '17 at 22:48

Since this has been reopened i figured i'd post what the problem was, in the end and what i did to fix it.

it turns out, that even though the documentation of the Curie tells us to apply a level shifter for i2c communications, this level shifter is already in-place on the genuino 101.

skimming over the documentation of the 101, i had overlooked this. The fix, in the end was removing the level shifter.

Your Answer

