In that case, I would start with the example I provided. In my application, I was reading voltage, current, and capacity. You’ll have to make some changes though as my application utilized two cells and their nominal capacity is likely not the same as your cell. Compare my register settings with the descriptions in the datasheet to see the changes I made from the default configuration.
As for basic registers, I would start with nConfig, nNVCfgx, and nPackCfg.
Here’s the complete code from my application if that helps. Sorry about the lacking comments.
/******************************************************************************/
/* Includes */
/******************************************************************************/
#include "mbed.h"
/******************************************************************************/
/* Globals */
/******************************************************************************/
I2C max17205( D7, D10 ); // PF_0 and PA11
Serial data_out( PB_6, PB_7, 9600 );
Ticker tick;
DigitalOut led( LED1 );
const int slave_addr = 0x6C;
const int nslave_addr = 0x16;
/******************************************************************************/
/* Function Prototypes */
/******************************************************************************/
int read_reg( int addr );
void write_reg( int addr, int value );
/******************************************************************************/
/* Interrupt Service Routines */
/******************************************************************************/
void wake( void )
{
SCB->SCR &= ~( SCB_SCR_SLEEPONEXIT_Msk );
}
/******************************************************************************/
/* Function Definitions */
/******************************************************************************/
/*******************************************************************************
* Function: main
* Author: Matt Mielke
* Description:
* Date: 04/03/17
*******************************************************************************/
int main( void )
{
float RepSOC; //, VCell;
//int Current;
char data_str[100];
wait( 0.5 );
write_reg( 0x18E, 0x0A05 ); // nODSCTh
write_reg( 0x18F, 0x4040 ); // nODSCCfg
write_reg( 0x19E, 0x9658 ); // nVEmpty
write_reg( 0x1B0, 0x0215 ); // nConfig
write_reg( 0x1B3, 0x3454 ); // nDesignCap
write_reg( 0x1A5, 0x3454 ); // nFullCapNom
write_reg( 0x1B5, 0x0C02 ); // nPackCfg
write_reg( 0x1B8, 0x0930 ); // nNVCfg0
write_reg( 0x1B9, 0x080E ); // nNVCfg1
write_reg( 0x1C0, 0xD996 ); // nVAltTh
write_reg( 0x1C1, 0x2305 ); // nTAlrtTh
write_reg( 0x1C2, 0x6401 ); // nSAlrtTh
write_reg( 0x1C3, 0x00BC ); // nIAlrtTh
write_reg( 0x0BB, 0x0001 ); // fuel gauge reset
wait( 0.5 );
tick.attach( &wake, 5.0 );
while ( 1 )
{
led = 1;
RepSOC = read_reg( 0x006 ) / 256.0;
//VCell = read_reg( 0x009 ) * 0.078125e-3;
//Current = read_reg( 0x00A );
//if ( Current & 0x00008000 ) Current |= 0xFFFF0000;
//sprintf( data_str, "%f, %f, %f\n\r", RepSOC, VCell, Current * 1.5625e-6 / 0.0197 );
data_out.printf( "%03.1f\0", RepSOC );
led = 0;
SCB->SCR &= ~( SCB_SCR_SLEEPDEEP_Msk );
SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk;
__WFI();
}
}
/*******************************************************************************
* Function: read_reg
* Author: Matt Mielke
* Description: This function utilizes the mbed I2C library to read the value
* contained in a register on the MAX17205. It distinguishes
* between the volitile and non volitile address spaces. If an
* error occurs when writing the desired address to the device, the
* write function will be repeaded until it succeeds. If the
* subsequent read operation fails, a value of -1 is returned.
* Date: 04/03/17
*******************************************************************************/
int read_reg( int addr )
{
char buffer[2] = {0};
if ( addr & 0x100 )
{
addr &= 0xFF;
while ( max17205.write( nslave_addr, (char*)&addr, 1 ) );
if ( max17205.read( nslave_addr, buffer, 2 ) )
{
return -1;
}
}
else
{
addr &= 0xFF;
while ( max17205.write( slave_addr, (char*)&addr, 1 ) );
if ( max17205.read( slave_addr, buffer, 2 ) )
{
return -1;
}
}
return ( buffer[1] << 8 ) | buffer[0];
}
/*******************************************************************************
* Function: write_reg
* Author: Matt Mielke
* Description: This function utilizes the mbed I2C library to write to a
* register on the MAX17205. If the register address is in the non
* volitile space, the non volitile address is used. The write
* function will repeat in a loop if it fails.
* Date: 04/03/17
*******************************************************************************/
void write_reg( int addr, int value )
{
char buffer[3] = {0};
buffer[0] = addr & 0xFF;
buffer[1] = value & 0xFF;
buffer[2] = ( value >> 8 ) & 0xFF;
if ( addr & 0x100 )
{
while ( max17205.write( nslave_addr, buffer, 3 ) );
}
else
{
while ( max17205.write( slave_addr, buffer, 3 ) );
}
}