Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
LTC2947.h
Go to the documentation of this file.
1 /*!
2 LTC2947: LTC2947 a high-precision power and energy monitor with an internal sense resistor supporting up to 30A.
3 
4 @verbatim
5 
6 The LTC2947 is a high-precision power and energy
7 monitor with an internal sense resistor supporting up
8 to 30A. Three internal No Latency delta sigma ADCs ensure
9 accurate measurement of voltage and current, while high-
10 bandwidth analog multiplication of voltage and current
11 provides accurate power measurement in a wide range of
12 applications. Internal or external clocking options enable
13 precise charge and energy measurements.
14 An internal 300 micro ohms, temperature-compensated sense
15 resistor minimizes efficiency loss and external compo-
16 nents, simplifying energy measurement applications while
17 enabling high accuracy current measurement over the full
18 temperature range. For more details see following URLs:
19 
20 @endverbatim
21 
22 
23 http://www.linear.com/product/LTC2947
24 
25 http://www.linear.com/product/LTC2947#demoboards
26 
27 
28 Copyright 2018(c) Analog Devices, Inc.
29 
30 All rights reserved.
31 
32 Redistribution and use in source and binary forms, with or without
33 modification, are permitted provided that the following conditions are met:
34  - Redistributions of source code must retain the above copyright
35  notice, this list of conditions and the following disclaimer.
36  - Redistributions in binary form must reproduce the above copyright
37  notice, this list of conditions and the following disclaimer in
38  the documentation and/or other materials provided with the
39  distribution.
40  - Neither the name of Analog Devices, Inc. nor the names of its
41  contributors may be used to endorse or promote products derived
42  from this software without specific prior written permission.
43  - The use of this software may or may not infringe the patent rights
44  of one or more patent holders. This license does not release you
45  from the requirement that you obtain separate licenses from these
46  patent holders to use this software.
47  - Use of the software either in source or binary form, must be run
48  on or directly connected to an Analog Devices Inc. component.
49 
50 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
51 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
52 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
53 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
54 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
55 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
56 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
57 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
58 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
59 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60 */
61 
62 
63 /*! @file
64  @ingroup LTC2947
65  Header for LTC2947 a high-precision power and energy monitor with an internal sense resistor supporting up to 30A.
66 */
67 
68 #ifndef LTC2947_H
69 #define LTC2947_H
70 
71 #undef LTC2947_DEBUG
72 
73 #include "arduino.h"
74 
75 #define bitMaskSetChk(value, bitMask) (((value) & (bitMask)) == (bitMask))
76 #define bitMaskClrChk(value, bitMask) (((value) & (bitMask)) == 0)
77 
78 #define bitMaskSet(value, bitMask) (value |= (bitMask))
79 #define bitMaskClr(value, bitMask) (value &= ~(bitMask))
80 
81 #define bitMaskSetClr(value, bitMask, setNotClr) ((setNotClr) ? bitMaskSet(value,bitMask) : bitMaskClr(value,bitMask))
82 
83 #define LOG_1(n) (((n) >= 2) ? 1 : 0)
84 #define LOG_2(n) (((n) >= 1<<2) ? (2 + LOG_1((n)>>2)) : LOG_1(n))
85 #define LOG_4(n) (((n) >= 1<<4) ? (4 + LOG_2((n)>>4)) : LOG_2(n))
86 #define LOG_8(n) (((n) >= 1<<8) ? (8 + LOG_4((n)>>8)) : LOG_4(n))
87 #define LOG(n) (((n) >= 1<<16) ? (16 + LOG_8((n)>>16)) : LOG_8(n))
88 
89 
90 // used to convert any bitmask like LTC2947_BM_TBCTL_DIV_0
91 // to its bit position index to be used for shift operations
92 // BM2BITPOS(LTC2947_BM_TBCTL_DIV_0) = BM2BITPOS(0x8) = BM2BITPOS(1<<3) = 3
93 #define BM2BITPOS(bm) ((bm)&1<<7 ? 7 : \
94  (bm)&1<<6 ? 6 : \
95  (bm)&1<<5 ? 5 : \
96  (bm)&1<<4 ? 4 : \
97  (bm)&1<<3 ? 3 : \
98  (bm)&1<<2 ? 2 : \
99  (bm)&1<<1 ? 1 : 0)
100 
101 
102 #define LTC2947_I2C_ADDR_LL 0x5C // AD0=L, AD1=L (default)
103 #define LTC2947_I2C_ADDR_LH 0x5D // AD0=L, AD1=H
104 #define LTC2947_I2C_ADDR_LR 0x5E // AD0=L, AD1=R
105 #define LTC2947_I2C_ADDR_RL 0x64 // AD0=R, AD1=L
106 #define LTC2947_I2C_ADDR_RH 0x65 // AD0=R, AD1=H
107 #define LTC2947_I2C_ADDR_RR 0x66 // AD0=R, AD1=R
108 
109 
110 #define LTC2947_SPI_READ_CMD 0x01
111 #define LTC2947_SPI_WRITE_CMD 0x00
112 
113 #define LTC2947_LSB_FACTOR_MILLI_HOURS (1.0 / 60.0 / 60.0 / 1.0e-3)
114 #define LTC2947_LSB_FACTOR_HOURS (1.0 / 60.0 / 60.0)
115 
116 #ifndef LTC2947_CS
117 #define LTC2947_CS QUIKEVAL_CS
118 #endif
119 
120 /**
121 \brief defines ltc 2947 extclk.
122 PRE, DIV, ext. oscillator setting:
123 Before include of LTC2947.h you may
124 1. define LTC2947_EXTCLK only to specify your external oscillator / crystal
125 frequency
126 
127 2. not define anything. In this case the internal oscillator will be used (PRE = 7, DIV = 0)
128 #undef LTC2947_EXTCLK // internal oscillator, so no external clock frequency
129 #undef LTC2947_PRE // will be defined for internal oscillator by LTC2947.h
130 #undef LTC2947_DIV // will be defined for internal oscillator by LTC2947.h
131 
132 3. define full set of PRE, DIV and EXTCLK
133 #define LTC2947_PRE 2 // LTC2947.h will use those definitions to calc LSB calues
134 #define LTC2947_DIV 30 // LTC2947.h will use those definitions to calc LSB calues
135 #define LTC2947_EXTCLK 4e6 // LTC2947.h will use those definitions to calc LSB calues
136 
137 In all cases after loading the header file you can
138 1. Use LTC2947_PRE, LTC2947_DIV to write to LTC2947_REG_TBCTL see below.
139 2. Use LSB definitions like LTC2947_LSB_TB1 to calculate real values out of integers
140 
141 Note: All LSBs are calculated as a function of PRE, DIV and EXTCLK by
142 pre-processor macros within LTC2947.h
143 
144 \param must be 4MHz in case of crystal operation,
145 or 0.2 to 25 MHz in case of external oscillator
146 */
147 #define LTC2947_EXTCLK 4e6 // external frequency on CLKI pin (must be 4MHz in case of crystal)
148 #undef LTC2947_PRE // will be calculated and defined by LTC2947.h
149 #undef LTC2947_DIV // will be calculated and defined by LTC2947.h
150 
151 
152 /** @name LTC2947 auto generated code
153 * This code is automatically generated by the LTC2947's GUI, see Tools menu of the GUI
154 * @{
155 */
156 
157 /////////////////////////////////////////////////////////
158 // Definitions of available registers without those //
159 // that are part of multiple byte values //
160 // (e.g. accumulators). //
161 // //
162 // Note: The address constants are 9 bit values where //
163 // the lower 8 bit define the address and the 9th bit //
164 // defines the page! //
165 /////////////////////////////////////////////////////////
166 
167 // GPIO status and control (register on page 0)
168 #define LTC2947_REG_GPIOSTATCL 0x067
169 
170 // Status register (active high) (register on page 0)
171 #define LTC2947_REG_STATUS 0x080
172 
173 // Voltage, Temperature Threshold Alerts (register on page 0)
174 #define LTC2947_REG_STATVT 0x081
175 
176 // Current Power Threshold Alerts (register on page 0)
177 #define LTC2947_REG_STATIP 0x082
178 
179 // Charge Threshold Alerts (register on page 0)
180 #define LTC2947_REG_STATC 0x083
181 
182 // Energy Threshold Alerts (register on page 0)
183 #define LTC2947_REG_STATE 0x084
184 
185 // Charge, Energy Overflow Alerts (register on page 0)
186 #define LTC2947_REG_STATCEOF 0x085
187 
188 // Time Base Alerts (register on page 0)
189 #define LTC2947_REG_STATTB 0x086
190 
191 // DVCC threshold alerts (register on page 0)
192 #define LTC2947_REG_STATVDVCC 0x087
193 
194 // STATUS mask register (1: alert from STATUS is disabled) (register on page 0)
195 #define LTC2947_REG_STATUSM 0x088
196 
197 // STATVT mask register (1: alert from STATVT is disabled) (register on page 0)
198 #define LTC2947_REG_STATVTM 0x089
199 
200 // STATIP mask register (1: alert from STATIP is disabled) (register on page 0)
201 #define LTC2947_REG_STATIPM 0x08A
202 
203 // STATC mask register (1: alert from STATC is disabled) (register on page 0)
204 #define LTC2947_REG_STATCM 0x08B
205 
206 // STATE mask register (1: alert from STATE is disabled) (register on page 0)
207 #define LTC2947_REG_STATEM 0x08C
208 
209 // STATCEOF mask register (1: alert from STATCEOF is disabled) (register on page 0)
210 #define LTC2947_REG_STATCEOFM 0x08D
211 
212 // STATTB mask register (1: alert from STATTB is disabled) (register on page 0)
213 #define LTC2947_REG_STATTBM 0x08E
214 
215 // STATVDVCC mask register (1: alert from STATVDVCC is disabled) (register on page 0)
216 #define LTC2947_REG_STATVDVCCM 0x08F
217 
218 // Accumulation control of Charge1/2 and Energy1/2 by current polarity.
219 // 00: Accumulation takes place always,
220 // 01: only if the current is positive,
221 // 10: only if the current is negative,
222 // 11: No accumulation takes place. (register on page 0)
223 #define LTC2947_REG_ACCICTL 0x0E1
224 
225 // Accumulation control of Charge1/2, Energy1/2 and TB1/2 by pin GPIO.
226 // 00: Accumulation takes place always,
227 // 01: only if pin GPIO is 1,
228 // 10: only if pin GPIO is 0,
229 // 11: RESERVED (register on page 0)
230 #define LTC2947_REG_ACCGPCTL 0x0E3
231 
232 // Deadband current for accumulation
233 // If the absolute current value is higher than or equal this value, accumulation of Charge1/Charge2 and Energy1/Energy2 and comparison to their respective threshold takes place. If lower, Charge1/Charge2 and Energy1/Energy2 values are not accumulated and there is no comparison against thresholds. (register on page 0)
234 #define LTC2947_REG_ACCIDB 0x0E4
235 
236 // Alert Master Control Enable (register on page 0)
237 #define LTC2947_REG_ALERTBCTL 0x0E8
238 
239 // Time Base Control (register on page 0)
240 #define LTC2947_REG_TBCTL 0x0E9
241 
242 // Operation Control (register on page 0)
243 #define LTC2947_REG_OPCTL 0x0F0
244 
245 // Page Control Register (register on page 0)
246 #define LTC2947_REG_PGCTL 0x0FF
247 
248 /////////////////////////////////////////////////////////
249 // Definitions of all byte addresses of all multiple //
250 // byte values (e.g. accumulators). //
251 // //
252 // Note: The address constants are 9 bit values where //
253 // the lower 8 bit define the address and the 9th bit //
254 // defines the page! //
255 /////////////////////////////////////////////////////////
256 
257 // Charge1 (register on page 0)
258 #define LTC2947_REG_C1_47_40 0x000
259 
260 // (register on page 0)
261 #define LTC2947_REG_C1_39_32 0x001
262 
263 // (register on page 0)
264 #define LTC2947_REG_C1_31_24 0x002
265 
266 // (register on page 0)
267 #define LTC2947_REG_C1_23_16 0x003
268 
269 // (register on page 0)
270 #define LTC2947_REG_C1_15_8 0x004
271 
272 // (register on page 0)
273 #define LTC2947_REG_C1_7_0 0x005
274 
275 // Energy1 (register on page 0)
276 #define LTC2947_REG_E1_47_40 0x006
277 
278 // (register on page 0)
279 #define LTC2947_REG_E1_39_32 0x007
280 
281 // (register on page 0)
282 #define LTC2947_REG_E1_31_24 0x008
283 
284 // (register on page 0)
285 #define LTC2947_REG_E1_23_16 0x009
286 
287 // (register on page 0)
288 #define LTC2947_REG_E1_15_8 0x00A
289 
290 // (register on page 0)
291 #define LTC2947_REG_E1_7_0 0x00B
292 
293 // Time1 (register on page 0)
294 #define LTC2947_REG_TB1_31_24 0x00C
295 
296 // (register on page 0)
297 #define LTC2947_REG_TB1_23_16 0x00D
298 
299 // (register on page 0)
300 #define LTC2947_REG_TB1_15_8 0x00E
301 
302 // (register on page 0)
303 #define LTC2947_REG_TB1_7_0 0x00F
304 
305 // Charge2 (register on page 0)
306 #define LTC2947_REG_C2_47_40 0x010
307 
308 // (register on page 0)
309 #define LTC2947_REG_C2_39_32 0x011
310 
311 // (register on page 0)
312 #define LTC2947_REG_C2_31_24 0x012
313 
314 // (register on page 0)
315 #define LTC2947_REG_C2_23_16 0x013
316 
317 // (register on page 0)
318 #define LTC2947_REG_C2_15_8 0x014
319 
320 // (register on page 0)
321 #define LTC2947_REG_C2_7_0 0x015
322 
323 // Energy2 (register on page 0)
324 #define LTC2947_REG_E2_47_40 0x016
325 
326 // (register on page 0)
327 #define LTC2947_REG_E2_39_32 0x017
328 
329 // (register on page 0)
330 #define LTC2947_REG_E2_31_24 0x018
331 
332 // (register on page 0)
333 #define LTC2947_REG_E2_23_16 0x019
334 
335 // (register on page 0)
336 #define LTC2947_REG_E2_15_8 0x01A
337 
338 // (register on page 0)
339 #define LTC2947_REG_E2_7_0 0x01B
340 
341 // Time2 (register on page 0)
342 #define LTC2947_REG_TB2_31_24 0x01C
343 
344 // (register on page 0)
345 #define LTC2947_REG_TB2_23_16 0x01D
346 
347 // (register on page 0)
348 #define LTC2947_REG_TB2_15_8 0x01E
349 
350 // (register on page 0)
351 #define LTC2947_REG_TB2_7_0 0x01F
352 
353 // Maximum current tracking (register on page 0)
354 #define LTC2947_REG_IMAX_15_8 0x040
355 
356 // (register on page 0)
357 #define LTC2947_REG_IMAX_7_0 0x041
358 
359 // Minimum Current tracking (register on page 0)
360 #define LTC2947_REG_IMIN_15_8 0x042
361 
362 // (register on page 0)
363 #define LTC2947_REG_IMIN_7_0 0x043
364 
365 // Maximum Power tracking (register on page 0)
366 #define LTC2947_REG_PMAX_15_8 0x044
367 
368 // (register on page 0)
369 #define LTC2947_REG_PMAX_7_0 0x045
370 
371 // Minimum Power tracking (register on page 0)
372 #define LTC2947_REG_PMIN_15_8 0x046
373 
374 // (register on page 0)
375 #define LTC2947_REG_PMIN_7_0 0x047
376 
377 // Maximum Voltage (VD = VP - VM) tracking (register on page 0)
378 #define LTC2947_REG_VMAX_15_8 0x050
379 
380 // (register on page 0)
381 #define LTC2947_REG_VMAX_7_0 0x051
382 
383 // Minimum Voltage (VD = VP - VM) tracking (register on page 0)
384 #define LTC2947_REG_VMIN_15_8 0x052
385 
386 // (register on page 0)
387 #define LTC2947_REG_VMIN_7_0 0x053
388 
389 // Maximum Temperature tracking (register on page 0)
390 #define LTC2947_REG_TEMPMAX_15_8 0x054
391 
392 // (register on page 0)
393 #define LTC2947_REG_TEMPMAX_7_0 0x055
394 
395 // Minimum Temperature tracking (register on page 0)
396 #define LTC2947_REG_TEMPMIN_15_8 0x056
397 
398 // (register on page 0)
399 #define LTC2947_REG_TEMPMIN_7_0 0x057
400 
401 // Maximum Voltage at DVCC tracking (register on page 0)
402 #define LTC2947_REG_VDVCCMAX_15_8 0x058
403 
404 // (register on page 0)
405 #define LTC2947_REG_VDVCCMAX_7_0 0x059
406 
407 // Minimum Voltage at DVCC tracking (register on page 0)
408 #define LTC2947_REG_VDVCCMIN_15_8 0x05A
409 
410 // (register on page 0)
411 #define LTC2947_REG_VDVCCMIN_7_0 0x05B
412 
413 // Current (register on page 0)
414 #define LTC2947_REG_I_23_16 0x090
415 
416 // (register on page 0)
417 #define LTC2947_REG_I_15_8 0x091
418 
419 // (register on page 0)
420 #define LTC2947_REG_I_7_0 0x092
421 
422 // Power (register on page 0)
423 #define LTC2947_REG_P_23_16 0x093
424 
425 // (register on page 0)
426 #define LTC2947_REG_P_15_8 0x094
427 
428 // (register on page 0)
429 #define LTC2947_REG_P_7_0 0x095
430 
431 // Voltage (VD = VP - VM) (register on page 0)
432 #define LTC2947_REG_V_15_8 0x0A0
433 
434 // (register on page 0)
435 #define LTC2947_REG_V_7_0 0x0A1
436 
437 // Temperature (register on page 0)
438 #define LTC2947_REG_TEMP_15_8 0x0A2
439 
440 // (register on page 0)
441 #define LTC2947_REG_TEMP_7_0 0x0A3
442 
443 // Voltage at DVCC (register on page 0)
444 #define LTC2947_REG_VDVCC_15_8 0x0A4
445 
446 // (register on page 0)
447 #define LTC2947_REG_VDVCC_7_0 0x0A5
448 
449 // Current History 1 (prev. result) (register on page 0)
450 #define LTC2947_REG_IH1_23_16 0x0B0
451 
452 // (register on page 0)
453 #define LTC2947_REG_IH1_15_8 0x0B1
454 
455 // (register on page 0)
456 #define LTC2947_REG_IH1_7_0 0x0B2
457 
458 // Current History 2 (prev. result '-1') (register on page 0)
459 #define LTC2947_REG_IH2_23_16 0x0B3
460 
461 // (register on page 0)
462 #define LTC2947_REG_IH2_15_8 0x0B4
463 
464 // (register on page 0)
465 #define LTC2947_REG_IH2_7_0 0x0B5
466 
467 // Current History 3 (prev. result '-2') (register on page 0)
468 #define LTC2947_REG_IH3_23_16 0x0B6
469 
470 // (register on page 0)
471 #define LTC2947_REG_IH3_15_8 0x0B7
472 
473 // (register on page 0)
474 #define LTC2947_REG_IH3_7_0 0x0B8
475 
476 // Current History 4 (prev. result '-3') (register on page 0)
477 #define LTC2947_REG_IH4_23_16 0x0B9
478 
479 // (register on page 0)
480 #define LTC2947_REG_IH4_15_8 0x0BA
481 
482 // (register on page 0)
483 #define LTC2947_REG_IH4_7_0 0x0BB
484 
485 // Current History 5 (prev. result '-4') (register on page 0)
486 #define LTC2947_REG_IH5_23_16 0x0BC
487 
488 // (register on page 0)
489 #define LTC2947_REG_IH5_15_8 0x0BD
490 
491 // (register on page 0)
492 #define LTC2947_REG_IH5_7_0 0x0BE
493 
494 // Charge 1 threshold high (register on page 1)
495 #define LTC2947_REG_C1TH_47_40 0x100
496 
497 // (register on page 1)
498 #define LTC2947_REG_C1TH_39_32 0x101
499 
500 // (register on page 1)
501 #define LTC2947_REG_C1TH_31_24 0x102
502 
503 // (register on page 1)
504 #define LTC2947_REG_C1TH_23_16 0x103
505 
506 // (register on page 1)
507 #define LTC2947_REG_C1TH_15_8 0x104
508 
509 // (register on page 1)
510 #define LTC2947_REG_C1TH_7_0 0x105
511 
512 // Charge 1 threshold low (register on page 1)
513 #define LTC2947_REG_C1TL_47_40 0x106
514 
515 // (register on page 1)
516 #define LTC2947_REG_C1TL_39_32 0x107
517 
518 // (register on page 1)
519 #define LTC2947_REG_C1TL_31_24 0x108
520 
521 // (register on page 1)
522 #define LTC2947_REG_C1TL_23_16 0x109
523 
524 // (register on page 1)
525 #define LTC2947_REG_C1TL_15_8 0x10A
526 
527 // (register on page 1)
528 #define LTC2947_REG_C1TL_7_0 0x10B
529 
530 // Time Base 1 threshold high (register on page 1)
531 #define LTC2947_REG_TB1TH_31_24 0x10C
532 
533 // (register on page 1)
534 #define LTC2947_REG_TB1TH_23_16 0x10D
535 
536 // (register on page 1)
537 #define LTC2947_REG_TB1TH_15_8 0x10E
538 
539 // (register on page 1)
540 #define LTC2947_REG_TB1TH_7_0 0x10F
541 
542 // Energy 1 threshold high (register on page 1)
543 #define LTC2947_REG_E1TH_47_40 0x110
544 
545 // (register on page 1)
546 #define LTC2947_REG_E1TH_39_32 0x111
547 
548 // (register on page 1)
549 #define LTC2947_REG_E1TH_31_24 0x112
550 
551 // (register on page 1)
552 #define LTC2947_REG_E1TH_23_16 0x113
553 
554 // (register on page 1)
555 #define LTC2947_REG_E1TH_15_8 0x114
556 
557 // (register on page 1)
558 #define LTC2947_REG_E1TH_7_0 0x115
559 
560 // Energy 1 threshold low (register on page 1)
561 #define LTC2947_REG_E1TL_47_40 0x116
562 
563 // (register on page 1)
564 #define LTC2947_REG_E1TL_39_32 0x117
565 
566 // (register on page 1)
567 #define LTC2947_REG_E1TL_31_24 0x118
568 
569 // (register on page 1)
570 #define LTC2947_REG_E1TL_23_16 0x119
571 
572 // (register on page 1)
573 #define LTC2947_REG_E1TL_15_8 0x11A
574 
575 // (register on page 1)
576 #define LTC2947_REG_E1TL_7_0 0x11B
577 
578 // Charge 2 threshold high (register on page 1)
579 #define LTC2947_REG_C2TH_47_40 0x120
580 
581 // (register on page 1)
582 #define LTC2947_REG_C2TH_39_32 0x121
583 
584 // (register on page 1)
585 #define LTC2947_REG_C2TH_31_24 0x122
586 
587 // (register on page 1)
588 #define LTC2947_REG_C2TH_23_16 0x123
589 
590 // (register on page 1)
591 #define LTC2947_REG_C2TH_15_8 0x124
592 
593 // (register on page 1)
594 #define LTC2947_REG_C2TH_7_0 0x125
595 
596 // Charge 2 threshold low (register on page 1)
597 #define LTC2947_REG_C2TL_47_40 0x126
598 
599 // (register on page 1)
600 #define LTC2947_REG_C2TL_39_32 0x127
601 
602 // (register on page 1)
603 #define LTC2947_REG_C2TL_31_24 0x128
604 
605 // (register on page 1)
606 #define LTC2947_REG_C2TL_23_16 0x129
607 
608 // (register on page 1)
609 #define LTC2947_REG_C2TL_15_8 0x12A
610 
611 // (register on page 1)
612 #define LTC2947_REG_C2TL_7_0 0x12B
613 
614 // Time Base 2 threshold high (register on page 1)
615 #define LTC2947_REG_TB2TH_31_24 0x12C
616 
617 // (register on page 1)
618 #define LTC2947_REG_TB2TH_23_16 0x12D
619 
620 // (register on page 1)
621 #define LTC2947_REG_TB2TH_15_8 0x12E
622 
623 // (register on page 1)
624 #define LTC2947_REG_TB2TH_7_0 0x12F
625 
626 // Energy 2 threshold high (register on page 1)
627 #define LTC2947_REG_E2TH_47_40 0x130
628 
629 // (register on page 1)
630 #define LTC2947_REG_E2TH_39_32 0x131
631 
632 // (register on page 1)
633 #define LTC2947_REG_E2TH_31_24 0x132
634 
635 // (register on page 1)
636 #define LTC2947_REG_E2TH_23_16 0x133
637 
638 // (register on page 1)
639 #define LTC2947_REG_E2TH_15_8 0x134
640 
641 // (register on page 1)
642 #define LTC2947_REG_E2TH_7_0 0x135
643 
644 // Energy 2 threshold low (register on page 1)
645 #define LTC2947_REG_E2TL_47_40 0x136
646 
647 // (register on page 1)
648 #define LTC2947_REG_E2TL_39_32 0x137
649 
650 // (register on page 1)
651 #define LTC2947_REG_E2TL_31_24 0x138
652 
653 // (register on page 1)
654 #define LTC2947_REG_E2TL_23_16 0x139
655 
656 // (register on page 1)
657 #define LTC2947_REG_E2TL_15_8 0x13A
658 
659 // (register on page 1)
660 #define LTC2947_REG_E2TL_7_0 0x13B
661 
662 // Current threshold high (register on page 1)
663 #define LTC2947_REG_ITH_15_8 0x180
664 
665 // (register on page 1)
666 #define LTC2947_REG_ITH_7_0 0x181
667 
668 // Current threshold low (register on page 1)
669 #define LTC2947_REG_ITL_15_8 0x182
670 
671 // (register on page 1)
672 #define LTC2947_REG_ITL_7_0 0x183
673 
674 // Power threshold high (register on page 1)
675 #define LTC2947_REG_PTH_15_8 0x184
676 
677 // (register on page 1)
678 #define LTC2947_REG_PTH_7_0 0x185
679 
680 // Power threshold low (register on page 1)
681 #define LTC2947_REG_PTL_15_8 0x186
682 
683 // (register on page 1)
684 #define LTC2947_REG_PTL_7_0 0x187
685 
686 // Voltage (VD = VP - VM) threshold high (register on page 1)
687 #define LTC2947_REG_VTH_15_8 0x190
688 
689 // (register on page 1)
690 #define LTC2947_REG_VTH_7_0 0x191
691 
692 // Voltage (VD = VP - VM) threshold low (register on page 1)
693 #define LTC2947_REG_VTL_15_8 0x192
694 
695 // (register on page 1)
696 #define LTC2947_REG_VTL_7_0 0x193
697 
698 // Temperature threshold high (register on page 1)
699 #define LTC2947_REG_TEMPTH_15_8 0x194
700 
701 // (register on page 1)
702 #define LTC2947_REG_TEMPTH_7_0 0x195
703 
704 // Temperature threshold low (register on page 1)
705 #define LTC2947_REG_TEMPTL_15_8 0x196
706 
707 // (register on page 1)
708 #define LTC2947_REG_TEMPTL_7_0 0x197
709 
710 // DVCC Voltage threshold high (register on page 1)
711 #define LTC2947_REG_VDVCCTH_15_8 0x198
712 
713 // (register on page 1)
714 #define LTC2947_REG_VDVCCTH_7_0 0x199
715 
716 // DVCC Voltage threshold low (register on page 1)
717 #define LTC2947_REG_VDVCCTL_15_8 0x19A
718 
719 // (register on page 1)
720 #define LTC2947_REG_VDVCCTL_7_0 0x19B
721 
722 // Fan temperature threshold high (if this temperature is exceeded the fan is enabled, see GPIOSTATCL) (register on page 1)
723 #define LTC2947_REG_TEMPTFANH_15_8 0x19C
724 
725 // (register on page 1)
726 #define LTC2947_REG_TEMPTFANH_7_0 0x19D
727 
728 // Fan temperature threshold low (if temperature falls below this value the fan is disabled, see GPIOSTATCL) (register on page 1)
729 #define LTC2947_REG_TEMPTFANL_15_8 0x19E
730 
731 // (register on page 1)
732 #define LTC2947_REG_TEMPTFANL_7_0 0x19F
733 
734 /////////////////////////////////////////////////////////
735 // Definitions of all available multiple byte values //
736 // (e.g. accumulators). //
737 // //
738 // Note: The address constants are 9 bit values where //
739 // the lower 8 bit define the address and the 9th bit //
740 // defines the page! //
741 /////////////////////////////////////////////////////////
742 
743 // Charge1 (register on page 0)
744 #define LTC2947_VAL_C1 0x000
745 
746 // Energy1 (register on page 0)
747 #define LTC2947_VAL_E1 0x006
748 
749 // Time1 (register on page 0)
750 #define LTC2947_VAL_TB1 0x00C
751 
752 // Charge2 (register on page 0)
753 #define LTC2947_VAL_C2 0x010
754 
755 // Energy2 (register on page 0)
756 #define LTC2947_VAL_E2 0x016
757 
758 // Time2 (register on page 0)
759 #define LTC2947_VAL_TB2 0x01C
760 
761 // Maximum current tracking (register on page 0)
762 #define LTC2947_VAL_IMAX 0x040
763 
764 // Minimum Current tracking (register on page 0)
765 #define LTC2947_VAL_IMIN 0x042
766 
767 // Maximum Power tracking (register on page 0)
768 #define LTC2947_VAL_PMAX 0x044
769 
770 // Minimum Power tracking (register on page 0)
771 #define LTC2947_VAL_PMIN 0x046
772 
773 // Maximum Voltage (VD = VP - VM) tracking (register on page 0)
774 #define LTC2947_VAL_VMAX 0x050
775 
776 // Minimum Voltage (VD = VP - VM) tracking (register on page 0)
777 #define LTC2947_VAL_VMIN 0x052
778 
779 // Maximum Temperature tracking (register on page 0)
780 #define LTC2947_VAL_TEMPMAX 0x054
781 
782 // Minimum Temperature tracking (register on page 0)
783 #define LTC2947_VAL_TEMPMIN 0x056
784 
785 // Maximum Voltage at DVCC tracking (register on page 0)
786 #define LTC2947_VAL_VDVCCMAX 0x058
787 
788 // Minimum Voltage at DVCC tracking (register on page 0)
789 #define LTC2947_VAL_VDVCCMIN 0x05A
790 
791 // Current (register on page 0)
792 #define LTC2947_VAL_I 0x090
793 
794 // Power (register on page 0)
795 #define LTC2947_VAL_P 0x093
796 
797 // Voltage (VD = VP - VM) (register on page 0)
798 #define LTC2947_VAL_V 0x0A0
799 
800 // Temperature (register on page 0)
801 #define LTC2947_VAL_TEMP 0x0A2
802 
803 // Voltage at DVCC (register on page 0)
804 #define LTC2947_VAL_VDVCC 0x0A4
805 
806 // Current History 1 (prev. result) (register on page 0)
807 #define LTC2947_VAL_IH1 0x0B0
808 
809 // Current History 2 (prev. result '-1') (register on page 0)
810 #define LTC2947_VAL_IH2 0x0B3
811 
812 // Current History 3 (prev. result '-2') (register on page 0)
813 #define LTC2947_VAL_IH3 0x0B6
814 
815 // Current History 4 (prev. result '-3') (register on page 0)
816 #define LTC2947_VAL_IH4 0x0B9
817 
818 // Current History 5 (prev. result '-4') (register on page 0)
819 #define LTC2947_VAL_IH5 0x0BC
820 
821 // Charge 1 threshold high (register on page 1)
822 #define LTC2947_VAL_C1TH 0x100
823 
824 // Charge 1 threshold low (register on page 1)
825 #define LTC2947_VAL_C1TL 0x106
826 
827 // Time Base 1 threshold high (register on page 1)
828 #define LTC2947_VAL_TB1TH 0x10C
829 
830 // Energy 1 threshold high (register on page 1)
831 #define LTC2947_VAL_E1TH 0x110
832 
833 // Energy 1 threshold low (register on page 1)
834 #define LTC2947_VAL_E1TL 0x116
835 
836 // Charge 2 threshold high (register on page 1)
837 #define LTC2947_VAL_C2TH 0x120
838 
839 // Charge 2 threshold low (register on page 1)
840 #define LTC2947_VAL_C2TL 0x126
841 
842 // Time Base 2 threshold high (register on page 1)
843 #define LTC2947_VAL_TB2TH 0x12C
844 
845 // Energy 2 threshold high (register on page 1)
846 #define LTC2947_VAL_E2TH 0x130
847 
848 // Energy 2 threshold low (register on page 1)
849 #define LTC2947_VAL_E2TL 0x136
850 
851 // Current threshold high (register on page 1)
852 #define LTC2947_VAL_ITH 0x180
853 
854 // Current threshold low (register on page 1)
855 #define LTC2947_VAL_ITL 0x182
856 
857 // Power threshold high (register on page 1)
858 #define LTC2947_VAL_PTH 0x184
859 
860 // Power threshold low (register on page 1)
861 #define LTC2947_VAL_PTL 0x186
862 
863 // Voltage (VD = VP - VM) threshold high (register on page 1)
864 #define LTC2947_VAL_VTH 0x190
865 
866 // Voltage (VD = VP - VM) threshold low (register on page 1)
867 #define LTC2947_VAL_VTL 0x192
868 
869 // Temperature threshold high (register on page 1)
870 #define LTC2947_VAL_TEMPTH 0x194
871 
872 // Temperature threshold low (register on page 1)
873 #define LTC2947_VAL_TEMPTL 0x196
874 
875 // DVCC Voltage threshold high (register on page 1)
876 #define LTC2947_VAL_VDVCCTH 0x198
877 
878 // DVCC Voltage threshold low (register on page 1)
879 #define LTC2947_VAL_VDVCCTL 0x19A
880 
881 // Fan temperature threshold high (if this temperature is exceeded the fan is enabled, see GPIOSTATCL) (register on page 1)
882 #define LTC2947_VAL_TEMPTFANH 0x19C
883 
884 // Fan temperature threshold low (if temperature falls below this value the fan is disabled, see GPIOSTATCL) (register on page 1)
885 #define LTC2947_VAL_TEMPTFANL 0x19E
886 
887 /////////////////////////////////////////////////////////
888 // Definition of LSB constants. //
889 /////////////////////////////////////////////////////////
890 
891 #ifndef LTC2947_PRE
892 #ifndef LTC2947_EXTCLK
893 // internal oscillator
894 #define LTC2947_PRE 7
895 #define LTC2947_DIV 0
896 #define LTC2947_EXTCLK 4e6
897 #else
898 #define LTC2947_EXTCLK_UNSUPPORTED 5
899 // user provided external oscillator frequency
900 #define LTC2947_PRE ( \
901  LTC2947_EXTCLK <= 1e6 ? 0 : \
902  LTC2947_EXTCLK <= 2e6 ? 1 : \
903  LTC2947_EXTCLK <= 4e6 ? 2 : \
904  LTC2947_EXTCLK <= 8e6 ? 3 : \
905  LTC2947_EXTCLK <= 16e6 ? 4 : \
906  LTC2947_EXTCLK <= 25e6 ? 5 : LTC2947_EXTCLK_UNSUPPORTED)
907 #define LTC2947_DIV ((uint8_t)(LTC2947_EXTCLK/32768.0/(1 << LTC2947_PRE)))
908 #endif
909 #endif
910 
911 #define LTC2947_EXTPER (1.0/LTC2947_EXTCLK)
912 
913 #define LTC2947_INTC 31e-6
914 
915 // LSB of C1 in As
916 #define LTC2947_LSB_C1 (0.0384946 * (LTC2947_PRE == 7 ? LTC2947_INTC : LTC2947_EXTPER * (1 << LTC2947_PRE) * (LTC2947_DIV + 1)))
917 // LSB of E1 in Ws
918 #define LTC2947_LSB_E1 (0.641576 * (LTC2947_PRE == 7 ? LTC2947_INTC : LTC2947_EXTPER * (1 << LTC2947_PRE) * (LTC2947_DIV + 1)))
919 // LSB of TB1 in s
920 #define LTC2947_LSB_TB1 (12.8315 * (LTC2947_PRE == 7 ? LTC2947_INTC : LTC2947_EXTPER * (1 << LTC2947_PRE) * (LTC2947_DIV + 1)))
921 // LSB of C2 in As
922 #define LTC2947_LSB_C2 (0.0384946 * (LTC2947_PRE == 7 ? LTC2947_INTC : LTC2947_EXTPER * (1 << LTC2947_PRE) * (LTC2947_DIV + 1)))
923 // LSB of E2 in Ws
924 #define LTC2947_LSB_E2 (0.641576 * (LTC2947_PRE == 7 ? LTC2947_INTC : LTC2947_EXTPER * (1 << LTC2947_PRE) * (LTC2947_DIV + 1)))
925 // LSB of TB2 in s
926 #define LTC2947_LSB_TB2 (12.8315 * (LTC2947_PRE == 7 ? LTC2947_INTC : LTC2947_EXTPER * (1 << LTC2947_PRE) * (LTC2947_DIV + 1)))
927 // LSB of IMAX in mA
928 #define LTC2947_LSB_IMAX 12.0
929 // LSB of IMIN in mA
930 #define LTC2947_LSB_IMIN 12.0
931 // LSB of PMAX in mW
932 #define LTC2947_LSB_PMAX 200.0
933 // LSB of PMIN in mW
934 #define LTC2947_LSB_PMIN 200.0
935 // LSB of VMAX in mV
936 #define LTC2947_LSB_VMAX 2.0
937 // LSB of VMIN in mV
938 #define LTC2947_LSB_VMIN 2.0
939 // LSB of TEMPMAX in °C (Note: Temperature has additionally an offset of 5.5 °C)
940 #define LTC2947_LSB_TEMPMAX 0.204
941 // Offset of TEMPMAX in °C
942 #define LTC2947_OFFS_TEMPMAX 5.5
943 // LSB of TEMPMIN in °C (Note: Temperature has additionally an offset of 5.5 °C)
944 #define LTC2947_LSB_TEMPMIN 0.204
945 // Offset of TEMPMIN in °C
946 #define LTC2947_OFFS_TEMPMIN 5.5
947 // LSB of VDVCCMAX in mV
948 #define LTC2947_LSB_VDVCCMAX 145.0
949 // LSB of VDVCCMIN in mV
950 #define LTC2947_LSB_VDVCCMIN 145.0
951 // LSB of I in mA
952 #define LTC2947_LSB_I 3.0
953 // LSB of P in mW
954 #define LTC2947_LSB_P 50.0
955 // LSB of V in mV
956 #define LTC2947_LSB_V 2.0
957 // LSB of TEMP in °C (Note: Temperature has additionally an offset of 5.5 °C)
958 #define LTC2947_LSB_TEMP 0.204
959 // Offset of TEMP in °C
960 #define LTC2947_OFFS_TEMP 5.5
961 // LSB of VDVCC in mV
962 #define LTC2947_LSB_VDVCC 145.0
963 // LSB of IH1 in mA
964 #define LTC2947_LSB_IH1 3.0
965 // LSB of IH2 in mA
966 #define LTC2947_LSB_IH2 3.0
967 // LSB of IH3 in mA
968 #define LTC2947_LSB_IH3 3.0
969 // LSB of IH4 in mA
970 #define LTC2947_LSB_IH4 3.0
971 // LSB of IH5 in mA
972 #define LTC2947_LSB_IH5 3.0
973 // LSB of C1TH in As
974 #define LTC2947_LSB_C1TH (0.0384946 * (LTC2947_PRE == 7 ? LTC2947_INTC : LTC2947_EXTPER * (1 << LTC2947_PRE) * (LTC2947_DIV + 1)))
975 // LSB of C1TL in As
976 #define LTC2947_LSB_C1TL (0.0384946 * (LTC2947_PRE == 7 ? LTC2947_INTC : LTC2947_EXTPER * (1 << LTC2947_PRE) * (LTC2947_DIV + 1)))
977 // LSB of TB1TH in s
978 #define LTC2947_LSB_TB1TH (12.8315 * (LTC2947_PRE == 7 ? LTC2947_INTC : LTC2947_EXTPER * (1 << LTC2947_PRE) * (LTC2947_DIV + 1)))
979 // LSB of E1TH in Ws
980 #define LTC2947_LSB_E1TH (0.641576 * (LTC2947_PRE == 7 ? LTC2947_INTC : LTC2947_EXTPER * (1 << LTC2947_PRE) * (LTC2947_DIV + 1)))
981 // LSB of E1TL in Ws
982 #define LTC2947_LSB_E1TL (0.641576 * (LTC2947_PRE == 7 ? LTC2947_INTC : LTC2947_EXTPER * (1 << LTC2947_PRE) * (LTC2947_DIV + 1)))
983 // LSB of C2TH in As
984 #define LTC2947_LSB_C2TH (0.0384946 * (LTC2947_PRE == 7 ? LTC2947_INTC : LTC2947_EXTPER * (1 << LTC2947_PRE) * (LTC2947_DIV + 1)))
985 // LSB of C2TL in As
986 #define LTC2947_LSB_C2TL (0.0384946 * (LTC2947_PRE == 7 ? LTC2947_INTC : LTC2947_EXTPER * (1 << LTC2947_PRE) * (LTC2947_DIV + 1)))
987 // LSB of TB2TH in s
988 #define LTC2947_LSB_TB2TH (12.8315 * (LTC2947_PRE == 7 ? LTC2947_INTC : LTC2947_EXTPER * (1 << LTC2947_PRE) * (LTC2947_DIV + 1)))
989 // LSB of E2TH in Ws
990 #define LTC2947_LSB_E2TH (0.641576 * (LTC2947_PRE == 7 ? LTC2947_INTC : LTC2947_EXTPER * (1 << LTC2947_PRE) * (LTC2947_DIV + 1)))
991 // LSB of E2TL in Ws
992 #define LTC2947_LSB_E2TL (0.641576 * (LTC2947_PRE == 7 ? LTC2947_INTC : LTC2947_EXTPER * (1 << LTC2947_PRE) * (LTC2947_DIV + 1)))
993 // LSB of ITH in mA
994 #define LTC2947_LSB_ITH 12.0
995 // LSB of ITL in mA
996 #define LTC2947_LSB_ITL 12.0
997 // LSB of PTH in mW
998 #define LTC2947_LSB_PTH 200.0
999 // LSB of PTL in mW
1000 #define LTC2947_LSB_PTL 200.0
1001 // LSB of VTH in mV
1002 #define LTC2947_LSB_VTH 2.0
1003 // LSB of VTL in mV
1004 #define LTC2947_LSB_VTL 2.0
1005 // LSB of TEMPTH in °C (Note: Temperature has additionally an offset of 5.5 °C)
1006 #define LTC2947_LSB_TEMPTH 0.204
1007 // Offset of TEMPTH in °C
1008 #define LTC2947_OFFS_TEMPTH 5.5
1009 // LSB of TEMPTL in °C (Note: Temperature has additionally an offset of 5.5 °C)
1010 #define LTC2947_LSB_TEMPTL 0.204
1011 // Offset of TEMPTL in °C
1012 #define LTC2947_OFFS_TEMPTL 5.5
1013 // LSB of VDVCCTH in mV
1014 #define LTC2947_LSB_VDVCCTH 145.0
1015 // LSB of VDVCCTL in mV
1016 #define LTC2947_LSB_VDVCCTL 145.0
1017 // LSB of TEMPTFANH in °C (Note: Temperature has additionally an offset of 5.5 °C)
1018 #define LTC2947_LSB_TEMPTFANH 0.204
1019 // Offset of TEMPTFANH in °C
1020 #define LTC2947_OFFS_TEMPTFANH 5.5
1021 // LSB of TEMPTFANL in °C (Note: Temperature has additionally an offset of 5.5 °C)
1022 #define LTC2947_LSB_TEMPTFANL 0.204
1023 // Offset of TEMPTFANL in °C
1024 #define LTC2947_OFFS_TEMPTFANL 5.5
1025 
1026 /////////////////////////////////////////////////////////
1027 // Definition of all bit masks. //
1028 /////////////////////////////////////////////////////////
1029 
1030 // GPIOSTATCL bit masks
1031 // GPIO output enable (0: input, 1: output)
1032 #define LTC2947_BM_GPIOSTATCL_GPOEN 0x1
1033 // This register shows the applied level at pin GPIO
1034 // 0: Logical level 0 at pin GPIO
1035 // 1: Logical level 1 at pin GPIO
1036 #define LTC2947_BM_GPIOSTATCL_GPI 0x10
1037 // This register sets the level at GPIO if set as output provided there is a pull-up resistor at GPIO
1038 // 0: Pin GPIO is set to 0 if set as output
1039 // 1: Pin GPIO is set to 1 if set as output
1040 #define LTC2947_BM_GPIOSTATCL_GPO 0x20
1041 // GPIO fan control enable
1042 // 0:GPIO controlled by GPO
1043 // 1: GPIO controlled by temperature measurement against thresholds
1044 #define LTC2947_BM_GPIOSTATCL_FANEN 0x40
1045 // Polarity of GPIO if FANEN = 1
1046 // 0: low active
1047 // 1: high active
1048 #define LTC2947_BM_GPIOSTATCL_FANPOL 0x80
1049 
1050 // STATUS bit masks
1051 // 1: Undervoltage in the analog domain including ADCs during a conversion
1052 #define LTC2947_BM_STATUS_UVLOA 0x1
1053 // 1: Power On Reset has occurred due to undervoltage in the analog domain.
1054 #define LTC2947_BM_STATUS_PORA 0x2
1055 // 1: Undervoltage in the standby domain
1056 #define LTC2947_BM_STATUS_UVLOSTBY 0x4
1057 // 1: Undervoltage in the digital domain
1058 #define LTC2947_BM_STATUS_UVLOD 0x8
1059 // 1: Result registers have been updated
1060 #define LTC2947_BM_STATUS_UPDATE 0x10
1061 // 1: The ADC conversion is not valid due to undervoltage during a conversion
1062 #define LTC2947_BM_STATUS_ADCERR 0x20
1063 // 1: External clock provided does not fit to TBC settings. Also LSB values of accumulated registers are wrong.
1064 #define LTC2947_BM_STATUS_TBERR 0x40
1065 
1066 // STATVT bit masks
1067 // 1: Voltage (VD = VP - VM) high threshold exceeded
1068 #define LTC2947_BM_STATVT_VH 0x1
1069 // 1: Voltage (VD = VP - VM) low threshold exceeded
1070 #define LTC2947_BM_STATVT_VL 0x2
1071 // 1: Temperature high threshold exceeded
1072 #define LTC2947_BM_STATVT_TEMPH 0x4
1073 // 1: Temperature low threshold exceeded
1074 #define LTC2947_BM_STATVT_TEMPL 0x8
1075 // 1: Fan high temperature threshold exceeded
1076 #define LTC2947_BM_STATVT_FANH 0x10
1077 // 1: Fan low temperature threshold exceeded
1078 #define LTC2947_BM_STATVT_FANL 0x20
1079 
1080 // STATIP bit masks
1081 // 1: Current high threshold exceeded
1082 #define LTC2947_BM_STATIP_IH 0x1
1083 // 1: Current low threshold exceeded
1084 #define LTC2947_BM_STATIP_IL 0x2
1085 // 1: Power high threshold exceeded
1086 #define LTC2947_BM_STATIP_PH 0x4
1087 // 1: Power low threshold exceeded
1088 #define LTC2947_BM_STATIP_PL 0x8
1089 
1090 // STATC bit masks
1091 // 1: Charge1 high threshold exceeded
1092 #define LTC2947_BM_STATC_C1H 0x1
1093 // 1: Charge1 low threshold exceeded
1094 #define LTC2947_BM_STATC_C1L 0x2
1095 // 1: Charge2 high threshold exceeded
1096 #define LTC2947_BM_STATC_C2H 0x4
1097 // 1: Charge2 low threshold exceeded
1098 #define LTC2947_BM_STATC_C2L 0x8
1099 
1100 // STATE bit masks
1101 // 1: Energy1 high threshold exceeded
1102 #define LTC2947_BM_STATE_E1H 0x1
1103 // 1: Energy1 low threshold exceeded
1104 #define LTC2947_BM_STATE_E1L 0x2
1105 // 1: Energy2 high threshold exceeded
1106 #define LTC2947_BM_STATE_E2H 0x4
1107 // 1: Energy2 low threshold exceeded
1108 #define LTC2947_BM_STATE_E2L 0x8
1109 
1110 // STATCEOF bit masks
1111 // 1: Charge1 overflow alert
1112 #define LTC2947_BM_STATCEOF_C1OF 0x1
1113 // 1: Charge2 overflow alert
1114 #define LTC2947_BM_STATCEOF_C2OF 0x2
1115 // 1: Energy1 overflow alert
1116 #define LTC2947_BM_STATCEOF_E1OF 0x10
1117 // 1: Energy2 overflow alert
1118 #define LTC2947_BM_STATCEOF_E2OF 0x20
1119 
1120 // STATTB bit masks
1121 // 1: Time1 threshold exceeded
1122 #define LTC2947_BM_STATTB_TB1TH 0x1
1123 // 1: Time2 threshold exceeded
1124 #define LTC2947_BM_STATTB_TB2TH 0x2
1125 // 1: Time1 overflow
1126 #define LTC2947_BM_STATTB_TB1OF 0x10
1127 // 1: Time 2 overflow
1128 #define LTC2947_BM_STATTB_TB2OF 0x20
1129 
1130 // STATVDVCC bit masks
1131 // 1: DVCC high threshold exceeded
1132 #define LTC2947_BM_STATVDVCC_VDVCCH 0x1
1133 // 1: DVCC low threshold exceeded
1134 #define LTC2947_BM_STATVDVCC_VDVCCL 0x2
1135 
1136 // STATUSM bit masks
1137 // UVLOA mask
1138 #define LTC2947_BM_STATUSM_UVLOAM 0x1
1139 // UVLOD mask
1140 #define LTC2947_BM_STATUSM_UVLODM 0x8
1141 // UPDATE mask
1142 #define LTC2947_BM_STATUSM_UPDATEM 0x10
1143 // ADCERR mask
1144 #define LTC2947_BM_STATUSM_ADCERRM 0x20
1145 // TBERR mask
1146 #define LTC2947_BM_STATUSM_TBERRM 0x40
1147 
1148 // STATVTM bit masks
1149 // VH mask
1150 #define LTC2947_BM_STATVTM_VHM 0x1
1151 // VL mask
1152 #define LTC2947_BM_STATVTM_VLM 0x2
1153 // TEMPH mask
1154 #define LTC2947_BM_STATVTM_TEMPHM 0x4
1155 // TEMPL mask
1156 #define LTC2947_BM_STATVTM_TEMPLM 0x8
1157 // FANH mask
1158 #define LTC2947_BM_STATVTM_FANHM 0x10
1159 // FANL mask
1160 #define LTC2947_BM_STATVTM_FANLM 0x20
1161 
1162 // STATIPM bit masks
1163 // IH mask
1164 #define LTC2947_BM_STATIPM_IHM 0x1
1165 // IL mask
1166 #define LTC2947_BM_STATIPM_ILM 0x2
1167 // PH mask
1168 #define LTC2947_BM_STATIPM_PHM 0x4
1169 // PL mask
1170 #define LTC2947_BM_STATIPM_PLM 0x8
1171 
1172 // STATCM bit masks
1173 // C1H mask
1174 #define LTC2947_BM_STATCM_C1HM 0x1
1175 // C1L mask
1176 #define LTC2947_BM_STATCM_C1LM 0x2
1177 // C2H mask
1178 #define LTC2947_BM_STATCM_C2HM 0x4
1179 // C2L mask
1180 #define LTC2947_BM_STATCM_C2LM 0x8
1181 
1182 // STATEM bit masks
1183 // E1H mask
1184 #define LTC2947_BM_STATEM_E1HM 0x1
1185 // E1L mask
1186 #define LTC2947_BM_STATEM_E1LM 0x2
1187 // E2H mask
1188 #define LTC2947_BM_STATEM_E2HM 0x4
1189 // E2L mask
1190 #define LTC2947_BM_STATEM_E2LM 0x8
1191 
1192 // STATCEOFM bit masks
1193 // C1OF mask
1194 #define LTC2947_BM_STATCEOFM_C1OFM 0x1
1195 // C2OF mask
1196 #define LTC2947_BM_STATCEOFM_C2OFM 0x2
1197 // E1OF mask
1198 #define LTC2947_BM_STATCEOFM_E1OFM 0x10
1199 // E2OF mask
1200 #define LTC2947_BM_STATCEOFM_E2OFM 0x20
1201 
1202 // STATTBM bit masks
1203 // TB1TH mask
1204 #define LTC2947_BM_STATTBM_TB1THM 0x1
1205 // TB2TH mask
1206 #define LTC2947_BM_STATTBM_TB2THM 0x2
1207 // TB1OF mask
1208 #define LTC2947_BM_STATTBM_TB1OFM 0x10
1209 // TB2OF mask
1210 #define LTC2947_BM_STATTBM_TB2OFM 0x20
1211 
1212 // STATVDVCCM bit masks
1213 // VDVCCH mask
1214 #define LTC2947_BM_STATVDVCCM_VDVCCHM 0x1
1215 // VDVCCL mask
1216 #define LTC2947_BM_STATVDVCCM_VDVCCLM 0x2
1217 
1218 // ACCICTL bit masks
1219 // accumulator 1 current control (bit 0)
1220 #define LTC2947_BM_ACCICTL_ACC1I0 0x1
1221 // accumulator 1 current control (bit 1)
1222 #define LTC2947_BM_ACCICTL_ACC1I1 0x2
1223 // accumulator 2 current control (bit 0)
1224 #define LTC2947_BM_ACCICTL_ACC2I0 0x4
1225 // accumulator 2 current control (bit 1)
1226 #define LTC2947_BM_ACCICTL_ACC2I1 0x8
1227 
1228 // ACCGPCTL bit masks
1229 // accumulator 1 GPIO control (bit 0)
1230 #define LTC2947_BM_ACCGPCTL_ACC1GP0 0x1
1231 // accumulator 1 GPIO control (bit 1)
1232 #define LTC2947_BM_ACCGPCTL_ACC1GP1 0x2
1233 // accumulator 2 GPIO control (bit 0)
1234 #define LTC2947_BM_ACCGPCTL_ACC2GP0 0x4
1235 // accumulator 2 GPIO control (bit 1)
1236 #define LTC2947_BM_ACCGPCTL_ACC2GP1 0x8
1237 
1238 // ALERTBCTL bit masks
1239 // 0: Unmasked alerts (see MASK registers) are not forwarded to ALERT pin
1240 // 1: Unmasked alerts (see MASK registers) are forwarded to ALERT pin
1241 #define LTC2947_BM_ALERTBCTL_ALERTBEN 0x1
1242 
1243 // TBCTL bit masks
1244 // Prescaler value bit 0, binary coded.
1245 #define LTC2947_BM_TBCTL_PRE_0 0x1
1246 // Prescaler value bit 1, binary coded.
1247 #define LTC2947_BM_TBCTL_PRE_1 0x2
1248 // Prescaler value bit 2, binary coded.
1249 #define LTC2947_BM_TBCTL_PRE_2 0x4
1250 // Divider value bit 0, binary coded.
1251 #define LTC2947_BM_TBCTL_DIV_0 0x8
1252 // Divider value bit 1, binary coded.
1253 #define LTC2947_BM_TBCTL_DIV_1 0x10
1254 // Divider value bit 2, binary coded.
1255 #define LTC2947_BM_TBCTL_DIV_2 0x20
1256 // Divider value bit 3, binary coded.
1257 #define LTC2947_BM_TBCTL_DIV_3 0x40
1258 // Divider value bit 4, binary coded.
1259 #define LTC2947_BM_TBCTL_DIV_4 0x80
1260 
1261 // OPCTL bit masks
1262 // 0: Normal operation
1263 // 1: Shutdown. The LTC2947 will exit shutdown in SPI mode if the pin AD1/CS is pulled lowand in I2C mode if it receives the correct I2C address (programmed at the ADx pins).
1264 #define LTC2947_BM_OPCTL_SHDN 0x1
1265 // 1: Clear. The accumulation and tracking (max/min) registers are cleared: C1, E1, TB1, C2, E2, TB2, IMAX, IMIN, PMAX, PMIN, VMAX, VMIN, TEMPMAX, TEMPMIN, VDVCCMAX,VDVCCMIN.
1266 #define LTC2947_BM_OPCTL_CLR 0x2
1267 // 1: Single Shot Measurement. A single set of measurements of current, voltage, power, temperature and VDVCC are performed and the result registers updated. If CONT is set, it is cleared after completion of any conversion cycle in progress and the single shot measurement is executed. SSHOT is cleared after the single measurement cycle is complete.
1268 #define LTC2947_BM_OPCTL_SSHOT 0x4
1269 // 0: Idle mode (no measurement)
1270 // 1: Continuous measurement is enabled. Measurement cycles run continuously. Charge and energy measurements are only active in continuous mode.
1271 #define LTC2947_BM_OPCTL_CONT 0x8
1272 // Global Reset. When set, the 2947 is reset and all registers are set to their default values.
1273 #define LTC2947_BM_OPCTL_RST 0x80
1274 
1275 // PGCTL bit masks
1276 // Memory Map Page Select.
1277 // 0: PAGE 0 of memory map is selected.
1278 // 1: PAGE 1 of memory map is selected.
1279 #define LTC2947_BM_PGCTL_PAGE 0x1
1280 
1281 /** @} */ // end of LTC2947 auto generated code
1282 
1283 /** @name function prototypes
1284 * @{
1285 */
1286 
1287 //! Initializes the LTC2947 library for I2C mode operation and configures the slave address
1288 //! see defines LTC2947_I2C_ADDR_LL to LTC2947_I2C_ADDR_RR for possible slave addresses
1289 void LTC2947_InitI2C(
1290  uint8_t slvAddr //!< 7-bit I2C slave address of the LTC2947 (e.g. LTC2947_I2C_ADDR_LL)
1291 );
1292 
1293 //! Initializes the LTC2947 library for SPI mode operation
1294 void LTC2947_InitSPI();
1295 
1296 //! Converts an array of 2 bytes to 16-bit unsigned integer
1297 //! @return 16-bit unsigned integer
1298 uint16_t LTC2947_2BytesToUInt16(
1299  byte *bytes //!< 2 byte array (MSB first)
1300 );
1301 
1302 //! converts an array of 3 bytes to 32-bit unsigned integer
1303 //! @return 32-bit unsigned integer
1304 uint32_t LTC2947_3BytesToUInt32(
1305  byte *bytes //!< 3 byte array (MSB first)
1306 );
1307 
1308 //! Converts an array of 4 bytes to 32-bit unsigned integer
1309 //! @return 32-bit unsigned integer
1310 uint32_t LTC2947_4BytesToUInt32(
1311  byte *bytes //!< 4 byte array (MSB first)
1312 );
1313 
1314 //! converts an array of 2 bytes to 16-bit signed integer
1315 //! @return 16-bit signed integer
1316 int16_t LTC2947_2BytesToInt16(
1317  byte *bytes //!< 2 byte array (MSB first)
1318 );
1319 
1320 //! converts an array of 3 bytes to 32-bit signed integer
1321 //! @return 32-bit signed integer
1322 int32_t LTC2947_3BytesToInt32(
1323  byte *bytes //!< 3 byte array (MSB first)
1324 );
1325 
1326 //! Converts an array of 4 bytes to 32-bit signed integer
1327 //! @return 32-bit signed integer
1328 int32_t LTC2947_4BytesToInt32(
1329  byte *bytes //!< 4 byte array (MSB first)
1330 );
1331 
1332 //! Converts an unsigned value of arbitrary number of bytes to a floating point value with the scaling factor lsb
1333 //! The input value must be usigned, use LTC2947_Abs to convert the bytes to an absolute (positive) value or use
1334 //! LTC2947_SignedBytesToDouble instead.
1335 //! For input values with up to 4 bytes use LTC2947_<X>BytesToUInt<N> (e.g. LTC2947_4BytesToUInt32, LTC2947_2BytesToUInt16)
1336 //! and multiply the result by lsb for reduced calculation time, e.g. "LTC2947_4BytesToUInt32(bytes)*lsb".
1337 //! @return result in floating point number format (absolute value, so always positive!)
1339  uint8_t *unsignedBytes, //!< unsigned input value as byte array (MSB first)
1340  uint8_t length, //!< number of bytes of the unsigned value
1341  double lsb //!< lsb value (scaling factor used to scale the unsigned value)
1342 );
1343 
1344 //! Converts a signed value of arbitrary number of bytes to a floating point value with the scaling factor lsb
1345 //! The input value must be a signed format. For unsigned values use LTC2947_UnsignedBytesToDouble.
1346 //! For input values with up to 4 bytes use LTC2947_<X>BytesToInt<N> (e.g. LTC2947_4BytesToInt32, LTC2947_2BytesToInt16)
1347 //! and multiply the result by lsb for reduced calculation time, e.g. "LTC2947_4BytesToInt32(bytes)*lsb".
1348 //! @return result in floating point number format.
1350  uint8_t *signedBytes, //!< signed input value as byte array (MSB first)
1351  uint8_t length, //!< number of bytes of the signed value
1352  double lsb //!< lsb value (scaling factor used to scale the signed value)
1353 );
1354 
1355 //! Converts a signed or unsigned value of arbitrary number of bytes to a floating point number
1356 //! @return result in floating point number format.
1357 double LTC2947_BytesToDouble(
1358  uint8_t *bytes, //!< input value as byte array (MSB first)
1359  uint8_t length, //!< number of bytes of the input value
1360  boolean sig, //!< true for signed value, false for unsigned
1361  double lsb //!< lsb value (scaling factor used to scale the input value)
1362 );
1363 
1364 //! Converts a floating point number that was scaled with a given LSB to an integer representation
1365 //! that will be stored in the given byte array.
1367  double value, //!< floating point value
1368  double lsb, //!< lsb of the floating point value (integer = value / lsb)
1369  uint8_t *bytes, //!< byte array of the integer representation
1370  uint8_t length //!< length (<=8) of the byte array. Note: The function does not check for overflow of the integer representation
1371 );
1372 
1373 //! Prints a 8-bit value in 2-character hexadecimal format with left padded zeros
1375  uint8_t val //!< 8-bit input value
1376 );
1377 
1378 //! Prints a 16-bit value in 4-character hexadecimal format with left padded zeros
1380  uint16_t val //!< 16-bit input value
1381 );
1382 
1383 //! Prints a 32-bit value in 8-character hexadecimal format with left padded zeros
1385  uint32_t val //!< 32-bit input value
1386 );
1387 
1388 //! Prints a 64-bit value in 16-character hexadecimal format with left padded zeros
1390  uint64_t uint64Val //!< 64-bit input value
1391 );
1392 
1393 #ifdef LTC2947_DEBUG
1394 //! conversion function test
1395 void LTC2947_DoubleToBytes_Test();
1396 #endif
1397 
1398 //! Calculates the absolute value of a signed value with arbitrary number of bytes
1399 //! @return true: value was inverted, false: value was already positive
1400 boolean LTC2947_Abs(
1401  uint8_t *bytes, //!< bytes of the signed value (MSB first)
1402  uint8_t length //!< number of bytes
1403 );
1404 
1405 //! Reads current (I), power (P), voltage (V), temperature (TEMP)
1406 //! and supply voltage (VCC) from the device
1407 //! Make sure LTC2947's page 0 is selected before calling this function.
1408 //! Use LTC2947_SetPageSelect to change page if necessary
1410  float *I, //!< Current im amps
1411  float *P, //!< Power in watts
1412  float *V, //!< Voltage in volts
1413  float *TEMP, //!< Temperature in degree celcius
1414  float *VCC //!< Supply voltage in volts
1415 );
1416 
1417 //! Reads charge (C), energy (E) and time (TB) from the device.
1418 //! Charge and Energy are converted to absulte
1419 //! values (always positive!) and a separate sign bit.
1420 //! If the separation in absolute value and sign is not desired use
1421 //! LTC2947_Read_C_E_TB instead.
1422 //! Make sure LTC2947's page 0 is selected before calling this function.
1423 //! Use LTC2947_SetPageSelect to change page if necessary
1425  boolean accuSet1, //!< True: Read C1, E1, TB1. False: Read C2, E2, TB2.
1426  double *C, //!< Absolute value of charge in As
1427  boolean *signC, //!< Sign of charge (True: negative, False: positive)
1428  double *E, //!< Absolute value of energy in Ws
1429  boolean *signE, //!< Sign of energy (True: negative, False: positive)
1430  double *TB //!< Time in s
1431 );
1432 
1433 //! Reads charge (C), energy (E) and time (TB) from the device.
1434 //! Make sure LTC2947's page 0 is selected before calling this function.
1435 //! Use LTC2947_SetPageSelect to change page if necessary
1436 void LTC2947_Read_C_E_TB(
1437  boolean accuSet1, //!< True: Read C1, E1, TB1. False: Read C2, E2, TB2.
1438  double *C, //!< Signed charge in As
1439  double *E, //!< Signed energy in Ws
1440  double *TB //!< Time in s
1441 );
1442 
1443 //! read single byte from SPI interface
1444 //! @return always 0
1445 int8_t LTC2947_SpiRdByte(
1446  uint8_t address, //!< register address
1447  uint8_t *value //!< Byte pointer to store read byte
1448 );
1449 
1450 //! write single byte to SPI interface
1451 //! @return always 0
1452 int8_t LTC2947_SpiWrByte(
1453  uint8_t address, //!< register address
1454  uint8_t value //!< Byte to be written
1455 );
1456 
1457 //! read array of bytes from the SPI interface
1458 //! @return always 0
1459 int8_t LTC2947_SpiRdBlock(
1460  uint8_t address, //!< register address
1461  uint8_t length, //!< Length of array
1462  uint8_t *values //!< Byte array to store read bytes
1463 );
1464 
1465 //! writes block (array) of bytes to the SPI interface
1466 //! @return always 0
1467 int8_t LTC2947_SpiWrBlock(
1468  uint8_t address, //!< register address
1469  uint8_t length, //!< Length of array
1470  uint8_t *values //!< Byte array to be written
1471 );
1472 
1473 //! read single byte via I2C
1474 //! @return 0 if successful, 1 if not successful
1475 int8_t LTC2947_I2CRdByte(
1476  uint8_t slvAddr, //!< The slv address.
1477  uint8_t regAddr, //!< The register address.
1478  uint8_t *value //!< byte that was read
1479 );
1480 
1481 //! read multiple bytes via I2C
1482 //! @return 0 if successful, 1 if not successful
1483 int8_t LTC2947_I2CRdBlock(
1484  uint8_t slvAddr, //!< The slv address.
1485  uint8_t regAddr, //!< The register address.
1486  uint8_t length, //!< number of bytes.
1487  uint8_t *values //!< read bytes
1488 );
1489 
1490 //! write single byte via I2C
1491 //! @return 0 if successful, 1 if not successful
1492 int8_t LTC2947_I2CWrByte(
1493  uint8_t slvAddr, //!< The slv address.
1494  uint8_t regAddr, //!< The register address.
1495  uint8_t value //!< byte to be written
1496 );
1497 
1498 //! write byte array via I2C interface
1499 //! @return 0 if successful, 1 if not successful
1500 int8_t LTC2947_I2CWrBlock(
1501  uint8_t slvAddr, //!< The slv address.
1502  uint8_t regAddr, //!< The register address.
1503  uint8_t length, //!< number of bytes.
1504  uint8_t *values //!< bytes to be written
1505 );
1506 
1507 //! general I2C communication error
1508 #define LTC2947_ARA_ERROR 0xFF
1509 //! got ARA response from LTC2947
1510 #define LTC2947_ARA_LTC2947_RESPONSE 1
1511 //! got ARA response from some other I2C slave
1512 #define LTC2947_ARA_OTHER_RESPONSE 2
1513 //! got NO ARA response
1514 #define LTC2947_ARA_NO_RESPONSE 3
1515 //! got ARA response from any slave but wihtout the expected WR bit
1516 #define LTC2947_ARA_RESPONSE_WO_WR 4
1517 //! The general alert response address
1518 #define LTC2947_ALERT_RESP_ADDR 0x0C
1519 
1520 
1521 //! Sends the Alert Response address to the I2C bus and reads the response
1522 //! If two or more devices on the same bus are generating
1523 //! alerts when the ARA is broadcasted, standard I2C arbitra-
1524 //! tion causes the device with the highest priority (lowest
1525 //! address) to reply first and the device with the lowest pri-
1526 //! ority (highest address) to reply last.The bus master will
1527 //! repeat the alert response protocol until the ALERT line is
1528 //! released.
1529 //! @return LTC2947_ARA_ERROR : general I2C communication error
1530 //! LTC2947_ARA_LTC2947_RESPONSE : got ARA response from LTC2947
1531 //! LTC2947_ARA_OTHER_RESPONSE : got ARA response from some other I2C slave
1532 //! LTC2947_ARA_NO_RESPONSE : got NO ARA response
1533 //! LTC2947_ARA_RESPONSE_WO_WR : got ARA response from any slave but wihtout the expected WR bit
1534 uint8_t LTC2947_Ara(
1535  uint8_t *svlAddr //!< 7-bit address of the responding slave
1536 );
1537 
1538 //! write LTC2947's page control register to selected one of two memory pages
1540  boolean page //!< false: select page 0, true: select page 1
1541 );
1542 
1543 //! Wake up LTC2947 from shutdown mode and measure the wakeup time
1544 //! @return -1 in case of timeout or milliseconds it took to wakeup LTC2947
1545 int16_t LTC2947_wake_up();
1546 
1547 //! reads LTC2947's page control register to determine the currently selected memory page
1548 //! @return true: page 1 is selected, false: page 0
1550 
1551 //! reads the current GPIO pin state
1552 //! Make sure LTC2947's page 0 is selected before calling this function.
1553 //! Use LTC2947_SetPageSelect to change page if necessary
1554 //! @return true: pin high, false: pin low
1555 boolean LTC2947_GPIO_Read();
1556 
1557 //! Enables/disables the output driver on the GPIO pin
1558 //! Make sure LTC2947's page 0 is selected before calling this function.
1559 //! Use LTC2947_SetPageSelect to change page if necessary
1561  uint8_t mode //!< OUTPUT (1): output driver enabled, INPUT (0): output driver disabled
1562 );
1563 
1564 //! Sets the level of the output driver on the GPIO pin
1565 //! This has only an effect if the output driver is enabled, see LTC2947_GPIO_PinMode
1566 //! Make sure LTC2947's page 0 is selected before calling this function.
1567 //! Use LTC2947_SetPageSelect to change page if necessary
1569  uint8_t val //!< LOW (0): pin low, HIGH (1): pin high
1570 );
1571 
1572 /** @} */ // end of function prototypes
1573 
1574 //! controlled by LTC2947_InitI2C / LTC2947_InitSPI to switch between I2C / SPI mode
1575 extern boolean LTC2947_SPI_Mode_Enabled;
1576 //! set by LTC2947_InitI2C to set slave address for I2C operation
1577 extern uint8_t LTC2947_I2C_Slave_Addr;
1578 
1579 /** @name serial communication wrapper macros
1580 * LTC2947's I2C / Spi functions are wrapped to common serial communication functions
1581 * The user sets the active communication interface by calling LTC2947_InitI2C or LTC2947_InitSPI
1582 * once at boot-up.
1583 * @{
1584 */
1585 
1586 //! read multiple bytes via I2C/SPI
1587 //! @return 0 if successful, 1 if not successful
1588 static inline int8_t LTC2947_RD_BYTES(
1589  uint8_t REG_ADDR, //!< The register address.
1590  uint8_t LENGTH, //!< number of bytes.
1591  uint8_t *BYTES //!< read bytes
1592 )
1593 {
1595  ? LTC2947_SpiRdBlock(REG_ADDR, LENGTH, BYTES)
1596  : LTC2947_I2CRdBlock(LTC2947_I2C_Slave_Addr, REG_ADDR, LENGTH, BYTES);
1597 }
1598 
1599 //! write byte array via I2C/SPI interface
1600 //! @return 0 if successful, 1 if not successful
1601 static inline int8_t LTC2947_WR_BYTES(
1602  uint8_t REG_ADDR, //!< The register address.
1603  uint8_t LENGTH, //!< number of bytes.
1604  uint8_t *BYTES //!< bytes to be written
1605 )
1606 {
1608  ? LTC2947_SpiWrBlock(REG_ADDR, LENGTH, BYTES)
1609  : LTC2947_I2CWrBlock(LTC2947_I2C_Slave_Addr, REG_ADDR, LENGTH, BYTES);
1610 }
1611 
1612 //! read single byte via I2C/SPI
1613 //! @return 0 if successful, 1 if not successful
1614 static inline int8_t LTC2947_RD_BYTE(
1615  uint8_t REG_ADDR, //!< The register address.
1616  uint8_t *RESULT //!< byte that was read
1617 )
1618 {
1620  ? LTC2947_SpiRdByte(REG_ADDR, RESULT)
1621  : LTC2947_I2CRdByte(LTC2947_I2C_Slave_Addr, REG_ADDR, RESULT);
1622 }
1623 
1624 //! write single byte via I2C
1625 //! @return 0 if successful, 1 if not successful
1626 static inline int8_t LTC2947_WR_BYTE(
1627  uint8_t REG_ADDR, //!< The register address.
1628  uint8_t VALUE //!< byte to be written
1629 )
1630 {
1632  ? LTC2947_SpiWrByte(REG_ADDR, VALUE)
1633  : LTC2947_I2CWrByte(LTC2947_I2C_Slave_Addr, REG_ADDR, VALUE);
1634 }
1635 /** @} */ // end of serial communication wrapper macros
1636 
1637 #endif // LTC2947_H
1638 
int32_t LTC2947_3BytesToInt32(byte *bytes)
converts an array of 3 bytes to 32-bit signed integer
Definition: LTC2947.cpp:282
double LTC2947_UnsignedBytesToDouble(uint8_t *unsignedBytes, uint8_t length, double lsb)
Converts an unsigned value of arbitrary number of bytes to a floating point value with the scaling fa...
Definition: LTC2947.cpp:137
void LTC2947_GPIO_PinMode(uint8_t mode)
Enables/disables the output driver on the GPIO pin Make sure LTC2947&#39;s page 0 is selected before call...
Definition: LTC2947.cpp:510
static int8_t LTC2947_RD_BYTES(uint8_t REG_ADDR, uint8_t LENGTH, uint8_t *BYTES)
read multiple bytes via I2C/SPI
Definition: LTC2947.h:1588
uint8_t LTC2947_Ara(uint8_t *svlAddr)
Sends the Alert Response address to the I2C bus and reads the response If two or more devices on the ...
Definition: LTC2947.cpp:533
void LTC2947_InitI2C(uint8_t slvAddr)
Initializes the LTC2947 library for I2C mode operation and configures the slave address see defines L...
Definition: LTC2947.cpp:85
uint32_t LTC2947_3BytesToUInt32(byte *bytes)
converts an array of 3 bytes to 32-bit unsigned integer
Definition: LTC2947.cpp:328
uint16_t LTC2947_2BytesToUInt16(byte *bytes)
Converts an array of 2 bytes to 16-bit unsigned integer.
Definition: LTC2947.cpp:342
void LTC2947_DoubleToBytes(double value, double lsb, uint8_t *bytes, uint8_t length)
Converts a floating point number that was scaled with a given LSB to an integer representation that w...
Definition: LTC2947.cpp:175
void LTC2947_SerialPrint64hex(uint64_t uint64Val)
Prints a 64-bit value in 16-character hexadecimal format with left padded zeros.
Definition: LTC2947.cpp:169
int8_t LTC2947_I2CWrBlock(uint8_t slvAddr, uint8_t regAddr, uint8_t length, uint8_t *values)
write byte array via I2C interface
Definition: LTC2947.cpp:414
uint8_t LTC2947_I2C_Slave_Addr
set by LTC2947_InitI2C to set slave address for I2C operation
Definition: LTC2947.cpp:83
void LTC2947_SetPageSelect(boolean page)
write LTC2947&#39;s page control register to selected one of two memory pages
Definition: LTC2947.cpp:598
uint32_t LTC2947_4BytesToUInt32(byte *bytes)
Converts an array of 4 bytes to 32-bit unsigned integer.
Definition: LTC2947.cpp:311
double LTC2947_BytesToDouble(uint8_t *bytes, uint8_t length, boolean sig, double lsb)
Converts a signed or unsigned value of arbitrary number of bytes to a floating point number...
Definition: LTC2947.cpp:121
void LTC2947_Read_Abs_C_E_TB(boolean accuSet1, double *C, boolean *signC, double *E, boolean *signE, double *TB)
Reads charge (C), energy (E) and time (TB) from the device.
Definition: LTC2947.cpp:622
static uint8_t address
Definition: DC2091A.ino:83
boolean LTC2947_GPIO_Read()
reads the current GPIO pin state Make sure LTC2947&#39;s page 0 is selected before calling this function...
Definition: LTC2947.cpp:526
int8_t LTC2947_I2CWrByte(uint8_t slvAddr, uint8_t regAddr, uint8_t value)
write single byte via I2C
Definition: LTC2947.cpp:469
int8_t LTC2947_SpiWrBlock(uint8_t address, uint8_t length, uint8_t *values)
writes block (array) of bytes to the SPI interface
Definition: LTC2947.cpp:358
void LTC2947_SerialPrint32hex(uint32_t val)
Prints a 32-bit value in 8-character hexadecimal format with left padded zeros.
Definition: LTC2947.cpp:163
int8_t LTC2947_I2CRdByte(uint8_t slvAddr, uint8_t regAddr, uint8_t *value)
read single byte via I2C
Definition: LTC2947.cpp:485
void LTC2947_GPIO_SetPinState(uint8_t val)
Sets the level of the output driver on the GPIO pin This has only an effect if the output driver is e...
Definition: LTC2947.cpp:518
int16_t LTC2947_2BytesToInt16(byte *bytes)
converts an array of 2 bytes to 16-bit signed integer
Definition: LTC2947.cpp:301
int8_t LTC2947_I2CRdBlock(uint8_t slvAddr, uint8_t regAddr, uint8_t length, uint8_t *values)
read multiple bytes via I2C
Definition: LTC2947.cpp:436
double LTC2947_SignedBytesToDouble(uint8_t *signedBytes, uint8_t length, double lsb)
Converts a signed value of arbitrary number of bytes to a floating point value with the scaling facto...
Definition: LTC2947.cpp:247
int8_t LTC2947_SpiRdBlock(uint8_t address, uint8_t length, uint8_t *values)
read array of bytes from the SPI interface
Definition: LTC2947.cpp:374
int32_t LTC2947_4BytesToInt32(byte *bytes)
Converts an array of 4 bytes to 32-bit signed integer.
Definition: LTC2947.cpp:265
boolean LTC2947_GetCurrentPageSelect()
reads LTC2947&#39;s page control register to determine the currently selected memory page ...
Definition: LTC2947.cpp:591
int8_t LTC2947_SpiRdByte(uint8_t address, uint8_t *value)
read single byte from SPI interface
Definition: LTC2947.cpp:402
boolean LTC2947_SPI_Mode_Enabled
controlled by LTC2947_InitI2C / LTC2947_InitSPI to switch between I2C / SPI mode
Definition: LTC2947.cpp:82
boolean LTC2947_Abs(uint8_t *bytes, uint8_t length)
Calculates the absolute value of a signed value with arbitrary number of bytes.
Definition: LTC2947.cpp:96
static int8_t LTC2947_WR_BYTES(uint8_t REG_ADDR, uint8_t LENGTH, uint8_t *BYTES)
write byte array via I2C/SPI interface
Definition: LTC2947.h:1601
const int16_t E
static int8_t LTC2947_WR_BYTE(uint8_t REG_ADDR, uint8_t VALUE)
write single byte via I2C
Definition: LTC2947.h:1626
void LTC2947_SerialPrint8hex(uint8_t val)
Prints a 8-bit value in 2-character hexadecimal format with left padded zeros.
Definition: LTC2947.cpp:152
void LTC2947_InitSPI()
Initializes the LTC2947 library for SPI mode operation.
Definition: LTC2947.cpp:91
int16_t LTC2947_wake_up()
Wake up LTC2947 from shutdown mode and measure the wakeup time.
Definition: LTC2947.cpp:567
void LTC2947_Read_C_E_TB(boolean accuSet1, double *C, double *E, double *TB)
Reads charge (C), energy (E) and time (TB) from the device.
Definition: LTC2947.cpp:649
void LTC2947_SerialPrint16hex(uint16_t val)
Prints a 16-bit value in 4-character hexadecimal format with left padded zeros.
Definition: LTC2947.cpp:157
static int8_t LTC2947_RD_BYTE(uint8_t REG_ADDR, uint8_t *RESULT)
read single byte via I2C/SPI
Definition: LTC2947.h:1614
static uint8_t values[4]
Definition: DC2218A.ino:117
void LTC2947_Read_I_P_V_TEMP_VCC(float *I, float *P, float *V, float *TEMP, float *VCC)
Reads current (I), power (P), voltage (V), temperature (TEMP) and supply voltage (VCC) from the devic...
Definition: LTC2947.cpp:603
int8_t LTC2947_SpiWrByte(uint8_t address, uint8_t value)
write single byte to SPI interface
Definition: LTC2947.cpp:390