LTC2942 interface with interrupt and battery register calculations

Committer:
kaushalpkk
Date:
Thu Aug 08 18:00:00 2019 +0000
Revision:
1:547ec53dc37d
Parent:
0:f9e13080204a
dfgdfg

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kaushalpkk 0:f9e13080204a 1 #include "mbed.h"
kaushalpkk 0:f9e13080204a 2 #include "LTC294X.h"
kaushalpkk 0:f9e13080204a 3
kaushalpkk 0:f9e13080204a 4 LTC29421::LTC29421(PinName _a,PinName _b,PinName _c,void (*interruptFunc)()):
kaushalpkk 0:f9e13080204a 5 _i2c(_a, _b),_alcc(_c){
kaushalpkk 0:f9e13080204a 6
kaushalpkk 0:f9e13080204a 7 _i2c.frequency(400000);
kaushalpkk 0:f9e13080204a 8 _alcc.fall(interruptFunc);
kaushalpkk 0:f9e13080204a 9 _addr = 0xC8;
kaushalpkk 0:f9e13080204a 10 _battMax = 0x00;
kaushalpkk 0:f9e13080204a 11 _presc = 128;
kaushalpkk 0:f9e13080204a 12 DEBUG("WARNING! use setPrescAndBattCap() to set Battery Capacity\r\n");
kaushalpkk 0:f9e13080204a 13
kaushalpkk 0:f9e13080204a 14 }
kaushalpkk 0:f9e13080204a 15
kaushalpkk 0:f9e13080204a 16 LTC29421::LTC29421(PinName _a,PinName _b,PinName _c,void (*interruptFunc)(), float battCap):
kaushalpkk 0:f9e13080204a 17 _i2c(_a, _b),_alcc(_c){
kaushalpkk 0:f9e13080204a 18
kaushalpkk 0:f9e13080204a 19 _i2c.frequency(400000);
kaushalpkk 0:f9e13080204a 20 _alcc.fall(interruptFunc);
kaushalpkk 0:f9e13080204a 21 _addr = 0xC8;
kaushalpkk 0:f9e13080204a 22
kaushalpkk 0:f9e13080204a 23 setPrescAndBattCap(battCap);
kaushalpkk 0:f9e13080204a 24 }
kaushalpkk 0:f9e13080204a 25
kaushalpkk 0:f9e13080204a 26 void LTC29421::setPrescAndBattCap(float battcap){
kaushalpkk 0:f9e13080204a 27 _battCap = battcap;
kaushalpkk 0:f9e13080204a 28 float posM = (char)23*_battCap;
kaushalpkk 0:f9e13080204a 29 for(int i=0; i<8; i++){
kaushalpkk 0:f9e13080204a 30 if(pow(2,(float)i) >= posM){
kaushalpkk 0:f9e13080204a 31 _presc = pow(2,(float)i);
kaushalpkk 0:f9e13080204a 32 setPrescaler((int)_presc);
kaushalpkk 0:f9e13080204a 33 break;
kaushalpkk 0:f9e13080204a 34 }
kaushalpkk 0:f9e13080204a 35 }
kaushalpkk 0:f9e13080204a 36 DEBUG("Prescaler 'M' set to %d\r\n", (int)_presc);
kaushalpkk 0:f9e13080204a 37 _battMax = ((_battCap*1000)*128)/(_presc*0.085);
kaushalpkk 0:f9e13080204a 38 DEBUG("Battery capacity computed as %.2f Ah with bat max 0x%X \r\n", _battCap, (int)_battMax);
kaushalpkk 0:f9e13080204a 39 }
kaushalpkk 0:f9e13080204a 40
kaushalpkk 0:f9e13080204a 41
kaushalpkk 0:f9e13080204a 42 void LTC29421::setADCMode(int modeSel){
kaushalpkk 0:f9e13080204a 43 char ans = getControlReg();
kaushalpkk 0:f9e13080204a 44
kaushalpkk 0:f9e13080204a 45 switch(modeSel) {
kaushalpkk 0:f9e13080204a 46 case ADC_AUTO:
kaushalpkk 0:f9e13080204a 47 sbi(ans, ADC_VOLT_MODE);
kaushalpkk 0:f9e13080204a 48 sbi(ans, ADC_TEMP_MODE);
kaushalpkk 0:f9e13080204a 49 break;
kaushalpkk 0:f9e13080204a 50 case ADC_VOLT:
kaushalpkk 0:f9e13080204a 51 sbi(ans, ADC_VOLT_MODE);
kaushalpkk 0:f9e13080204a 52 cbi(ans, ADC_TEMP_MODE);
kaushalpkk 0:f9e13080204a 53 break;
kaushalpkk 0:f9e13080204a 54 case ADC_TEMP:
kaushalpkk 0:f9e13080204a 55 cbi(ans, ADC_VOLT_MODE);
kaushalpkk 0:f9e13080204a 56 sbi(ans, ADC_TEMP_MODE);
kaushalpkk 0:f9e13080204a 57 break;
kaushalpkk 0:f9e13080204a 58 case ADC_SLEEP:
kaushalpkk 0:f9e13080204a 59 cbi(ans, ADC_VOLT_MODE);
kaushalpkk 0:f9e13080204a 60 cbi(ans, ADC_TEMP_MODE);
kaushalpkk 0:f9e13080204a 61 break;
kaushalpkk 0:f9e13080204a 62 default:
kaushalpkk 0:f9e13080204a 63
kaushalpkk 0:f9e13080204a 64 break;
kaushalpkk 0:f9e13080204a 65 }
kaushalpkk 0:f9e13080204a 66 setControlReg(ans);
kaushalpkk 0:f9e13080204a 67 }
kaushalpkk 0:f9e13080204a 68
kaushalpkk 0:f9e13080204a 69 void LTC29421::setPrescaler(int val){
kaushalpkk 0:f9e13080204a 70 if(val <= 7) {
kaushalpkk 0:f9e13080204a 71 char ans = getControlReg();
kaushalpkk 0:f9e13080204a 72
kaushalpkk 0:f9e13080204a 73 if((val & 0x01) != 0) {
kaushalpkk 0:f9e13080204a 74 sbi(ans, PRESCALER_0);
kaushalpkk 0:f9e13080204a 75 } else {
kaushalpkk 0:f9e13080204a 76 cbi(ans, PRESCALER_0);
kaushalpkk 0:f9e13080204a 77 }
kaushalpkk 0:f9e13080204a 78 if((val & 0x02) != 0) {
kaushalpkk 0:f9e13080204a 79 sbi(ans, PRESCALER_1);
kaushalpkk 0:f9e13080204a 80 } else {
kaushalpkk 0:f9e13080204a 81 cbi(ans, PRESCALER_1);
kaushalpkk 0:f9e13080204a 82 }
kaushalpkk 0:f9e13080204a 83 if((val & 0x04) != 0) {
kaushalpkk 0:f9e13080204a 84 sbi(ans, PRESCALER_2);
kaushalpkk 0:f9e13080204a 85 } else {
kaushalpkk 0:f9e13080204a 86 cbi(ans, PRESCALER_2);
kaushalpkk 0:f9e13080204a 87 }
kaushalpkk 0:f9e13080204a 88 setControlReg(ans);
kaushalpkk 0:f9e13080204a 89
kaushalpkk 0:f9e13080204a 90 _presc = (float)getPrescaler();
kaushalpkk 0:f9e13080204a 91
kaushalpkk 0:f9e13080204a 92 } else {
kaushalpkk 0:f9e13080204a 93
kaushalpkk 0:f9e13080204a 94 }
kaushalpkk 0:f9e13080204a 95 }
kaushalpkk 0:f9e13080204a 96
kaushalpkk 0:f9e13080204a 97 int LTC29421::getPrescaler(){
kaushalpkk 0:f9e13080204a 98 char res = 0x00;
kaushalpkk 0:f9e13080204a 99 char ans = getControlReg();
kaushalpkk 0:f9e13080204a 100
kaushalpkk 0:f9e13080204a 101 if((ans & _BV(PRESCALER_0)) != 0) {
kaushalpkk 0:f9e13080204a 102 sbi(res, 0x00);
kaushalpkk 0:f9e13080204a 103 } else {
kaushalpkk 0:f9e13080204a 104 cbi(res, 0x00);
kaushalpkk 0:f9e13080204a 105 }
kaushalpkk 0:f9e13080204a 106 if((ans & _BV(PRESCALER_1)) != 0) {
kaushalpkk 0:f9e13080204a 107 sbi(res, 0x01);
kaushalpkk 0:f9e13080204a 108 } else {
kaushalpkk 0:f9e13080204a 109 cbi(res, 0x01);
kaushalpkk 0:f9e13080204a 110 }
kaushalpkk 0:f9e13080204a 111 if((ans & _BV(PRESCALER_2)) != 0) {
kaushalpkk 0:f9e13080204a 112 sbi(res, 0x02);
kaushalpkk 0:f9e13080204a 113 } else {
kaushalpkk 0:f9e13080204a 114 cbi(res, 0x02);
kaushalpkk 0:f9e13080204a 115 }
kaushalpkk 0:f9e13080204a 116 ans = getControlReg();
kaushalpkk 0:f9e13080204a 117 return (int)(pow(2,(float)ans));
kaushalpkk 0:f9e13080204a 118
kaushalpkk 0:f9e13080204a 119 }
kaushalpkk 0:f9e13080204a 120
kaushalpkk 0:f9e13080204a 121 void LTC29421::configALCC(int modeSel){
kaushalpkk 0:f9e13080204a 122 char ans = getControlReg();
kaushalpkk 0:f9e13080204a 123
kaushalpkk 0:f9e13080204a 124 switch(modeSel) {
kaushalpkk 0:f9e13080204a 125 case ALCC_ALERT:
kaushalpkk 0:f9e13080204a 126 sbi(ans, ALCC_ALERT_MODE);
kaushalpkk 0:f9e13080204a 127 cbi(ans, ALCC_CHRGC_MODE);
kaushalpkk 0:f9e13080204a 128 break;
kaushalpkk 0:f9e13080204a 129 case ALCC_CCOMP:
kaushalpkk 0:f9e13080204a 130 cbi(ans, ALCC_ALERT_MODE);
kaushalpkk 0:f9e13080204a 131 sbi(ans, ALCC_CHRGC_MODE);
kaushalpkk 0:f9e13080204a 132 break;
kaushalpkk 0:f9e13080204a 133 case ALCC_OFF:
kaushalpkk 0:f9e13080204a 134 cbi(ans, ALCC_ALERT_MODE);
kaushalpkk 0:f9e13080204a 135 cbi(ans, ALCC_CHRGC_MODE);
kaushalpkk 0:f9e13080204a 136 break;
kaushalpkk 0:f9e13080204a 137 default:
kaushalpkk 0:f9e13080204a 138
kaushalpkk 0:f9e13080204a 139 break;
kaushalpkk 0:f9e13080204a 140 }
kaushalpkk 0:f9e13080204a 141 setControlReg(ans);
kaushalpkk 0:f9e13080204a 142 }
kaushalpkk 0:f9e13080204a 143
kaushalpkk 0:f9e13080204a 144 void LTC29421::shutdown(){
kaushalpkk 0:f9e13080204a 145 char ans = 0x00;
kaushalpkk 0:f9e13080204a 146 ans = getControlReg();
kaushalpkk 0:f9e13080204a 147 sbi(ans,IC_SHUTDOWN);
kaushalpkk 0:f9e13080204a 148 setControlReg(ans);
kaushalpkk 0:f9e13080204a 149 }
kaushalpkk 0:f9e13080204a 150
kaushalpkk 0:f9e13080204a 151 void LTC29421::wake(){
kaushalpkk 0:f9e13080204a 152 char ans = 0x00;
kaushalpkk 0:f9e13080204a 153 ans = getControlReg();
kaushalpkk 0:f9e13080204a 154 cbi(ans,IC_SHUTDOWN);
kaushalpkk 0:f9e13080204a 155 setControlReg(ans);
kaushalpkk 0:f9e13080204a 156 }
kaushalpkk 0:f9e13080204a 157
kaushalpkk 0:f9e13080204a 158 int LTC29421::accumulatedChargeReg(){
kaushalpkk 0:f9e13080204a 159 char inn = ACC_MSB;
kaushalpkk 0:f9e13080204a 160 char outt[2];
kaushalpkk 1:547ec53dc37d 161 _i2c.write( _addr, &inn, 1 , true);
kaushalpkk 0:f9e13080204a 162 _i2c.read( _addr, outt, 2 );
kaushalpkk 0:f9e13080204a 163 int accChg = (int)outt[0];
kaushalpkk 0:f9e13080204a 164 accChg = (accChg*256)+ outt[1];
kaushalpkk 0:f9e13080204a 165 return accChg;
kaushalpkk 0:f9e13080204a 166 }
kaushalpkk 0:f9e13080204a 167
kaushalpkk 0:f9e13080204a 168 float LTC29421::accumulatedCharge(){
kaushalpkk 0:f9e13080204a 169 int reg = accumulatedChargeReg();
kaushalpkk 0:f9e13080204a 170 float res = ((float)accumulatedChargeReg()/_battMax)*100;
kaushalpkk 0:f9e13080204a 171 return res;
kaushalpkk 0:f9e13080204a 172 }
kaushalpkk 0:f9e13080204a 173
kaushalpkk 0:f9e13080204a 174 void LTC29421::accumulatedChargeReg(int inp){
kaushalpkk 0:f9e13080204a 175 shutdown();
kaushalpkk 0:f9e13080204a 176 char cmd[3];
kaushalpkk 0:f9e13080204a 177
kaushalpkk 0:f9e13080204a 178 cmd[0] = ACC_MSB;
kaushalpkk 0:f9e13080204a 179 cmd[1] = (0xFF00 & inp) >> 8;
kaushalpkk 0:f9e13080204a 180 cmd[2] = (0x00FF & inp);
kaushalpkk 0:f9e13080204a 181 _i2c.write(_addr, cmd, 3, true);
kaushalpkk 0:f9e13080204a 182 wake();
kaushalpkk 0:f9e13080204a 183 }
kaushalpkk 0:f9e13080204a 184
kaushalpkk 0:f9e13080204a 185 void LTC29421::accumulatedCharge(float inp){
kaushalpkk 0:f9e13080204a 186 inp = (inp/100)*_battMax;
kaushalpkk 0:f9e13080204a 187 accumulatedChargeReg(inp);
kaushalpkk 0:f9e13080204a 188 }
kaushalpkk 0:f9e13080204a 189
kaushalpkk 0:f9e13080204a 190 void LTC29421::setChargeThresholdLow(float prect){
kaushalpkk 0:f9e13080204a 191 char cmd[3];
kaushalpkk 0:f9e13080204a 192 prect = (prect/100)*_battMax;
kaushalpkk 0:f9e13080204a 193
kaushalpkk 0:f9e13080204a 194 cmd[0] = CHRG_THL_MSB;
kaushalpkk 0:f9e13080204a 195 cmd[1] = (0xFF00 & (int)prect) >> 8;
kaushalpkk 0:f9e13080204a 196 cmd[2] = (0x00FF & (int)prect);
kaushalpkk 0:f9e13080204a 197 _i2c.write(_addr, cmd, 2, true);
kaushalpkk 0:f9e13080204a 198 }
kaushalpkk 0:f9e13080204a 199
kaushalpkk 0:f9e13080204a 200 void LTC29421::setChargeThresholdHigh(float prect){
kaushalpkk 0:f9e13080204a 201 char cmd[3];
kaushalpkk 0:f9e13080204a 202 prect = (prect/100)*_battMax;
kaushalpkk 0:f9e13080204a 203
kaushalpkk 0:f9e13080204a 204 cmd[0] = CHRG_THH_MSB;
kaushalpkk 0:f9e13080204a 205 cmd[1] = (0xFF00 & (int)prect) >> 8;
kaushalpkk 0:f9e13080204a 206 cmd[2] = (0x00FF & (int)prect);
kaushalpkk 0:f9e13080204a 207 _i2c.write(_addr, cmd, 2, true);
kaushalpkk 0:f9e13080204a 208 }
kaushalpkk 0:f9e13080204a 209
kaushalpkk 0:f9e13080204a 210 float LTC29421::voltage(){
kaushalpkk 0:f9e13080204a 211 char inn = VOLT_MSB;
kaushalpkk 0:f9e13080204a 212 char outt[2];
kaushalpkk 0:f9e13080204a 213 _i2c.write( _addr, &inn, 1 ,true );
kaushalpkk 0:f9e13080204a 214 _i2c.read( _addr, outt, 2 );
kaushalpkk 0:f9e13080204a 215 int vtemp = (int)outt[0];
kaushalpkk 0:f9e13080204a 216 vtemp = (vtemp*256)+ outt[1];
kaushalpkk 0:f9e13080204a 217 float vol = 6 * ((float)vtemp / 65535);
kaushalpkk 0:f9e13080204a 218 return vol;
kaushalpkk 0:f9e13080204a 219 }
kaushalpkk 0:f9e13080204a 220
kaushalpkk 0:f9e13080204a 221 void LTC29421::setVoltageThresholdLow(float inp){
kaushalpkk 0:f9e13080204a 222 char cmd[2];
kaushalpkk 0:f9e13080204a 223 int ans = (int)(inp *65535)/6;
kaushalpkk 0:f9e13080204a 224 ans = ans >> 8;
kaushalpkk 0:f9e13080204a 225 cmd[0] = VOLT_THL;
kaushalpkk 0:f9e13080204a 226 cmd[1] = (char)ans;
kaushalpkk 0:f9e13080204a 227 _i2c.write(_addr, cmd, 2, true);
kaushalpkk 0:f9e13080204a 228 }
kaushalpkk 0:f9e13080204a 229
kaushalpkk 0:f9e13080204a 230 void LTC29421::setVoltageThresholdHigh(float inp){
kaushalpkk 0:f9e13080204a 231 char cmd[2];
kaushalpkk 0:f9e13080204a 232 int ans = (int)(inp *65535)/6;
kaushalpkk 0:f9e13080204a 233 ans = ans >> 8;
kaushalpkk 0:f9e13080204a 234 cmd[0] = VOLT_THH;
kaushalpkk 0:f9e13080204a 235 cmd[1] = (char)ans;
kaushalpkk 0:f9e13080204a 236 _i2c.write(_addr, cmd, 2, true);
kaushalpkk 0:f9e13080204a 237 }
kaushalpkk 0:f9e13080204a 238
kaushalpkk 0:f9e13080204a 239
kaushalpkk 0:f9e13080204a 240 float LTC29421::temperature(){
kaushalpkk 0:f9e13080204a 241 char inn = TEMP_MSB;
kaushalpkk 0:f9e13080204a 242 char outt[2];
kaushalpkk 0:f9e13080204a 243 _i2c.write( _addr, &inn, 1 ,true );
kaushalpkk 0:f9e13080204a 244 _i2c.read( _addr, outt, 2 );
kaushalpkk 0:f9e13080204a 245 int ttemp = (int)outt[0];
kaushalpkk 0:f9e13080204a 246 ttemp = (ttemp*256)+ outt[1];
kaushalpkk 0:f9e13080204a 247 float tempp = (600 * ((float)ttemp / 65535)) - 273.15;
kaushalpkk 0:f9e13080204a 248 return tempp;
kaushalpkk 0:f9e13080204a 249 }
kaushalpkk 0:f9e13080204a 250
kaushalpkk 0:f9e13080204a 251 void LTC29421::setTemperatureThresholdLow(float inp){
kaushalpkk 0:f9e13080204a 252 int ans = (int)(((inp+273.15)*65535)/600);
kaushalpkk 0:f9e13080204a 253 ans = ans >> 8;
kaushalpkk 0:f9e13080204a 254 char cmd[2];
kaushalpkk 0:f9e13080204a 255 cmd[0] = TEMPERATURE_THL;
kaushalpkk 0:f9e13080204a 256 cmd[1] = ans;
kaushalpkk 0:f9e13080204a 257 _i2c.write(_addr, cmd, 2, true);
kaushalpkk 0:f9e13080204a 258 }
kaushalpkk 0:f9e13080204a 259
kaushalpkk 0:f9e13080204a 260 void LTC29421::setTemperatureThresholdHigh(float inp){
kaushalpkk 0:f9e13080204a 261 int ans = (int)(((inp+273.15)*65535)/600);
kaushalpkk 0:f9e13080204a 262 ans = ans >> 8;
kaushalpkk 0:f9e13080204a 263 char cmd[2];
kaushalpkk 0:f9e13080204a 264 cmd[0] = TEMPERATURE_THH;
kaushalpkk 0:f9e13080204a 265 cmd[1] = ans;
kaushalpkk 0:f9e13080204a 266 _i2c.write(_addr, cmd, 2, true);
kaushalpkk 0:f9e13080204a 267 }
kaushalpkk 0:f9e13080204a 268
kaushalpkk 0:f9e13080204a 269 void LTC29421::readAll(){
kaushalpkk 0:f9e13080204a 270 char cmd[16];
kaushalpkk 0:f9e13080204a 271 cmd[0] = REG_STATUS;
kaushalpkk 0:f9e13080204a 272 _i2c.write(_addr, cmd, 1, true);
kaushalpkk 0:f9e13080204a 273 _i2c.read(_addr, cmd, 16); // read the two-byte echo result
kaushalpkk 0:f9e13080204a 274 DEBUG("===================================================\r\n");
kaushalpkk 0:f9e13080204a 275 DEBUG("REG_STATUS [%X] \r\n",cmd[REG_STATUS]);
kaushalpkk 0:f9e13080204a 276 DEBUG("REG_CONTROL [%X] \r\n",cmd[REG_CONTROL]);
kaushalpkk 0:f9e13080204a 277 DEBUG("ACC_CHARGE [%X %X] \r\n",cmd[ACC_MSB],cmd[ACC_LSB]);
kaushalpkk 0:f9e13080204a 278 DEBUG("CHRG_THH [%X %X] \r\n",cmd[CHRG_THH_MSB],cmd[CHRG_THH_LSB]);
kaushalpkk 0:f9e13080204a 279 DEBUG("CHRG_THL [%X %X] \r\n",cmd[CHRG_THL_MSB],cmd[CHRG_THL_LSB]);
kaushalpkk 0:f9e13080204a 280 DEBUG("VOLTAGE [%X %X] \r\n",cmd[VOLT_MSB],cmd[VOLT_LSB]);
kaushalpkk 0:f9e13080204a 281 DEBUG("VOLT_THH [%X] \r\n",cmd[VOLT_THH]);
kaushalpkk 0:f9e13080204a 282 DEBUG("VOLT_THL [%X] \r\n",cmd[VOLT_THL]);
kaushalpkk 0:f9e13080204a 283 DEBUG("TEMPERATURE [%X %X] \r\n",cmd[TEMP_MSB],cmd[TEMP_LSB]);
kaushalpkk 0:f9e13080204a 284 DEBUG("TEMPERATURE_THH [%X] \r\n",cmd[TEMPERATURE_THH]);
kaushalpkk 0:f9e13080204a 285 DEBUG("TEMPERATURE_THL [%X] \r\n",cmd[TEMPERATURE_THL]);
kaushalpkk 0:f9e13080204a 286 DEBUG("===================================================\r\n");
kaushalpkk 0:f9e13080204a 287 DEBUG("\r\n");
kaushalpkk 0:f9e13080204a 288 }
kaushalpkk 0:f9e13080204a 289
kaushalpkk 0:f9e13080204a 290 int LTC29421::alertResponse(){
kaushalpkk 0:f9e13080204a 291 char reg = getStatusReg();
kaushalpkk 0:f9e13080204a 292 char ans;
kaushalpkk 0:f9e13080204a 293 char cmd= 0x19;
kaushalpkk 0:f9e13080204a 294 _i2c.read(cmd, &ans, 1);
kaushalpkk 0:f9e13080204a 295 if(ans == 0xC8){
kaushalpkk 0:f9e13080204a 296 DEBUG("alert = %x, reg = %x\r\n", ans,reg);
kaushalpkk 0:f9e13080204a 297 return reg;
kaushalpkk 0:f9e13080204a 298 }else
kaushalpkk 0:f9e13080204a 299 return -1;
kaushalpkk 0:f9e13080204a 300 }
kaushalpkk 0:f9e13080204a 301
kaushalpkk 0:f9e13080204a 302 char LTC29421::getControlReg()
kaushalpkk 0:f9e13080204a 303 {
kaushalpkk 0:f9e13080204a 304 char cmd;
kaushalpkk 0:f9e13080204a 305 char ans;
kaushalpkk 0:f9e13080204a 306 cmd= REG_CONTROL;
kaushalpkk 0:f9e13080204a 307 _i2c.write(_addr, &cmd, 1, true);
kaushalpkk 0:f9e13080204a 308 _i2c.read(_addr, &ans, 1);
kaushalpkk 0:f9e13080204a 309
kaushalpkk 0:f9e13080204a 310 return ans;
kaushalpkk 0:f9e13080204a 311 }
kaushalpkk 0:f9e13080204a 312
kaushalpkk 0:f9e13080204a 313 char LTC29421::getStatusReg()
kaushalpkk 0:f9e13080204a 314 {
kaushalpkk 0:f9e13080204a 315 char cmd;
kaushalpkk 0:f9e13080204a 316 char ans;
kaushalpkk 0:f9e13080204a 317 cmd= REG_STATUS;
kaushalpkk 0:f9e13080204a 318 _i2c.write(_addr, &cmd, 1, true);
kaushalpkk 0:f9e13080204a 319 _i2c.read(_addr, &ans, 1);
kaushalpkk 0:f9e13080204a 320
kaushalpkk 0:f9e13080204a 321 return ans;
kaushalpkk 0:f9e13080204a 322 }
kaushalpkk 0:f9e13080204a 323
kaushalpkk 0:f9e13080204a 324 void LTC29421::setControlReg(char inp)
kaushalpkk 0:f9e13080204a 325 {
kaushalpkk 0:f9e13080204a 326 char cmd[2];
kaushalpkk 0:f9e13080204a 327 cmd[0] = REG_CONTROL;
kaushalpkk 0:f9e13080204a 328 cmd[1] = inp;
kaushalpkk 0:f9e13080204a 329 _i2c.write(_addr, cmd, 2, true);
kaushalpkk 0:f9e13080204a 330 }