Skip to Main Content

How to work with I2C bus in Jave ME 8?

Yury EvgenevApr 3 2015 — edited Apr 6 2015

I have the following setup with Raspberry Pi.

Two devices are connected to the bus: temperature sensor and RTC.

My program periodically reads sensor’s data in one thread.

           I2CDevice slave = DeviceManager.open(I2CDevice.class, config);

            slave.begin();

            slave.read(TEMPERATURE_REGISTER, REGISTER_ADDRESS_SIZE, rxBuf);

            slave.end();

slave.close();

This works fine. But if I try to read RTC from another thread at the same time as reading sensor, sometimes it throws an exception.

Uncaught exception: java.lang.IllegalStateException: Driver reported error

- com.oracle.dio.i2cbus.impl.I2CSlaveImpl.transfer0(), bci=0

- com.oracle.dio.i2cbus.impl.I2CSlaveImpl.transfer(), bci=64

- com.oracle.dio.i2cbus.impl.I2CCombinedMessage.transfer(), bci=213

- com.oracle.dio.i2cbus.impl.I2CSlaveImpl.end(), bci=48

- home.dm.sensors.LM75ADSensor.readCurrentTemperatureValue(), bci=63

- home.dm.sensors.LM75ADSensor.refreshTemperatureValue(), bci=2

- home.dm.LoggerService.run(), bci=67

- java.lang.Thread.run(), bci=5

[ERROR] [CORE] iso=2:Uncaught exeption java/lang/IllegalStateException. Driver reported error

So, my questions are: How can I determine if I2C bus is occupied or free at current moment?

How to lock I2C bus to avoid this exception?

Comments
Post Details
Added on Apr 3 2015
1 comment
1,103 views