| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

Functions | Variables
LTC2947.cpp File Reference
Power Monitors and Coulomb Counters » LTC2947 a high-precision power and energy monitor with an internal sense resistor supporting up to 30A.

Library for LTC2947: A high-precision power and energy monitor with an internal sense resistor supporting up to 30A. More...

## Detailed Description

Library for LTC2947: A high-precision power and energy monitor with an internal sense resistor supporting up to 30A.

Definition in file LTC2947.cpp.

Go to the source code of this file.

## Functions
void | LTC2947_InitI2C (uint8_t slvAddr)
| Initializes the LTC2947 library for I2C mode operation and configures the slave address see defines LTC2947_I2C_ADDR_LL to LTC2947_I2C_ADDR_RR for possible slave addresses. More...
void | LTC2947_InitSPI ()
| Initializes the LTC2947 library for SPI mode operation. More...
boolean | LTC2947_Abs (uint8_t *bytes, uint8_t length)
| Calculates the absolute value of a signed value with arbitrary number of bytes. More...
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. More...
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 factor lsb The input value must be usigned, use LTC2947_Abs to convert the bytes to an absolute (positive) value or use LTC2947_SignedBytesToDouble instead. More...
void | LTC2947_SerialPrint8hex (uint8_t val)
| Prints a 8-bit value in 2-character hexadecimal format with left padded zeros. More...
void | LTC2947_SerialPrint16hex (uint16_t val)
| Prints a 16-bit value in 4-character hexadecimal format with left padded zeros. More...
void | LTC2947_SerialPrint32hex (uint32_t val)
| Prints a 32-bit value in 8-character hexadecimal format with left padded zeros. More...
void | LTC2947_SerialPrint64hex (uint64_t uint64Val)
| Prints a 64-bit value in 16-character hexadecimal format with left padded zeros. More...
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 will be stored in the given byte array. More...
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 factor lsb The input value must be a signed format. More...
int32_t | LTC2947_4BytesToInt32 (byte *bytes)
| Converts an array of 4 bytes to 32-bit signed integer. More...
int32_t | LTC2947_3BytesToInt32 (byte *bytes)
| converts an array of 3 bytes to 32-bit signed integer More...
int16_t | LTC2947_2BytesToInt16 (byte *bytes)
| converts an array of 2 bytes to 16-bit signed integer More...
uint32_t | LTC2947_4BytesToUInt32 (byte *bytes)
| Converts an array of 4 bytes to 32-bit unsigned integer. More...
uint32_t | LTC2947_3BytesToUInt32 (byte *bytes)
| converts an array of 3 bytes to 32-bit unsigned integer More...
uint16_t | LTC2947_2BytesToUInt16 (byte *bytes)
| Converts an array of 2 bytes to 16-bit unsigned integer. More...
int8_t | LTC2947_SpiWrBlock (uint8_t address, uint8_t length, uint8_t *values)
| writes block (array) of bytes to the SPI interface More...
int8_t | LTC2947_SpiRdBlock (uint8_t address, uint8_t length, uint8_t *values)
| read array of bytes from the SPI interface More...
int8_t | LTC2947_SpiWrByte (uint8_t address, uint8_t value)
| write single byte to SPI interface More...
int8_t | LTC2947_SpiRdByte (uint8_t address, uint8_t *value)
| read single byte from SPI interface More...
int8_t | LTC2947_I2CWrBlock (uint8_t slvAddr, uint8_t regAddr, uint8_t length, uint8_t *values)
| write byte array via I2C interface More...
int8_t | LTC2947_I2CRdBlock (uint8_t slvAddr, uint8_t regAddr, uint8_t length, uint8_t *values)
| read multiple bytes via I2C More...
int8_t | LTC2947_I2CWrByte (uint8_t slvAddr, uint8_t regAddr, uint8_t value)
| write single byte via I2C More...
int8_t | LTC2947_I2CRdByte (uint8_t slvAddr, uint8_t regAddr, uint8_t *value)
| read single byte via I2C More...
void | LTC2947_GPIO_PinMode (uint8_t mode)
| Enables/disables the output driver on the GPIO pin Make sure LTC2947's page 0 is selected before calling this function. More...
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 enabled, see LTC2947_GPIO_PinMode Make sure LTC2947's page 0 is selected before calling this function. More...
boolean | LTC2947_GPIO_Read ()
| reads the current GPIO pin state Make sure LTC2947's page 0 is selected before calling this function. More...
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 same bus are generating alerts when the ARA is broadcasted, standard I2C arbitra- tion causes the device with the highest priority (lowest address) to reply first and the device with the lowest pri- ority (highest address) to reply last.The bus master will repeat the alert response protocol until the ALERT line is released. More...
int16_t | LTC2947_wake_up ()
| Wake up LTC2947 from shutdown mode and measure the wakeup time. More...
boolean | LTC2947_GetCurrentPageSelect ()
| reads LTC2947's page control register to determine the currently selected memory page More...
void | LTC2947_SetPageSelect (boolean page)
| write LTC2947's page control register to selected one of two memory pages More...
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 device Make sure LTC2947's page 0 is selected before calling this function. More...
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. More...
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. More...

