I2C address bug with basic read?

I believe I have found a bug. Correct me if I’m wrong.

I have a TE M3200 pressure/temperature sensor with default I2C address 0x36. It wasn’t working with my imp code and I used a logic analyzer to deduce it must have been an address issue.

So I wrote a loop to test all 127 I2C addresses and my sensor only responded when the imp was testing address 108d = 0x6C. I confirmed with my logic analyzer that this is address 0x36 on the actual I2C bus.

Why do I have to write 0x6C to get address 0x36 on the I2C bus?

0x6C is 0x36 right shifted by 1. Is this I2C address convention to include the R/W bit in the address?


Apparently the logic software includes the R/W bit in the I2C address.

Device code:

// This is device code
@include "device/flash.nut"
@include "device/flow-meter.nut"

 
class TE_M3200 {
    _i2c  = null;
    _addr = null;
  
    constructor(i2c) {
        _i2c  = i2c;
        _addr = 0x35; /* TE M3200 part # M32xx-xxxx1x-xxxxx. The "1" = addr 0x36*/
    }
  
    function get() {
        for(local address = 0; address < 128; address++){
            server.log("trying i2C address " + address);
            local reading = _i2c.read(address, "", 4);
            server.log(reading)
            local error_check = _i2c.readerror();
            if(error_check != 0){
                server.log("TE M3200 I2C Error " + error_check)

                // return error_check;
            }
            else{
                break;
            }

        }

        /*
            https://developer.electricimp.com/api/hardware/i2c/readerror

            No error	0	Method completed successfully
            Controller select error	-1	Timeout waiting for bus to be released after sending start
            Transmit select error	-2	Timeout while selecting transmit mode
            Transmit error	-3	Timeout while sending data
            BTF error	-4	Timeout waiting for data transfer to complete
            Stop error	-5	Timeout waiting for stop condition to be detected
            Address clear error	-6	Timeout waiting for address flag to be cleared
            Address RXNE error	-7	Timeout waiting for address to be read
            Data RXNE error	-8	Timeout waiting for data to be read
            Peripheral NACKed error	-9	Peripheral NACKs the send
            Controller receive select error	-10	Timeout while selecting multibyte receive mode
            Receive error	-11	Timeout during multibyte read
            Reselect error	-12	Timeout waiting for bus to be released after sending start
            Not enabled	-13	Attempt to read or write from an unconfigured peripheral
        */

        // local pressure_raw = reading[1];
        // pressure_raw = pressure_raw | ((reading[0] & 0x3F) << 8);

        // local temperature_raw = reading[3] >> 5;
        // temperature_raw = temperature_raw | (reading[2] << 3);

        // local status = reading[0] >> 6;

        // return "Temperature: " + temperature_raw + ", Pressure: " + pressure_raw, ", Status: " + status;
    }
}

// Configure an imp001 i2c bus
hardware.i2cJK.configure(CLOCK_SPEED_400_KHZ);

// Create TempSensor object
tempSensor <- TE_M3200(hardware.i2cJK);

// Read temperature
server.log(tempSensor.get());

Output:

2020-08-19 14:09:20-0700 [Device] TE M3200 I2C Error -10
2020-08-19 14:09:20-0700 [Device] trying i2C address 98
2020-08-19 14:09:20-0700 [Device] (null : 0x0)
2020-08-19 14:09:20-0700 [Device] TE M3200 I2C Error -10
2020-08-19 14:09:20-0700 [Device] trying i2C address 99
2020-08-19 14:09:20-0700 [Device] (null : 0x0)
2020-08-19 14:09:20-0700 [Device] TE M3200 I2C Error -10
2020-08-19 14:09:20-0700 [Device] trying i2C address 100
2020-08-19 14:09:20-0700 [Device] (null : 0x0)
2020-08-19 14:09:20-0700 [Device] TE M3200 I2C Error -10
2020-08-19 14:09:20-0700 [Device] trying i2C address 101
2020-08-19 14:09:20-0700 [Device] (null : 0x0)
2020-08-19 14:09:20-0700 [Device] TE M3200 I2C Error -10
2020-08-19 14:09:20-0700 [Device] trying i2C address 102
2020-08-19 14:09:20-0700 [Device] (null : 0x0)
2020-08-19 14:09:20-0700 [Device] TE M3200 I2C Error -10
2020-08-19 14:09:20-0700 [Device] trying i2C address 103
2020-08-19 14:09:20-0700 [Device] (null : 0x0)
2020-08-19 14:09:20-0700 [Device] TE M3200 I2C Error -10
2020-08-19 14:09:20-0700 [Device] trying i2C address 104
2020-08-19 14:09:20-0700 [Device] (null : 0x0)
2020-08-19 14:09:20-0700 [Device] TE M3200 I2C Error -10
2020-08-19 14:09:20-0700 [Device] trying i2C address 105
2020-08-19 14:09:20-0700 [Device] (null : 0x0)
2020-08-19 14:09:20-0700 [Device] TE M3200 I2C Error -10
2020-08-19 14:09:20-0700 [Device] trying i2C address 106
2020-08-19 14:09:21-0700 [Device] (null : 0x0)
2020-08-19 14:09:21-0700 [Device] TE M3200 I2C Error -10
2020-08-19 14:09:21-0700 [Device] trying i2C address 107
2020-08-19 14:09:21-0700 [Device] (null : 0x0)
2020-08-19 14:09:21-0700 [Device] TE M3200 I2C Error -10
2020-08-19 14:09:21-0700 [Device] trying i2C address 108
2020-08-19 14:09:21-0700 [Device] binary: 84 a3 5f 50
2020-08-19 14:09:21-0700 [Device] (null : 0x0)

This is not a bug, this is as designed - see the “addressing” section here: https://developer.electricimp.com/resources/i2c

It’s rather a matter of personal choice as to whether you refer to i2c addresses as 7 or 8 bits (with the bottom bit ignored). The imp uses 8 bit addresses, and inserts the correct bit for read/write as bit 0.

As you noticed, your logic analyzer software works the same way as impOS.

This topic was automatically closed after 60 days. New replies are no longer allowed.