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.

bq24160 I2C

Other Parts Discussed in Thread: BQ24160

hey it s me again :) 
i'm trying to make an I2c communication between the bq24160 and a microcontroller 16f 
the microcontroller is a master and the bq is a slave 
so i want to know for example if the alimentation is from  an USB or IN 
so i write this code 
can u chek it for me plz 


#include <16F.h>
#include <lcd.c>

#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz)
#FUSES PUT //Power Up Timer
#FUSES PROTECT //Code protected from reads
#FUSES NODEBUG //No Debug mode for ICD
#FUSES BROWNOUT //Brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected

#use delay(clock=20M)
#use i2c(MASTER, sda=*** ,scl=*** ,force_hw )/
int data

main ()
{
while (1)
{
//lcd_init() ;

i2c_start(); // start i2c
i2c_write(0x70) ; // adress of the slave device REG_STATUS_STAT_MASK
data=i2c_read(); // read the status of the mask

if (data=0x03)
{
lcd_gotoxy(1,1);
lcd_putc("\charging from IN \n");
}
else if (data=0x04)
{
lcd_gotoxy(1,1);
lcd_putc("\charging from USB \n");
}
else if (data=0x05)
{
lcd_gotoxy(1,1);
lcd_putc("\charge done \n");
}
i2c_stop();
}
}

  • Hello Jbeli,

    Due to variation in code styles and compilers I can not speak as to whether or not your code will work.

    The way I would approach this question:

    -Enable I2C

    -Address the device

    -Read the Status register by using the register address and setting the Read/Write bit in the address to READ

    I would then isolate the STAT_1, 2, & 3 bits to determine what input is selected and if it is charging.

    Have you attempted you code on a development platform before posting? You should be able to see if the you can read which input is active without even having a battery attached.