## Variables
boolean | LTC2947_SPI_Mode_Enabled = false
| controlled by LTC2947_InitI2C / LTC2947_InitSPI to switch between I2C / SPI mode More...
uint8_t | LTC2947_I2C_Slave_Addr = LTC2947_I2C_ADDR_LL
| set by LTC2947_InitI2C to set slave address for I2C operation More...

## Function Documentation

## ◆ LTC2947_2BytesToInt16()

int16_t LTC2947_2BytesToInt16 | ( | byte * | bytes | ) |

converts an array of 2 bytes to 16-bit signed integer

Returns
  16-bit signed integer

Parameters

  bytes | 2 byte array (MSB first)

Definition at line 301 of file LTC2947.cpp.

## ◆ LTC2947_2BytesToUInt16()

uint16_t LTC2947_2BytesToUInt16 | ( | byte * | bytes | ) |

Converts an array of 2 bytes to 16-bit unsigned integer.

Returns
  16-bit unsigned integer

Parameters

  bytes | 2 byte array (MSB first)

Definition at line 342 of file LTC2947.cpp.

## ◆ LTC2947_3BytesToInt32()

int32_t LTC2947_3BytesToInt32 | ( | byte * | bytes | ) |

converts an array of 3 bytes to 32-bit signed integer

Returns
  32-bit signed integer

Parameters

  bytes | 3 byte array (MSB first)

Definition at line 282 of file LTC2947.cpp.

## ◆ LTC2947_3BytesToUInt32()

uint32_t LTC2947_3BytesToUInt32 | ( | byte * | bytes | ) |

converts an array of 3 bytes to 32-bit unsigned integer

Returns
  32-bit unsigned integer

Parameters

  bytes | 3 byte array (MSB first)

Definition at line 328 of file LTC2947.cpp.

## ◆ LTC2947_4BytesToInt32()

int32_t LTC2947_4BytesToInt32 | ( | byte * | bytes | ) |

Converts an array of 4 bytes to 32-bit signed integer.

Returns
  32-bit signed integer

Parameters

  bytes | 4 byte array (MSB first)

Definition at line 265 of file LTC2947.cpp.

## ◆ LTC2947_4BytesToUInt32()

uint32_t LTC2947_4BytesToUInt32 | ( | byte * | bytes | ) |

Converts an array of 4 bytes to 32-bit unsigned integer.

Returns
  32-bit unsigned integer

Parameters

  bytes | 4 byte array (MSB first)

Definition at line 311 of file LTC2947.cpp.

## ◆ LTC2947_Abs()

boolean LTC2947_Abs | ( | uint8_t * | bytes,
|  | uint8_t | length
| ) |  |

Calculates the absolute value of a signed value with arbitrary number of bytes.

Returns
  true: value was inverted, false: value was already positive

Parameters

  bytes | bytes of the signed value (MSB first)
  length | number of bytes

Definition at line 96 of file LTC2947.cpp.

## ◆ LTC2947_Ara()

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 same bus are generating alerts when the ARA is broadcasted, standard I2C arbitra- tion causes the device with the highest priority (lowest address) to reply first and the device with the lowest pri- ority (highest address) to reply last.The bus master will repeat the alert response protocol until the ALERT line is released.

