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.

BQ27421 I2C confusion

Hi everyone,

Could someone please help me provide me a small code snippet on reading the Device Type using the Control command and its sub-command? Also for putting the device to Shutdown? or even a detailed pseudo code is fine with me.

Sorry for asking like this, its just i already tried almost all i can do but still i can't get the expected result. For Voltage reading, Temperature reading and the rest, is already OK.

Thanks in advance.

- Geo

  • int i2cwrite( char i2c_address, char command, char * data, int length );

    int i2cread( char i2c_address, char command, char * data, int length );

     

    // reading device type:

    i2cwrite( 0x55, 0x00, (char[]){0x01,0x00}, 2); // Control(DEVICE_TYPE)

    char buffer[2];

    i2cread( 0x55, 0x00, buffer, 2); // Now read 

    unsigned short device_type = buffer[0] + (buffer[1] << 8);

    // Putting in shutdown:

    i2cwrite( 0x55, 0x00, (char[]){0x1B,0x00}, 2); // Control(SHUTDOWN_ENABLE)

    i2cwrite( 0x55, 0x00, (char[]){0x1C,0x00}, 2); // Control(SHUTDOWN)

    // What about Temperature():

    char buffer[2];

    i2cread( 0x55, 0x02, buffer, 2);

    unsigned short temperature = buffer[0] + (buffer[1] << 8); // Remember to convert this value, because it's in deciKelvin

     

    // Or Voltage():

    char buffer[2];

    i2cread( 0x55, 0x04, buffer, 2);

    unsigned short voltage = buffer[0] + (buffer[1] << 8); // in mV