Page 13 and 14 of the bq27x10 data sheet have limited information about the host side configuration of the bq27210. There is very little information on this subject in the data sheet and the little bit of information there is confusing at best.
I'm trying to load new coefficients to the bq27210 with the CTRL and MODE registers using the UPDC, UPEDV1, UPDMF, UPCFG, and UPCOMP bits.
The datasheet states: "The host must set the appropriate command bit in MODE before sending the command key to CTRL" So that's how I implemented my code. However, the MSP430 application example for the BQ27210 does the following to set the up the GPIO bits in the MODE and CTRL regs:
MSP430_bq27210_write(bq27x10CMD_CTRL, 0xA9); //Set the command key in CTRL
MSP430_bq27210_read(bq27x10CMD_MODE, 1); //Reads MODE
mode = RxData[0];
mode &= ~(bq27x10REG_MODE_GPIEN|bq27x10REG_MODE_GPSTAT);
MSP430_bq27210_write(bq27x10CMD_MODE, mode); //Writes the command to MODE
This is the exact opposite of what the data sheet says to do. Later in the MSP430 example code to perform an offset measurement:
// Perform internal offset measurement
MSP430_bq27210_write(bq27x10CMD_MODE, bq27x10REG_MODE_CIO);
MSP430_bq27210_write(bq27x10CMD_CTRL, 0x56);
The MODE reg is set followed by writing a 0x56 to the CTRL reg like the data sheet says to.
My problem is that neither of these methods is working to modify the UPDC, UPEDV1, UPDMF, UPCFG, and UPCOMP bits and load new data into the 0x46-0x4f RAM space. I've verified that my I2C comm setup is working and can correctly read the battery voltage, flag, and average current registers. I can also write data to the ARL and ARH registers and read it back without issues.
The following is my code. This is written for a PIC18F25J50 and compiled with Microchips C18 compiler. When I run the code and look at RAM locations 0x46-0x4f I see part of the correct values in neighboring locations, but there's no pattern. Am I missing something?
//Device i2c address
#define FUEL_ADDR 0xaa
//RAM Regs
#define ARL_REG 0x02
#define ARH_REG 0x03
#define MODE_REG 0x01
#define CTRL_REG 0x00
//EEPROM Reg Config
//defined from battery calc spreadsheet
//Address 0x76
#define ILMD 0x05
//Address 0x77
#define SEDVF 0x64
//Address 0x78
#define SEDV1 0xb6
//Address 0x79
#define ISCL_EDVT 0x23
//Address 0x7a
#define DMFSD 0x38
//Address 0x7b
#define TAPER 0x81
//Address 0x7c
#define PKCFG 0xC0
//Address 0x7d
#define GAF_DEDV 0x43
//Address 0x7e
#define DCOMP 0x09
//Address 0x7f
#define TCOMP 0x2e
//Commands
//Related to host parameter updates
#define EEUPDATE 0xc5
#define FGRESET 0xa9
#define UPCOMP 0x01
#define UPCFG 0x02
#define UPDMF 0x08
#define UPEDV1 0x10
#define UPDC 0x20
#define FGINIT 0x04
#define FRST 0x02
//Related to battery monitoring
#define VOLT 0x08
#define AMPS 0x14
#define FLAGS 0x0a
#define CMD_CYCT 0x2a
#define CMD_NAC 0x0c
#define CMD_LMD 0x0e
//Flag Register bit offsets
#define FLAG_CHGS 0b10000000
#define FLAG_NOACT 0b01000000
#define FLAG_IMIN 0b00100000
#define FLAG_CI 0b00010000
#define FLAG_CALIP 0b00001000
#define FLAG_VDQ 0b00000100
#define FLAG_EDV1 0b00000010
#define FLAG_EDVF 0b00000001
void _UPCOMP(void)
{
//////////////////////////////////////////////////////////////////////
//COMMAND: UPCOMP
//
//DCOMP-ARL_REG
//TCOMP-ARH_REG
//////////////////////////////////////////////////////////////////////
EEByteWrite(FUEL_ADDR, ARL_REG, DCOMP);
EEByteWrite(FUEL_ADDR, ARH_REG, TCOMP);
EEByteWrite(FUEL_ADDR, MODE_REG, UPCOMP);
EEByteWrite(FUEL_ADDR, CTRL_REG, EEUPDATE);
}
void _UPCFG(void)
{
//////////////////////////////////////////////////////////////////////
//COMMAND:UPCFG
//PKCFG-ARL_REG
//GAF/DEDV-ARH_REG
//////////////////////////////////////////////////////////////////////
EEByteWrite(FUEL_ADDR, ARL_REG, PKCFG);
EEByteWrite(FUEL_ADDR, ARH_REG, GAF_DEDV);
EEByteWrite(FUEL_ADDR, MODE_REG, UPCFG);
EEByteWrite(FUEL_ADDR, CTRL_REG, EEUPDATE);
}
void _UPDMF(void)
{
//////////////////////////////////////////////////////////////////////
//COMMAND:UPDMF
//DMFSD-ARL_REG
//TAPER-ARH_REG
//////////////////////////////////////////////////////////////////////
EEByteWrite(FUEL_ADDR, ARL_REG, DMFSD);
EEByteWrite(FUEL_ADDR, ARH_REG, TAPER);
EEByteWrite(FUEL_ADDR, MODE_REG, UPDMF);
EEByteWrite(FUEL_ADDR, CTRL_REG, EEUPDATE);
}
void _UPEDV1(void)
{
//////////////////////////////////////////////////////////////////////
//COMMAND:UPEDV1
//EDV1-ARL_REG
//ISCL/EDVT-ARH_REG
//////////////////////////////////////////////////////////////////////
EEByteWrite(FUEL_ADDR, ARL_REG, SEDV1);
EEByteWrite(FUEL_ADDR, ARH_REG, ISCL_EDVT);
EEByteWrite(FUEL_ADDR, MODE_REG, UPEDV1);
EEByteWrite(FUEL_ADDR, CTRL_REG, EEUPDATE);
}
void _UPDC(void)
{
//////////////////////////////////////////////////////////////////////
//COMMAND:UPDC
//ILMD-ARL_REG
//EDVF-ARH_REG
//////////////////////////////////////////////////////////////////////
EEByteWrite(FUEL_ADDR, ARL_REG, ILMD);
EEByteWrite(FUEL_ADDR, ARH_REG, SEDVF);
EEByteWrite(FUEL_ADDR, MODE_REG, UPDC);
EEByteWrite(FUEL_ADDR, CTRL_REG, EEUPDATE);
}
void main(void)
{
//turn on i2c
i2cInit();
//update RAM values
_UPDC();
_UPEDV1();
_UPDMF();
_UPCFG();
_UPCOMP();
//read back data from 0x46 to 0x4f
EESequentialRead(FUEL_ADDR, 0x46, var, 10);
}