Returns
  LTC2947_ARA_ERROR : general I2C communication error LTC2947_ARA_LTC2947_RESPONSE : got ARA response from LTC2947 LTC2947_ARA_OTHER_RESPONSE : got ARA response from some other I2C slave LTC2947_ARA_NO_RESPONSE : got NO ARA response LTC2947_ARA_RESPONSE_WO_WR : got ARA response from any slave but wihtout the expected WR bit

Parameters

  svlAddr | 7-bit address of the responding slave

Definition at line 533 of file LTC2947.cpp.

## ◆ LTC2947_BytesToDouble()

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.

Returns
  result in floating point number format.

Parameters

  bytes | input value as byte array (MSB first)
  length | number of bytes of the input value
  sig | true for signed value, false for unsigned
  lsb | lsb value (scaling factor used to scale the input value)

Definition at line 121 of file LTC2947.cpp.

## ◆ LTC2947_DoubleToBytes()

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 will be stored in the given byte array.

Parameters

  value | floating point value
  lsb | lsb of the floating point value (integer = value / lsb)
  bytes | byte array of the integer representation
  length | length (<=8) of the byte array. Note: The function does not check for overflow of the integer representation

Definition at line 175 of file LTC2947.cpp.

## ◆ LTC2947_GetCurrentPageSelect()

boolean LTC2947_GetCurrentPageSelect | ( |  | ) |

reads LTC2947's page control register to determine the currently selected memory page

Returns
  true: page 1 is selected, false: page 0

Definition at line 591 of file LTC2947.cpp.

## ◆ LTC2947_GPIO_PinMode()

void LTC2947_GPIO_PinMode | ( | uint8_t | mode | ) |

Enables/disables the output driver on the GPIO pin Make sure LTC2947's page 0 is selected before calling this function.

Use LTC2947_SetPageSelect to change page if necessary

Parameters

  mode | OUTPUT (1): output driver enabled, INPUT (0): output driver disabled

Definition at line 510 of file LTC2947.cpp.

## ◆ LTC2947_GPIO_Read()

boolean LTC2947_GPIO_Read | ( |  | ) |

reads the current GPIO pin state Make sure LTC2947's page 0 is selected before calling this function.

Use LTC2947_SetPageSelect to change page if necessary

Returns
  true: pin high, false: pin low

Definition at line 526 of file LTC2947.cpp.

## ◆ LTC2947_GPIO_SetPinState()

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 enabled, see LTC2947_GPIO_PinMode Make sure LTC2947's page 0 is selected before calling this function.

Use LTC2947_SetPageSelect to change page if necessary

Parameters

  val | LOW (0): pin low, HIGH (1): pin high

Definition at line 518 of file LTC2947.cpp.

## ◆ LTC2947_I2CRdBlock()

int8_t LTC2947_I2CRdBlock | ( | uint8_t | slvAddr,
|  | uint8_t | regAddr,
|  | uint8_t | length,
|  | uint8_t * | values
| ) |  |

read multiple bytes via I2C

Returns
  0 if successful, 1 if not successful

Parameters

  slvAddr | The slv address.
  regAddr | The register address.
  length | number of bytes.
  values | read bytes

Definition at line 436 of file LTC2947.cpp.

## ◆ LTC2947_I2CRdByte()

int8_t LTC2947_I2CRdByte | ( | uint8_t | slvAddr,
|  | uint8_t | regAddr,
|  | uint8_t * | value
| ) |  |

read single byte via I2C

Returns
  0 if successful, 1 if not successful

Parameters

  slvAddr | The slv address.
  regAddr | The register address.
  value | byte that was read

Definition at line 485 of file LTC2947.cpp.

## ◆ LTC2947_I2CWrBlock()

int8_t LTC2947_I2CWrBlock | ( | uint8_t | slvAddr,
|  | uint8_t | regAddr,
|  | uint8_t | length,
|  | uint8_t * | values
| ) |  |

write byte array via I2C interface

Returns
  0 if successful, 1 if not successful

