I2C - use of REPEATED START in reading date from slave MMA8452Q

203 views
Skip to first unread message

Harald SATTMANN

unread,
Feb 14, 2016, 1:11:16 PM2/14/16
to Pi4J

Hi
Anyone tried to read date from a slave needing repeated start sequence? Can not do this with java. RPi i2cget con do this if the combined parameter is set to 1 (Y).
Need this f.e. for the ADAFRUIT MMA8452Q accelerometer. (Same as in ORACLE SDK ME 8.2 sample). ORACLE and Pi4J are not doing the needed repeated start sequence. Anybody with help.

Regards, harald.

Kyle Godett

unread,
Feb 14, 2016, 11:07:51 PM2/14/16
to Pi4J
Harald,

Have you tried using the methods from com.pi4j.wiringpi.I2C? This worked for me on other chips.

Harald SATTMANN

unread,
Feb 15, 2016, 2:36:10 AM2/15/16
to Pi4J
HI Kyle thanx for answer.

I used
import com.pi4j.io.i2c.I2CBus;
import com.pi4j.io.i2c.I2CDevice;
import com.pi4j.io.i2c.I2CFactory;

and the following snippet:

        System.out.println("I2C Test start");
       
        try {
            I2C_bus = I2CFactory.getInstance(I2CBus.BUS_1);
            I2C_device = I2C_bus.getDevice(0x1D); 
           
            byte[] writeBuf = new byte[10];
            byte[] readBuf = new byte[10];
            writeBuf[0] = 0x0D;
            int val = I2C_device.read(writeBuf, 0, 1, readBuf, 0, 1);
            System.out.println("Result = " + String.format("0x%02X",readBuf[0]));
        }
        catch(IOException ex ) {
            System.out.println("Exception occured " + ex.toString());
        }

        System.out.println("I2C test finished");

This gives me:

I2C Test start
Result = 0x00
I2C test finished

but the result should be 0x2A.

Maybe I use the wrong statements.

Regards, Harald.

Harald SATTMANN

unread,
Feb 15, 2016, 4:34:19 AM2/15/16
to Pi4J
Hi
I but some more explanations in the attached file. It shows exactly wht I mean. Some errata: the device is not ADAFRUIT it is build by SPARCFUN and the some chip is used in the ORACLE SDK 8.2 ME samples which also do not work with the RPi. Same behavior.

Ragards, Harald
I2C repeated start does not work with Pi4J - 15.02.2016.pdf

Kyle Godett

unread,
Feb 15, 2016, 9:40:38 AM2/15/16
to Pi4J
Harald,

I had a similar experience with a MPL3115A3, where I used com.pi4j.io.i2c.* and I could never get it to work correctly, because the MPL3115A3 seems to reset it's address register every time it receives a stop bit. After changing my code to:


import com.pi4j.wiringpi.I2C;

i2c_handle = I2C.wiringPiI2CSetup(MPL_ADDRESS);

data = I2C.wiringPiI2CReadReg8(i2c_handle, MPL_DEVICE_ID_REG)


Everything seems to operate correctly.

Harald SATTMANN

unread,
Feb 15, 2016, 10:41:28 AM2/15/16
to Pi4J
Hi
Thanks. But that did not solve the problem. Still there is a STOP condition and not a REPEATED START and therefore the readout is not correct. I will play around with wiringpi tomorrow. Lets see.

Regards, Harald.

Harald SATTMANN

unread,
Feb 16, 2016, 4:24:46 AM2/16/16
to Pi4J
Hi
Found the solution. You are right. Your codesnippet solves the problem after I set the combined parameter in /sys/module/bcm_2708/paramters to Y
sudo echo -n 1 >combined.
Why the statement:

            writeBuf[0] = 0x0D;
            int val = I2C_device.read(writeBuf, 0, 1, readBuf, 0, 1);
does not do the job I have to figure out.

Thanx, harald.
Reply all
Reply to author
Forward
0 new messages