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.

BQ27220: bq27220 fuel gauge configuration through cc2640 via i2c communication

Part Number: BQ27220
Other Parts Discussed in Thread: CC2640
Hi,
We are using bq27220 fuel gauge in our project with battery(18000mAh) pack of 6 batteries 3000mAh each connected in parallel.

I am trying to update its parameters by TI's CC2640 ble module via i2c interface. I tried to code with the help of Example code given in http://www.ti.com/general/docs/lit/getliterature.tsp?baseLiteratureNumber=sluubd4&fileType=pdf  but still I am not able to update the Design capacity of battery. Can you please guide me that how can i configure the parameters of battery gauge.
I am adding the code by which I am trying change the battery parameter(Design capacity). 


//100 ms delay time
#define MS_2_TICK                             (((100) * 1000) / Clock_tickPeriod)
// bq27220 address
static uint8_t  slaveaddr_guage = 0x55;

static uint8_t control_staus[2]        =    {0x00,0x01};
static uint8_t device_id[2]            =    {0,0};
static uint8_t unseal_1[2]                =    {0x00,0x14};
static uint8_t unseal_2[2]                =    {0x01,0x04};
static uint8_t unseal_3[2]                =    {0x00,0x72};
static uint8_t unseal_4[2]                =    {0x01,0x36};

static uint8_t full_access_1[2]        =    {0x00,0xFF};
static uint8_t full_access_2[2]        =    {0x01,0xFF};
static uint8_t full_access_3[2]        =    {0x00,0xFF};
static uint8_t full_access_4[2]        =    {0x01,0xFF};

static uint8_t enter_cfg_up_1[2]        =    {0x00,0x90};
static uint8_t enter_cfg_up_2[2]        =    {0x01,0x00};

static uint8_t flag                     =     0;

static uint8_t msb_design_cap_1[2]        =    {0x3E,0x9F};
static uint8_t lsb_design_cap_2[2]        =    {0x3F,0x92};
static uint8_t old_checksum             =     0;
static uint8_t data_len                 =    0;
static uint8_t old_dc_msb;
static uint8_t old_dc_lsb;
static uint8_t design_capicity_1[2]     = {0x40,0x46};
static uint8_t design_capicity_2[2]     = {0x41,0x50};
static uint8_t temp;
uint8_t write_new_checksum[2] = {0,0};
static uint8_t new_checksum;
static uint8_t checksum_data_len ;
static uint8_t exit_cfg_update_1[2]     = {0x00,0x92,0x00};
static uint8_t exit_cfg_update_2[2]     = {0x01,0x00};
static uint8_t sealed_1[3]             = {0x00,0x30};
static uint8_t sealed_2[2]             = {0x01,0x00};