Parameters

  slvAddr | The slv address.
  regAddr | The register address.
  length | number of bytes.
  values | bytes to be written

Definition at line 414 of file LTC2947.cpp.

## ◆ LTC2947_I2CWrByte()

int8_t LTC2947_I2CWrByte | ( | uint8_t | slvAddr,
|  | uint8_t | regAddr,
|  | uint8_t | value
| ) |  |

write single byte via I2C

Returns
  0 if successful, 1 if not successful

Parameters

  slvAddr | The slv address.
  regAddr | The register address.
  value | byte to be written

Definition at line 469 of file LTC2947.cpp.

## ◆ LTC2947_InitI2C()

void LTC2947_InitI2C | ( | uint8_t | slvAddr | ) |

Initializes the LTC2947 library for I2C mode operation and configures the slave address see defines LTC2947_I2C_ADDR_LL to LTC2947_I2C_ADDR_RR for possible slave addresses.

Parameters

  slvAddr | 7-bit I2C slave address of the LTC2947 (e.g. LTC2947_I2C_ADDR_LL)

Definition at line 85 of file LTC2947.cpp.

## ◆ LTC2947_InitSPI()

void LTC2947_InitSPI | ( |  | ) |

Initializes the LTC2947 library for SPI mode operation.

Definition at line 91 of file LTC2947.cpp.

## ◆ LTC2947_Read_Abs_C_E_TB()

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.

Charge and Energy are converted to absulte values (always positive!) and a separate sign bit. If the separation in absolute value and sign is not desired use LTC2947_Read_C_E_TB instead. Make sure LTC2947's page 0 is selected before calling this function. Use LTC2947_SetPageSelect to change page if necessary

Parameters

  accuSet1 | True: Read C1, E1, TB1. False: Read C2, E2, TB2.
  C | Absolute value of charge in As
  signC | Sign of charge (True: negative, False: positive)
  E | Absolute value of energy in Ws
  signE | Sign of energy (True: negative, False: positive)
  TB | Time in s

Definition at line 622 of file LTC2947.cpp.

## ◆ LTC2947_Read_C_E_TB()

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.

Make sure LTC2947's page 0 is selected before calling this function. Use LTC2947_SetPageSelect to change page if necessary

Parameters

  accuSet1 | True: Read C1, E1, TB1. False: Read C2, E2, TB2.
  C | Signed charge in As
  E | Signed energy in Ws
  TB | Time in s

Definition at line 649 of file LTC2947.cpp.

## ◆ LTC2947_Read_I_P_V_TEMP_VCC()

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 device Make sure LTC2947's page 0 is selected before calling this function.

Use LTC2947_SetPageSelect to change page if necessary

Parameters

  I | Current im amps
  P | Power in watts
  V | Voltage in volts
  TEMP | Temperature in degree celcius
  VCC | Supply voltage in volts

Definition at line 603 of file LTC2947.cpp.

## ◆ LTC2947_SerialPrint16hex()

void LTC2947_SerialPrint16hex | ( | uint16_t | val | ) |

Prints a 16-bit value in 4-character hexadecimal format with left padded zeros.

Parameters

  val | 16-bit input value

Definition at line 157 of file LTC2947.cpp.

## ◆ LTC2947_SerialPrint32hex()

void LTC2947_SerialPrint32hex | ( | uint32_t | val | ) |

Prints a 32-bit value in 8-character hexadecimal format with left padded zeros.

Parameters

  val | 32-bit input value

Definition at line 163 of file LTC2947.cpp.

## ◆ LTC2947_SerialPrint64hex()

void LTC2947_SerialPrint64hex | ( | uint64_t | uint64Val | ) |

Prints a 64-bit value in 16-character hexadecimal format with left padded zeros.

Parameters

  uint64Val | 64-bit input value

Definition at line 169 of file LTC2947.cpp.

## ◆ LTC2947_SerialPrint8hex()

void LTC2947_SerialPrint8hex | ( | uint8_t | val | ) |

Prints a 8-bit value in 2-character hexadecimal format with left padded zeros.

Parameters

  val | 8-bit input value

Definition at line 152 of file LTC2947.cpp.

## ◆ LTC2947_SetPageSelect()

