Wrong I2C addresses

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Wrong I2C addresses

3,466 Views
dimitrissideris
Contributor III

Hi there,

I have a custom pcb with an LPC 4367 on it.

I am trying to build a multisensor device with multiple i2c sensors.

According to datasheets, sensors are expected to have specific i2c addresses.

From lpcopen examples, I use i2c_probe_slaves function from i2c example and i see other addresses than expected and although 4 i2c sensors are on pcb more addresses occur. (without having any other i2c devices) !!!???

Could that be error responses from i2c devices and not their adresses?

i2c_probe_slaves function of i2c example uses Chip_I2C_MasterRead function to find i2c slave device address.

The lpcopen driver is implemented in such a way that can talk with every i2c device or in some cases this Chip_I2C_MasterRead function cannot get a device's address?

Can anyone help me figure out why i get wrong i2c addresses?

Labels (3)
Tags (4)
0 Kudos
3 Replies

2,115 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Dimitrs Sideris,

   

    i2c_probe_slaves is the function that probes all available slaves connected to an I2C bus.

   Different the I2C slave have different address, if the master send the address which the slave have, this slave will give ACK, if it is not the slave's address, the master will get the NACK.

   This logic analyzer wave will help you to understand it:

pastedImage_1.png

   In fact, in your own application, you don't need to send a lot of addresses, because you already know your sensor's address, you can send the sensor address directly.

   About the code:

static void i2c_probe_slaves(I2C_ID_T i2c)
{
    int i;
    uint8_t ch[2];

    DEBUGOUT("Probing available I2C devices...\r\n");
    DEBUGOUT("\r\n     00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F");
    DEBUGOUT("\r\n====================================================");
    for (i = 0; i <= 0x7F; i++) {
        if (!(i & 0x0F)) DEBUGOUT("\r\n%02X  ", i >> 4);
        if (i <= 7 || i > 0x78) {
            DEBUGOUT("   ");
            continue;
        }
        /* Address 0x48 points to LM75AIM device which needs 2 bytes be read */
        if(Chip_I2C_MasterRead(i2c, i, ch, 1 + (i == 0x48)) > 0)
            DEBUGOUT(" %02X", i);
        else
            DEBUGOUT(" --");
    }
    DEBUGOUT("\r\n");
}

   This code will send address from 0x08 to 0x078, you don't need to send all these address, you just need to call:

Chip_I2C_MasterRead(i2c, Sensor_address, ch, 1 );

Sensor_address is your own sensor's address.

Wish it helps you!

If you still have question, please contact me!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

2,115 Views
dimitrissideris
Contributor III

Hi Kerry Zhou,

Thanks for the quick reply.

The problem is that i am working on a custom pcb and when i probe the i2c slaves i don't see correct addresses.

More specifically i have a temperature/humidity sensor that lies in 0x40 address.

When i speak directly to that address or probe the i2c slave I never see sth at address 0x40.

I changed the iteration number of "for (i = 0; i <= 0x7F; i++) {" for test reasons (i know i2c can have up to 127/7f slave addresses) and a device appear at 0xC0 (0x40 is 0b 100 0000, 0xC0 is 0b 1100 0000 ).

Also i have two sensors at correct addresses as expected.

0x60 and 0x6A. There are also devices at 0xE0 (0x60 is 0b 110 0000, 0xE0 is 0b 1110 0000 ) and

0xEA (0x6A is 0b 110 1010, 0xEA is 0b 1110 1010 ).

To sum up,

I should see the 7bit addresses 0x40, 0x60 and 0x6A. I only see 0x60 and 0x6A.

When i change probe slave to check after 7F. I see 0xC0, 0xE0 and 0xEA addresses that are the 7bit above adresses with an 1 as an eight bit.

Is this expected?

When i2c_probe_slaves function is called Chip_I2C_MasterRead is called and then Chip_I2C_MasterTransfer

that finally calls these two functions:

/* Enable I2C and start master transfer */
STATIC INLINE void startMasterXfer(LPC_I2C_T *pI2C)
{
    /* Reset STA, STO, SI */
    pI2C->CONCLR = I2C_CON_SI | I2C_CON_STA | I2C_CON_AA;

    /* Enter to Master Transmitter mode */
    pI2C->CONSET = I2C_CON_I2EN | I2C_CON_STA;
}

and

/* Enable I2C and enable slave transfers */
STATIC INLINE void startSlaverXfer(LPC_I2C_T *pI2C)
{
    /* Reset STA, STO, SI */
    pI2C->CONCLR = I2C_CON_SI | I2C_CON_STA;

    /* Enter to Master Transmitter mode */
    pI2C->CONSET = I2C_CON_I2EN | I2C_CON_AA;
}

.

How does the i2c_probe_slaves gets the ack as you showed before and understands that a device lies in a specific address?

Thanks a lot in advance.

Dimitris

0 Kudos

2,115 Views
kerryzhou
NXP TechSupport
NXP TechSupport

HI Dimitris,

The address is 7bit:(0b)xxxx xxxr a.xxxx xxx is the address data in Lpc code, r is the read bit 1, w is the write bit 0, a is the ack bit.
Did your sensor need 0x40 in the I2C bus directly? (0b)0100 0000 a?
If yes, you can't send 0x40 data in the address, because if you use the 0x40 data in the code, you will find the data in I2C wave is:0x81+ACK or NACK, read. if write, should be 0x80+ack or nack.
Just like the above logic anayzer wave I give you, the code send address 0x2d, and the data in the I2C wave is 0x5B.
Now, please give me your sensor datasheet, the I2C wave to read the addresss.
You said you want 0x60, but device at 0xe0, what do your mean device at 0xe0, the I2C wave data or the LPC code send address data?

Please give me more details.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos