Skip to Main Content

Transactional versus CombinedMessage

2833902Sep 6 2018 — edited Oct 30 2018

Hi,

I am trying to understand the semantic differences (if any) between using a Transactional Device and a *CombinedMessage (on the I2C or SPI bus).

The reason I ask is because I am trying to interact with a sensor (the MPU6050 accelerometer/gyroscope/thermometer sensor) which stores measurements in two 1-byte registers (one of which is the MSB and the other the LSB). Those registers are updated at whatever sampling rate has been configured in the sensor and each value can be built by concatenating the two bytes yielding a twos-complement number (effectively a short in the Java world).

Now, the catch is this: As mentioned, the sensor will keep updating those registers at the sampling rate and it becomes the app's responsibility to ensure that that both reads from both registers come from the same sampling instant so that we don't get into a situation where register A's value is from sampling instant #1 and register B's from instant #2. The datasheet suggests two ways of achieving that..you can either keep checking an "interrupt" pin and read the values when that's turned on or you must read both registers whilst the serial bus is busy (i.e. if this is the I2C bus, both reads happen between the "start" and "stop" sequences). So effectively, the bus acts as a lock whose "busy-ness" prevents the sensor from updating the registers.

If I understood correctly from reading the documentation two ways of implementing that is by using either a Transactional Device or a I2CCombinedMessage (MPU6050 only supports I2C access). The former is not an option on the RasPi platform which I am using, as the following code (mpu6050 is a I2CDevice instance):

if (mpu6050 instanceof Transactional) {

         System.out.println("Device transactional");

} else {

         System.out.println("Device not transactional");

}

prints: "Device not transactional"

I can implement that using the CombinedMessage approach but I was wondering..is there a semantic difference between the two approaches? i.e. if a Device supports the Transactional interface why would one choose one over the other?

Any input?

Thanks

Comments
Post Details
Added on Sep 6 2018
1 comment
326 views