### STC3115 Initialization Sequence Example Source: https://github.com/st-sw/stc3115genericdriver/blob/master/Examples/InitExamples/STC3115_init_sequence_example_(pseudo-code).txt This pseudo-code demonstrates the full initialization sequence for the STC3115 gas gauge. It includes steps for device reset, configuration of various registers, and starting the monitoring process. Customize register values based on specific battery characteristics and system configuration. ```pseudo-code # Wait the battery is relaxed (recommended) (i.e. wait 30s or more) # Check I2C is working & Device ID is correct (must be equal to 0x14) I2C_Read @0x18 # [Optional]: Set GG_RUN to 0 if Device already running (default value at init: 0x09) I2C_Write @0x00 0x09 # Clear the Power-On Reset (POR) detection bit, and release the software-reset (default value at init: 0x15) I2C_Write @0x01 0x05 # Wait the Device is ready (i.e. wait it finished the initial measurements) # Status is checked by waiting REG_COUNTER value is 3 or more, or by waiting 1.5s after reset. loop while VALUE < 3 { #read REG_COUNTER I2C_Read @0x04 & @0x05 #(2 byte length) } # Read and store REG_OCV I2C_Read @0x0D (2 byte length) # Write REG_OCVTAB (set the values depending on the battery characteristics). (Below are the default values) I2C_Write @0x30 0x00 I2C_Write @0x31 0x00 I2C_Write @0x32 0x00 I2C_Write @0x33 0x00 I2C_Write @0x34 0x00 I2C_Write @0x35 0x00 I2C_Write @0x36 0x00 I2C_Write @0x37 0x00 I2C_Write @0x38 0x00 I2C_Write @0x39 0x00 I2C_Write @0x3A 0x00 I2C_Write @0x3B 0x00 I2C_Write @0x3C 0x00 I2C_Write @0x3D 0x00 I2C_Write @0x3E 0x00 I2C_Write @0x3F 0x00 # Compute VM_CNF = R_internal_battery x C_nom_battery / 977.78 # Write REG_VM_CNF (Voltage Mode Configuration) I2C_Write @0x11 0x21 I2C_Write @0x12 0x03 # Compute CC_CNF = R_sense_external x C_nom_battery / 49.556 # Write REG_CC_CNF (Coulomb Counter Configuration) only if mixed-mode is used with an external sense Resistor I2C_Write @0x0F 0x95 I2C_Write @0x10 0x03 # Write REG_ALARM_SOC (default value at init: 0x02) I2C_Write @0x13 0x02 # Write REG_ALARM_VOLTAGE (default value at init: 0xAA) I2C_Write @0x14 0xAA #Write IO0DATA for Alarm pin (default bit value is 1: driven by alarm condition) I2C_Write @0x01 0x01 # Write back REG_OCV I2C_Write @0x0D MYDATA1 (2 byte length) # Write VMODE (Voltage mode or Mixed mode) (e.g. set to Mixed mode here) I2C_Write @0x00 0x08 # Start the device monitoring: Set GG_RUN to 1 # (Note: Enable GG_RUN only at the end of the init sequence) # (for example set value to 0x18) I2C_Write @0x00 0x18 # now periodically read the state of charge REG_SOC (every 5s) loop { #read REG_SOC I2C_Read @0x02 & @0x03 #(2 byte length) #read REG_VOLTAGE I2C_Read @0x08 & @0x09 #(2 byte length) #read REG_CURRENT I2C_Read @0x06 & @0x07 #(2 byte length) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.