This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

BQ27542-g1 fuel guage

Hello,

I want to read device id by sending sub command DEVICE_TYPE.

First i am sending command 0x01 to control reg which have 0x00 address.

after that i am sending sub command in byte to control reg  which have 0x00 address.

then i am reading control reg but it has some different value.As per the data sheet it should have  0x0541 value.

Can you Tell me this sequence is correct to read Device id.If this is wrong tell me the correct sequence.It is Baremetal  code.

Thanks

  • To read the DEVICE_TYPE you first have to write 0x01 0x00 to register 0x00 and 0x01 followed by reading register 0x00 and 0x01.

    Here is code that reads device type (pI2C is a pointer to an I2C driver context, which allows addressing of a specific I2C hardware interface - it's abstract and must be implemented for a specific system or can be left NULL if you don't need it):

    ...
    #define DEVICE_TYPE 0x0001

    nResult = gauge_control(pI2C, DEVICE_TYPE);
    printf("DEVICE_TYPE = 0x%04X\n\r", nResult);
    ...

    unsigned int gauge_control(void * pI2C, unsigned int nSubCmd)
    {
    unsigned int nResult = 0;

    char pData[2];

    pData[0] = nSubCmd & 0xFF;
    pData[1] = (nSubCmd >> 8) & 0xFF;

    i2c_write(pI2C, 0x00, pData, 2); // issue control and sub command

    i2c_read(pI2C, 0x00, pData, 2); // read data

    nResult = (pData[1] << 8) | pData[0];

    return nResult;
    }