This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

TWI_I2C_Error

main.cHi,

I am having an issue with I2C transaction in my program.

There are two sensors(Touch and Temp) connected to the I2C bus. Touch sensor is working well when I added Temp senor config, it started showing I2C error.

In my program line 407,408 are used to read Temp sensor. I am always getting error messages on these two line.

Any advise would be much appreciated.

Regards Siva

  • Hi,

    I found a very strange problem!

    In my program at line 145, I have defined "Temp_Addr1 0x80" if I replace "0x80" with "0x5A" it starts complying.

    Does any one know what might be the problem? I presume it nothing to do with the compiler.

    Regards Siva

  • I don't know what the proper address of your temperature sensor is, but from you code it looks like you are using a LMB75B sensor. Which if this is the case I don't think 0x80 can possibly be the correct I2C address based on this line from the datasheet:

    The LM75B slave address on the I2C-bus is partially defined by the logic applied to the device address pins A2, A1 and A0. Each of them is typically connected either to GND for logic 0, or to VCC for logic 1. These pins represent the three LSB bits of the device 7-bit address. The other four MSB bits of the address data are preset to ‘1001’ by hard wiring inside the LM75B.

  • Hello John,

    Thanks for your reply.

    In my code I left some of the bits that are already present in the TWI example(Temp and acce). I am not using them.

    I am actually using "SHT21" Temp Sensor which has got "0x80" address. I have also tried doing something like (0x08 <<4) but still shows the same error.

    Regards Siva

  • Hi John,

    Even though if I define incorrect address, the compiler should at least compile independent to actual hardware. My concern is why it's not complying instead it's showing "..../app_twi.h:76:40: error: large integer implicitly truncated to unsigned type #define APP_TWI_WRITE_OP(address)" (((address)<<1)|0)".

    I didn't understand this error.

    Regards Siva

  • Well, that certainly wasn't clear from the original question. "Complying" has a very different meaning than "compiling", I'd also suggest including the error when asking for help with a compilation issue. I believe what the compiler is telling you is that 0x80 left shifted one is too large for an 8 bit variable. I2C addresses steal the least significant bit as a R/W indicator so the code is taking your defined address and shifting it 1 bit to allow that to happen.

    If you look at the SHT21 data sheet the I2C address is a 7-bit 0b1000000, so you should be defining your address as 0x40 and then that shift will compile properly.

Related