Does I2C with "repeated start" bits actually work ?

I have three new I2C modules, one with a Freescale MPL3115A2 pressure sensor and two with a Freescale MMA8451Q accelerometer.

The I2C_Scanner sketch detects an address response from each of them, at the expected address, but apart from that I cannot get any I2C communication to actually work. These Freescale devices apparently rely on an I2C scheme which is slightly different to (most) other I2C devices. The difference involves sending a "repeated start" bit between setting the register address to read from, and requesting the data.

I have tried using "Wire", I have tried using "I2C", I have tried using "I2CDEV", and none of them will work. I have tried using all three of those libraries with other I2C sensor modules, and they work just fine. I have also tried using 2.7k and 3.3k and 4.7k pullup resistors.

Has anyone actually succeeded in getting any of these modules using Freescale's version of I2C to actually work ? Are there any examples of sketches that work ?

Here is the code I am using. I have tried every combination of “true” and “false” for the final parameter of the call to endTransmission() and requestFrom(), the outcome is the same every time, no response.

#include <Arduino.h>
#include <Wire.h>

#include “MySens_MMA8451Q.h”

MMA8451Q acc ; // accelerometer device

void setup()
{
Serial.begin(9600);
Serial.println(“Hello World !”);

Wire.beginTransmission( (uint8_t) MMA8451Q_Address );
Wire.write( (uint8_t) MMA845x_WHO_AM_I );
Wire.endTransmission( false );

Wire.requestFrom( (uint8_t) MMA8451Q_Address, (uint8_t) 1 , (uint8_t) true );
delay(1);
if ( Wire.available() >= 1 )
{
int result = Wire.read() ;
Serial.println( result, HEX );
}
else
{
Serial.println(“No response available”);
}
delay(1000);
Serial.println(“leaving setup()” );
}

Good news.

After trying literally a thousand permutations of pullup resistors, modifications to twi and wire, alternative I2C libraries, and just about everything else, I have succeeded in getting communications with my Freescale MMA8451Q to work.

So it appears that I2C with "repeated start" bits can be made to work.

It's not clear exactly what the stumbling block was, because the permutation that eventually worked was the same as one that had previously not worked.

I did identify one very devious bug in the header file for the device which I had downloaded. For some obscure reason, the internal register addresses for the I2C device were defined by both #define's and an enum. And the enum was wrong, because one item was omitted leading to all the other items being wrong by 1.

did you mail your bug found to the maintainer of the code? Which device had exactly the bug? The MPL3115A2 pressure sensor or the Freescale MMA8451Q ?

The MMA8451Q software has the error.

It is in the example software of Freescale's, in their application note AN4076SW, in the .h file for the device. The 7th item in the enum is missing, which makes all the enum values > 7 to be wrong. The enum can be fixed by inserting the 7th element. Actually, element 7 is probably the 8th element.

This seems to be a very nice device, once it actually starts to work.