Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
STC3100Sensor.h
00001 #ifndef STC3100Sensor_H_ 00002 #define STC3100Sensor_H_ 00003 00004 /** 00005 * I2C Device address 00006 * ------------------ 00007 * The mbed API uses 8 bit addresses, so make sure to thake the 7 bit address 00008 * and left shift it by 1 before passing it. 00009 * The eight bit presents a R/W bit, see datasheet STC3100 page 12. 00010 */ 00011 #define STC3100_ADDRESS_READ 0b11100000 00012 #define STC3100_ADRESS_WRITE 0b11100001 00013 00014 /** 00015 * INTERNAL REGISTER MAP 00016 * --------------------- 00017 * For this application the RAM registers are not used 00018 */ 00019 #define REG_MODE 0 // Mode register (R/W) 00020 #define REG_CTRL 1 // Control and status register (R/W) 00021 #define REG_CHARGE_LOW 2 // Gas gauge charge data, bits 0-7 (R) 00022 #define REG_CHARGE_HIGH 3 // Gas gauge charge data, bits 8-15 (R) 00023 #define REG_COUNTER_LOW 4 // Number of conversions, bits 0-7 (R) 00024 #define REG_COUNTER_HIGH 5 // Number of conversions, bits 8-15 (R) 00025 #define REG_CURRENT_LOW 6 // Battery current value, bits 0-7 (R) 00026 #define REG_CURRENT_HIGH 7 // Battery current value, bits 8-15 (R) 00027 #define REG_VOLTAGE_LOW 8 // Battery voltage value, bits 0-7 (R) 00028 #define REG_VOLTAGE_HIGH 9 // Battery voltage value, bits 8-15 (R) 00029 //#define REG_TEMPERATURE_LOW 10 // Temperature value, bits 0-7 (R) 00030 //#define REG_TEMPERATURE_HIGH 11 // Temperature value, bits 8-15 (R) 00031 00032 //The following registers are the Device ID registers (R) 00033 //#define REG_ID0 24 00034 //#define REG_ID1 25 00035 //#define REG_ID2 26 00036 //#define REG_ID3 27 00037 //#define REG_ID4 28 00038 //#define REG_ID5 29 00039 //#define REG_ID6 30 00040 //#define REG_ID7 31 00041 00042 typedef union STC3100Data { 00043 00044 // Reading of the chip will be stored in the byteArray 00045 unsigned char byteArray[10]; 00046 00047 struct { 00048 unsigned char Mode; 00049 unsigned char ControlStatus; 00050 unsigned char ChargeLow; 00051 unsigned char ChargeHigh; 00052 unsigned char CounterLow; 00053 unsigned char CounterHigh; 00054 unsigned char CurrentLow; 00055 unsigned char CurrentHigh; 00056 unsigned char VoltageLow; 00057 unsigned char VoltageHigh; 00058 // unsigned char TemperatureLow; 00059 // unsigned char TemperatureHigh; 00060 // unsigned char Reserved[13]; 00061 // unsigned char ID0; 00062 // unsigned char ID1; 00063 // unsigned char ID2; 00064 // unsigned char ID3; 00065 // unsigned char ID4; 00066 // unsigned char ID5; 00067 // unsigned char ID6; 00068 // unsigned char ID7; 00069 }; 00070 }; 00071 /** 00072 * Struct that stores the updated values. 00073 */ 00074 typedef struct STC3100ActualData { 00075 // Voltage in mV 00076 float voltage; 00077 // Current in mA 00078 float current; 00079 // Current charge of the battery mAh 00080 float charge; 00081 // // Temperature in °C 00082 // float temperature; 00083 }; 00084 00085 STC3100ActualData stc3100ActualData; 00086 STC3100Data stc3100Data; 00087 00088 void stc3100Configure(void); 00089 void stc3100ReadChip(void); 00090 void updateData(void); 00091 float getVoltage(void); 00092 float getCurrent(void); 00093 float getCharge(void); 00094 //float getTemperature(void); 00095 00096 #endif /* STC3100Sensor_H_ */
Generated on Sat Jul 16 2022 09:53:01 by
1.7.2