void Battery_gauge_init(void)
{
                /*selecting the i2c slave device */

                i2c_status = bspI2cOpen();

                 if (i2c_status == TRUE)
                {
                      while(bspI2cSelect(interface_0, slaveaddr_guage) == true)
                      {
                        Task_sleep(MS_2_TICK);
                      }

                if (bspI2cWrite(unseal_1,2) == true)
                {
                  /* Success */
                }

                Task_sleep(MS_2_TICK);

                if (bspI2cWrite(unseal_2,2) == true)
                {
                  /* Success */
                }

                Task_sleep(MS_2_TICK);

                if (bspI2cWrite(unseal_3,2) == true)
                {
                  /* Success */
                }

                Task_sleep(MS_2_TICK);

                if (bspI2cWrite(unseal_4,2) == true)
                {
                  /* Success */
                }

        /* Providing full access to data memory */

                Task_sleep(MS_2_TICK);

                if (bspI2cWrite(full_access_1,2) == true)
                {
                /* Success */
                }

                Task_sleep(MS_2_TICK);

                if (bspI2cWrite(full_access_2,2) == true)
                {
                  /* Success */

                }

                Task_sleep(MS_2_TICK);

                if (bspI2cWrite(full_access_3,2) == true)
                {
                  /* Success */

                }

                if (bspI2cWrite(full_access_4,2) == true)
                {
                  /* Success */

                }


                Task_sleep(MS_2_TICK);

        /* enter configure update */

                if (bspI2cWrite(enter_cfg_up_1,3) == true)
                {
                  /* Success */

                }

                Task_sleep(MS_2_TICK);

                if (bspI2cWrite(enter_cfg_up_2,2) == true)
                {
                  /* Success */

                }

                // 1sec delay
                Task_sleep(MS_2_TICK);
                /*check if configuration update is updated or not */

                while(!(flag & 0x20))
                {
                    if (bspI2cWriteRead(0x3B,1,&flag,1) == true)
                    {
                      /* Success */

                            Task_sleep(2*MS_2_TICK);
                    }
                }

                /* Get Access of MSB of data Capicity */
                Task_sleep(MS_2_TICK);

                if (bspI2cWrite(msb_design_cap_1,2) == true)
                {
                  /* Success */

                }

                Task_sleep(MS_2_TICK);

                /* Get Access of LSB of data Capicity */

                if (bspI2cWrite(lsb_design_cap_2,2) == true)
                {
                          /* Success */

                }

                Task_sleep(MS_2_TICK);
                /* read one byte of check sum */

                if (bspI2cWriteRead(0x60,1,&old_checksum,1) == true)
                {
                
                          /* Success */
                }

                Task_sleep(MS_2_TICK);
                /* read block length of checksum */


                if (bspI2cWriteRead(0x61,1,&data_len,1) == true)
                {
                          /* Success */
            }

                Task_sleep(MS_2_TICK);
                /* read both design capicity byte*/

                if (bspI2cWriteRead(0x40,1,&old_dc_msb,1) == true)
                        {
                                  /* Success */
                        }

                Task_sleep(MS_2_TICK);

                if (bspI2cWriteRead(0x41,1,&old_dc_lsb,1) == true)
                        {
                                  /* Success */
                        }

                Task_sleep(MS_2_TICK);
                /* write both designcapicity bytes here 18000mAh = 4650 */

                if (bspI2cWrite(design_capicity_1,2) == true)
                        {
                                  /* Success */
                        }

                Task_sleep(MS_2_TICK);

                if (bspI2cWrite(design_capicity_2,2) == true)
                        {
                                  /* Success */
                        }

                Task_sleep(MS_2_TICK);

                /* calculating new check sum */

                temp = 256 % (255 - old_checksum - old_dc_lsb - old_dc_msb);
                new_checksum = 255 - (256 % (temp + 0x4D + 0x58));

                write_new_checksum[0]     = 0x60;
                write_new_checksum[1]   = new_checksum;

                /* write new check sum */

                if (bspI2cWrite(write_new_checksum,2) == true)
                        {
                                  /* Success */
                        }

                Task_sleep(MS_2_TICK);

                /* read checksum data length */

                if (bspI2cWriteRead(0x61,1,&checksum_data_len,1) == true)
                        {
                                  /* Success */
                        }

                Task_sleep(MS_2_TICK);
                /* exit configurtion uodate */

                if (bspI2cWrite(exit_cfg_update_1,2) == true)
                        {
                                  /* Success */
                        }

                Task_sleep(MS_2_TICK);

                if (bspI2cWrite(exit_cfg_update_2,2) == true)
                        {
                                  /* Success */
                        }

                /* confermation that configuration update */
                Task_sleep(MS_2_TICK);

                while(flag & 0x20)
                {
                    if (bspI2cWriteRead(0x3B,1,&flag,1) == true)
                            {
                                      /* Success */

                                Task_sleep(MS_2_TICK);
                            }
                    Task_sleep(5 * MS_2_TICK);
                }

            /* return to the sealed mode */

                if (bspI2cWrite(sealed_1,2) == true)
                        {
                                  /* Success */
                        }

                Task_sleep(MS_2_TICK);
                if (bspI2cWrite(sealed_2,2) == true)
                        {
                                  /* Success */
                        }

                if (bspI2cWriteRead(control_staus,2,device_id,2) == true)
                        {
                                  /* Success */
                        }
                Task_sleep(MS_2_TICK);

                bspI2cDeselect();
            }

            bspI2cClose();
}