UM1836
User manual
STSW-BAT001 open source driver for the STC3115
Aurelien Mazard
Introduction
The STC3115 open source driver is a ready-to-use, configurable software (STSW-BAT001) which
allows the STC3115 gas gauge IC to be rapidly integrated to the final system software. The driver is
split into five C language files and can be compiled with any operating system for any processor.
The STC3115 open source driver comes with a full API which uses simple input information to initialize
and control the STC3115 registers and RAM and return battery status information in a simple structure
to the system.
The open source driver is available for free to manage system requirements and to handle the
complexity of STC3115 initialization. It is intended only for example purposes.
This user manual describes the STC3115 open source driver (STSW-BAT001) package content,
capabilities, and correct usage. It also explains the step-by-step procedure to configure and integrate
the open source driver in a complete software architecture.
The figure below shows an overview of the STC3115 software driver architecture. No additional
software is needed to manage the STC3115.
Figure 1: STC3115 software driver architecture
Application
Main
Application layer
STC3115
Driver.C
STC3115 driver layer
STC3115 Driver.h
STC3115 Battery.h
STC3115
I2C.C
STC3115 intermediate
I2C layer
STC3115 I2C.h
Hardware driver layer
I2C dri ver
December 2014
DocID027146 Rev 1
1/16
www.st.com
Contents
UM1836
Contents
1
Software overview ........................................................................... 3
1.1
1.2
1.3
1.4
1.5
stc3115_Driver.c ............................................................................... 3
stc3115_Driver.h ............................................................................... 3
stc3115_Battery.h ............................................................................. 3
stc3115_I2C.c ................................................................................... 3
stc3115_I2C.h ................................................................................... 4
Battery parameters configuration ...................................................... 5
Application parameters configuration ................................................ 6
Exchange data structures ................................................................. 7
Main functions of the API .................................................................. 8
Additional functions of the API .......................................................... 9
Hardware initialization ..................................................................... 11
Software initialization ...................................................................... 11
Periodic update of the battery state................................................. 12
Stopping and resetting the STC3115 .............................................. 12
2
Software configuration ................................................................... 5
2.1
2.2
3
API overview .................................................................................... 7
3.1
3.2
3.3
4
How to use the driver .................................................................... 11
4.1
4.2
4.3
4.4
5
6
7
Code to call the API of the STC3115 open source driver ........... 13
Related documentation ................................................................. 14
Revision history ............................................................................ 15
2/16
DocID027146 Rev 1
UM1836
Software overview
1
Software overview
The STC3115 device is a battery monitoring IC which uses simple battery parameters and
system information to provide information on the battery state, such as the remaining
battery capacity, battery voltage, and battery current.
The STC3115 software driver package manages the STC3115 including device
configuration and battery information read back. Management and configuration of the
device is in accordance with battery and application events.
The STC3115 software driver package provides several files; the content of each is
described in the sections below. Their organization and connections are shown in
Figure 1.
1.1
stc3115_Driver.c
This file contains the functions to initialize and report the battery state based on STC3115
algorithms. The functions include the following features:
•
Dedicated I C functions which are linked to the interface driver functions in the
2
stc3115_I2C.c file (see
Section 1.4).
The hardware system has to support multiple I C
access commands to guarantee data integrity during the 16-bit register read/write
operations.
The STC3115 driver's own functions which are contained in the first part of the
stc3115_Driver.c file. These functions should not be accessed by external functions.
Gas gauge functions which are the main interface functions and which have to be
used by the application to initialize, monitor, and stop the STC3115 device.
Power saving functions which can be used to manage the STC3115 operating mode
(mixed mode or voltage mode). Power saving functions have to be called by an
external program to change the STC3115 operating mode after STC3115 initialization.
Alarm management functions which have to be called to set, stop, get, clear, and
change the alarm thresholds after STC3115 initialization.
2
•
•
•
•
1.2
stc3115_Driver.h
This file defines the STC3115 constant numbers and the driver API structures and
functions as follows:
•
•
•
The STC3115_ConfigData_TypeDef structure is filled by the driver with battery
configuration data from the stc3115_Battery.h (see
Section 1.3)
information.
The STC3115_BatteryData_TypeDef structure is filled by the driver with the battery
state.
The RAMData structure is the RAM memory map description which is used internally
by the driver. This structure must not be modified by external accesses.
1.3
stc3115_Battery.h
This file is used to describe the battery and application configuration. It has to be filed with
battery and application data (see
Section 2).
1.4
stc3115_I2C.c
This file is used to define the I C exchange functions between the STC3115 driver and the
2
2
application I C driver. This file has to be updated with the functions of the application I C
2
driver. The hardware system has to support multiple I C access commands to guarantee
data integrity during the 16-bit register read/write operations.
DocID027146 Rev 1
3/16
2
Software overview
UM1836
1.5
stc3115_I2C.h
This file is used to declare the I C exchange functions between the STC3115 driver and the
2
application I C driver.
2
4/16
DocID027146 Rev 1
UM1836
Software configuration
2
Software configuration
Configuration of the STC3115 open source driver is done using the stc3115_Battery.h file.
This file allows the battery and application parameters to be configured with the minimum
variable set.
2.1
Battery parameters configuration
An extract of the stc3115_Battery.h file where battery parameters are defined is shown
below. A detailed explanation of the terms used in this code (CAPACITY, RINT, and
OCV_OFFSET_TAB) is also available below.
/*Battery parameters define ----------------------------------------*/
#define CAPACITY 1500 /* battery nominal capacity in mAh
*/
#define RINT 200 /* Internal battery impedance in mOhms,0 if unknown*/
#define OCV_OFFSET_TAB {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
/* OCVTAB */
The CAPACITY parameter describes the typical battery capacity in mAh.
The RINT parameter describes the internal battery impedance in mOhm. The value has to
include battery cell impedance and battery security IC impedance. If the battery is
connected to the STC3115 by long and/or small wires, the wire impedance has also to be
included in this parameter. If this parameter is unknown, it can be declared as zero. In this
case, a default value of 200 mOhms is used for the RINT.
The OCV_OFFSET_TAB is the REG_OCVTAB register described in the STC3115
datasheet. This register can be filled by using the battery open circuit voltage (OCV) curve
(see AN4324). If the OCV adjustment table is set up at 0, the OCV curve used to monitor
the battery is the default OCV programmed in the STC3115 internal registers (see
STC3115 datasheet). This default configuration is adequate to maintain a functional
system. The OCV adjustment table must not be filled with any value below -127 or above
127.
DocID027146 Rev 1
5/16