Custom project for driving a STC3100 sensor

Dependencies:   mbed

Fork of STC3100 by Levi Mariën

Committer:
tommienator
Date:
Sat Nov 04 13:07:17 2017 +0000
Revision:
1:dbc1e56be2cc
Parent:
0:014d4be7a437
stc3100

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tommienator 0:014d4be7a437 1 #ifndef STC3100Sensor_H_
tommienator 0:014d4be7a437 2 #define STC3100Sensor_H_
tommienator 0:014d4be7a437 3
tommienator 0:014d4be7a437 4 /**
tommienator 0:014d4be7a437 5 * I2C Device address
tommienator 0:014d4be7a437 6 * ------------------
tommienator 0:014d4be7a437 7 * The mbed API uses 8 bit addresses, so make sure to thake the 7 bit address
tommienator 0:014d4be7a437 8 * and left shift it by 1 before passing it.
tommienator 0:014d4be7a437 9 * The eight bit presents a R/W bit, see datasheet STC3100 page 12.
tommienator 0:014d4be7a437 10 */
tommienator 0:014d4be7a437 11 #define STC3100_ADDRESS_READ 0b11100000
tommienator 0:014d4be7a437 12 #define STC3100_ADRESS_WRITE 0b11100001
tommienator 0:014d4be7a437 13
tommienator 0:014d4be7a437 14 /**
tommienator 0:014d4be7a437 15 * INTERNAL REGISTER MAP
tommienator 0:014d4be7a437 16 * ---------------------
tommienator 0:014d4be7a437 17 * For this application the RAM registers are not used
tommienator 0:014d4be7a437 18 */
tommienator 0:014d4be7a437 19 #define REG_MODE 0 // Mode register (R/W)
tommienator 0:014d4be7a437 20 #define REG_CTRL 1 // Control and status register (R/W)
tommienator 0:014d4be7a437 21 #define REG_CHARGE_LOW 2 // Gas gauge charge data, bits 0-7 (R)
tommienator 0:014d4be7a437 22 #define REG_CHARGE_HIGH 3 // Gas gauge charge data, bits 8-15 (R)
tommienator 0:014d4be7a437 23 #define REG_COUNTER_LOW 4 // Number of conversions, bits 0-7 (R)
tommienator 0:014d4be7a437 24 #define REG_COUNTER_HIGH 5 // Number of conversions, bits 8-15 (R)
tommienator 0:014d4be7a437 25 #define REG_CURRENT_LOW 6 // Battery current value, bits 0-7 (R)
tommienator 0:014d4be7a437 26 #define REG_CURRENT_HIGH 7 // Battery current value, bits 8-15 (R)
tommienator 0:014d4be7a437 27 #define REG_VOLTAGE_LOW 8 // Battery voltage value, bits 0-7 (R)
tommienator 0:014d4be7a437 28 #define REG_VOLTAGE_HIGH 9 // Battery voltage value, bits 8-15 (R)
tommienator 0:014d4be7a437 29 //#define REG_TEMPERATURE_LOW 10 // Temperature value, bits 0-7 (R)
tommienator 0:014d4be7a437 30 //#define REG_TEMPERATURE_HIGH 11 // Temperature value, bits 8-15 (R)
tommienator 0:014d4be7a437 31
tommienator 0:014d4be7a437 32 //The following registers are the Device ID registers (R)
tommienator 0:014d4be7a437 33 //#define REG_ID0 24
tommienator 0:014d4be7a437 34 //#define REG_ID1 25
tommienator 0:014d4be7a437 35 //#define REG_ID2 26
tommienator 0:014d4be7a437 36 //#define REG_ID3 27
tommienator 0:014d4be7a437 37 //#define REG_ID4 28
tommienator 0:014d4be7a437 38 //#define REG_ID5 29
tommienator 0:014d4be7a437 39 //#define REG_ID6 30
tommienator 0:014d4be7a437 40 //#define REG_ID7 31
tommienator 0:014d4be7a437 41
tommienator 0:014d4be7a437 42 unsigned char Mode;
tommienator 0:014d4be7a437 43 unsigned char ControlStatus;
tommienator 0:014d4be7a437 44 unsigned char ChargeLow;
tommienator 0:014d4be7a437 45 unsigned char ChargeHigh;
tommienator 0:014d4be7a437 46 unsigned char CounterLow;
tommienator 0:014d4be7a437 47 unsigned char CounterHigh;
tommienator 0:014d4be7a437 48 unsigned char CurrentLow;
tommienator 0:014d4be7a437 49 unsigned char CurrentHigh;
tommienator 0:014d4be7a437 50 unsigned char VoltageLow;
tommienator 0:014d4be7a437 51 unsigned char VoltageHigh;
tommienator 0:014d4be7a437 52 // unsigned char TemperatureLow;
tommienator 0:014d4be7a437 53 // unsigned char TemperatureHigh;
tommienator 0:014d4be7a437 54 // unsigned char Reserved[13];
tommienator 0:014d4be7a437 55 // unsigned char ID0;
tommienator 0:014d4be7a437 56 // unsigned char ID1;
tommienator 0:014d4be7a437 57 // unsigned char ID2;
tommienator 0:014d4be7a437 58 // unsigned char ID3;
tommienator 0:014d4be7a437 59 // unsigned char ID4;
tommienator 0:014d4be7a437 60 // unsigned char ID5;
tommienator 0:014d4be7a437 61 // unsigned char ID6;
tommienator 0:014d4be7a437 62 // unsigned char ID7;
tommienator 1:dbc1e56be2cc 63
tommienator 0:014d4be7a437 64 /**
tommienator 0:014d4be7a437 65 * Struct that stores the updated values.
tommienator 0:014d4be7a437 66 */
tommienator 0:014d4be7a437 67 // Voltage in mV
tommienator 0:014d4be7a437 68 float voltage;
tommienator 0:014d4be7a437 69 // Current in mA
tommienator 0:014d4be7a437 70 float current;
tommienator 0:014d4be7a437 71 // Current charge of the battery mAh
tommienator 0:014d4be7a437 72 float charge;
tommienator 0:014d4be7a437 73 // // Temperature in °C
tommienator 0:014d4be7a437 74 // float temperature;
tommienator 0:014d4be7a437 75
tommienator 1:dbc1e56be2cc 76 //STC3100ActualData stc3100ActualData;
tommienator 1:dbc1e56be2cc 77 //STC3100Data stc3100Data;
tommienator 1:dbc1e56be2cc 78 // Reading of the chip will be stored in the byteArray
tommienator 1:dbc1e56be2cc 79 char byteArray[10];
tommienator 0:014d4be7a437 80
tommienator 0:014d4be7a437 81 void stc3100Configure(void);
tommienator 0:014d4be7a437 82 void stc3100ReadChip(void);
tommienator 0:014d4be7a437 83 void updateData(void);
tommienator 0:014d4be7a437 84 float getVoltage(void);
tommienator 0:014d4be7a437 85 float getCurrent(void);
tommienator 0:014d4be7a437 86 float getCharge(void);
tommienator 0:014d4be7a437 87 //float getTemperature(void);
tommienator 0:014d4be7a437 88
tommienator 0:014d4be7a437 89 #endif /* STC3100Sensor_H_ */