I2CDevice.getDevice($ADDR) fails on an I2C device which requires "Repeated Start I2C support" (MMA8451)

38 views
Skip to first unread message

Tom Moyer

unread,
Jan 28, 2018, 9:24:35 PM1/28/18
to Pi4J
Am trying to port Massixon's support (python) for the Adifruit MMA8541 accerometer to java.
The MMA8541 is said to require "repeated start I2C support".   
Pi4J throws exception upon attempting the I2CDevice.getDevice()

The output from the attached .java file is: 

instanced bus ok
luxDevice=com.pi4j.io.i2c.impl.I2CDeviceImpl@ea2f77
device=com.pi4j.io.i2c.impl.I2CDeviceImpl@1c7353a
Exception in thread "main" java.io.IOException: Error reading from I2CDevice on I2CBus '1' ('/dev/i2c-1') at address 0x1d to address 0x2a. Got '-20001'.
at com.pi4j.io.i2c.impl.I2CDeviceImpl.read(I2CDeviceImpl.java:227)
at myJavaStuff.MMA8451.main(MMA8451.java:323)


Have Massixon's  https://github.com/massixone/mma8451   accel.py up and running which demonstrates two things,
1) My Raspberry Pi 3 Model B is able function with the MMA8541
2) The Adifruit documentation of the default address as 0x1C might need to be corrected.
    I mention this only in that if anyone is trying to diagnose with hardware the address becomes important.
    My board has no connection to the A address select pin, but the Massixon default address of   i2caddr = 0x1D works
Have acquired a TSL2561, and successfully executed the Pi4J   I2CExample.java, which uses the I2CDevice.getDevice($ADDR) 


MMA8451.java

Greg Flurry

unread,
Jan 29, 2018, 10:04:44 AM1/29/18
to Pi4J
I cannot tell if the symptoms of your problem are the same as I had with my device (FXAS21002C) and Pi4J. First, your subject suggests there is a problem with I2CDevice.getDevice(), but the exception seems to indicate a problem with I2CDevice[Impl].read(). Second, I copied the code you posted into my IDE, and line 323 (supposedly the source of the exception) is a comment, so I really can't tell much.

I suggest you create a very short simple program to highlight your problem and thus help diagnose.

Tom Moyer

unread,
Jan 31, 2018, 6:15:54 PM1/31/18
to Pi4J
Got a java implementation of MMA8451 demo code to function, following the clues from Greg Flurry.  
The crux of getting an I2C device which "requires repeated start" is to use the I2C.wiringPiI2C library.
Working code attached. 
MMA8451.java
Reply all
Reply to author
Forward
0 new messages