void LTC2947_SetPageSelect | ( | boolean | page | ) |

write LTC2947's page control register to selected one of two memory pages

Parameters

  page | false: select page 0, true: select page 1

Definition at line 598 of file LTC2947.cpp.

## ◆ LTC2947_SignedBytesToDouble()

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 factor lsb The input value must be a signed format.

For unsigned values use LTC2947_UnsignedBytesToDouble. For input values with up to 4 bytes use LTC2947_<X>BytesToInt<N> (e.g. LTC2947_4BytesToInt32, LTC2947_2BytesToInt16) and multiply the result by lsb for reduced calculation time, e.g. "LTC2947_4BytesToInt32(bytes)*lsb".

Returns
  result in floating point number format.

Parameters

  signedBytes | signed input value as byte array (MSB first)
  length | number of bytes of the signed value
  lsb | lsb value (scaling factor used to scale the signed value)

Definition at line 247 of file LTC2947.cpp.

## ◆ LTC2947_SpiRdBlock()

int8_t LTC2947_SpiRdBlock | ( | uint8_t | address,
|  | uint8_t | length,
|  | uint8_t * | values
| ) |  |

read array of bytes from the SPI interface

Returns
  always 0

Parameters

  address | register address
  length | Length of array
  values | Byte array to store read bytes

Definition at line 374 of file LTC2947.cpp.

## ◆ LTC2947_SpiRdByte()

int8_t LTC2947_SpiRdByte | ( | uint8_t | address,
|  | uint8_t * | value
| ) |  |

read single byte from SPI interface

Returns
  always 0

Parameters

  address | register address
  value | Byte pointer to store read byte

Definition at line 402 of file LTC2947.cpp.

## ◆ LTC2947_SpiWrBlock()

int8_t LTC2947_SpiWrBlock | ( | uint8_t | address,
|  | uint8_t | length,
|  | uint8_t * | values
| ) |  |

writes block (array) of bytes to the SPI interface

Returns
  always 0

Parameters

  address | register address
  length | Length of array
  values | Byte array to be written

Definition at line 358 of file LTC2947.cpp.

## ◆ LTC2947_SpiWrByte()

int8_t LTC2947_SpiWrByte | ( | uint8_t | address,
|  | uint8_t | value
| ) |  |

write single byte to SPI interface

Returns
  always 0

Parameters

  address | register address
  value | Byte to be written

Definition at line 390 of file LTC2947.cpp.

## ◆ LTC2947_UnsignedBytesToDouble()

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 factor lsb The input value must be usigned, use LTC2947_Abs to convert the bytes to an absolute (positive) value or use LTC2947_SignedBytesToDouble instead.

For input values with up to 4 bytes use LTC2947_<X>BytesToUInt<N> (e.g. LTC2947_4BytesToUInt32, LTC2947_2BytesToUInt16) and multiply the result by lsb for reduced calculation time, e.g. "LTC2947_4BytesToUInt32(bytes)*lsb".

Returns
  result in floating point number format (absolute value, so always positive!)

Parameters

  unsignedBytes | unsigned input value as byte array (MSB first)
  length | number of bytes of the unsigned value
  lsb | lsb value (scaling factor used to scale the unsigned value)

Definition at line 137 of file LTC2947.cpp.

## ◆ LTC2947_wake_up()

int16_t LTC2947_wake_up | ( |  | ) |

Wake up LTC2947 from shutdown mode and measure the wakeup time.

Returns
  -1 in case of timeout or milliseconds it took to wakeup LTC2947

Definition at line 567 of file LTC2947.cpp.

## Variable Documentation

## ◆ LTC2947_I2C_Slave_Addr

uint8_t LTC2947_I2C_Slave_Addr = LTC2947_I2C_ADDR_LL

set by LTC2947_InitI2C to set slave address for I2C operation

Definition at line 83 of file LTC2947.cpp.

## ◆ LTC2947_SPI_Mode_Enabled

boolean LTC2947_SPI_Mode_Enabled = false

controlled by LTC2947_InitI2C / LTC2947_InitSPI to switch between I2C / SPI mode

Definition at line 82 of file LTC2947.cpp.