LTC4261 - Negative Voltage Hot Swap Controllers with ADC and I²C Monitoring

Features

  • Allows Safe Insertion into Live –48V Backplanes
  • 10-Bit ADC Monitors Current and Voltages
  • I2C/SMBus Interface or Single-Wire Broadcast Mode
  • Floating Topology Allows Very High Voltage Operation
  • Independently Adjustable Inrush and Overcurrent Limits
  • Controlled Soft-Start Inrush
  • Adjustable UV/OV Thresholds and Hysteresis
  • Sequenced Power Good Outputs with Delays
  • Adjustable Power Good Input Timeout
  • Programmable Latchoff or Auto-Retry After Faults
  • Alerts Host After Faults
  • Available in 28-Lead Narrow SSOP and 24-Lead (4mm × 5mm) QFN Packages

Typical Application

LTC4261 Typical Application
LTC4261 Typical Application

Description

The LTC®4261/LTC4261-2 negative voltage Hot SwapTM controllers allow a board to be safely inserted and removed from a live backplane. Using an external N-channel pass transistor, the board supply voltage can be ramped at an adjustable rate. The devices feature independently adjustable inrush current and overcurrent limits to minimize stresses on the pass transistor during start-up, input step and output short conditions. The LTC4261 defaults to latch-off while the LTC4261-2 defaults to auto-retry on overcurrent faults.

An I2C interface and onboard 10-bit ADC allow monitoring of board current, voltage and fault status. A single-wire broadcast mode is available to simplify the interface by eliminating two optoisolators.

The controllers have additional features to interrupt the host when a fault has occurred, notify when output power is good, detect insertion of a board and turn off the pass transistor if an external supply monitor fails to indicate power good within a timeout period.

Packaging

CAD Symbols and Footprints: The downloadable Zip file below contains the schematic symbol and PCB footprints.

For complete and up to date package information and drawings, please refer to our packaging page

Part Number Package Code Temp Package
Drawing
RoHS
LTC4261CGN-2#PBF SSOP-28 GN C 05-08-1641 (GN28) Yes
LTC4261CGN-2#TRPBF SSOP-28 GN C 05-08-1641 (GN28) Yes
LTC4261CGN#PBF SSOP-28 GN C 05-08-1641 (GN28) Yes
LTC4261CGN#TRPBF SSOP-28 GN C 05-08-1641 (GN28) Yes
LTC4261CUFD-2#PBF 4x5 QFN-24 UFD C 05-08-1696 Yes
LTC4261CUFD-2#TRPBF 4x5 QFN-24 UFD C 05-08-1696 Yes
LTC4261CUFD#PBF 4x5 QFN-24 UFD C 05-08-1696 Yes
LTC4261CUFD#TRPBF 4x5 QFN-24 UFD C 05-08-1696 Yes
LTC4261IGN-2#PBF SSOP-28 GN I 05-08-1641 (GN28) Yes
LTC4261IGN-2#TRPBF SSOP-28 GN I 05-08-1641 (GN28) Yes
LTC4261IGN#PBF SSOP-28 GN I 05-08-1641 (GN28) Yes
LTC4261IGN#TRPBF SSOP-28 GN I 05-08-1641 (GN28) Yes
LTC4261IUFD-2#PBF 4x5 QFN-24 UFD I 05-08-1696 Yes
LTC4261IUFD-2#TRPBF 4x5 QFN-24 UFD I 05-08-1696 Yes
LTC4261IUFD#PBF 4x5 QFN-24 UFD I 05-08-1696 Yes
LTC4261IUFD#TRPBF 4x5 QFN-24 UFD I 05-08-1696 Yes


LTC4261 Package Drawing
LTC4261 Package Drawing

Order Info

  • Part numbers ending in PBF are lead free. Solder plated terminal finish (SnPb) versions are non-standard and special terms and conditions and pricing applies if available. Please contact LTC marketing for information.
  • Part numbers containing TR or TRM are shipped in tape and reel or 500 unit mini tape and reel, respectively
  • Please refer to our general ordering information or the product datasheet for more details

Package Variations and Pricing

Part Number Package Temp Price
(1-99)
Price
(1k)*
RoHS
LTC4261CGN-2#PBF SSOP-28 C $8.50 $5.95 Yes
LTC4261CGN-2#TRPBF SSOP-28 C $6.01 Yes
LTC4261CGN#PBF SSOP-28 C $8.50 $5.95 Yes
LTC4261CGN#TRPBF SSOP-28 C $6.05 Yes
LTC4261CUFD-2#PBF 4x5 QFN-24 C $8.50 $5.95 Yes
LTC4261CUFD-2#TRPBF 4x5 QFN-24 C $6.01 Yes
LTC4261CUFD#PBF 4x5 QFN-24 C $8.50 $5.95 Yes
LTC4261CUFD#TRPBF 4x5 QFN-24 C $6.05 Yes
LTC4261IGN-2#PBF SSOP-28 I $10.21 $7.15 Yes
LTC4261IGN-2#TRPBF SSOP-28 I $7.21 Yes
LTC4261IGN#PBF SSOP-28 I $10.21 $7.15 Yes
LTC4261IGN#TRPBF SSOP-28 I $7.25 Yes
LTC4261IUFD-2#PBF 4x5 QFN-24 I $10.21 $7.15 Yes
LTC4261IUFD-2#TRPBF 4x5 QFN-24 I $7.21 Yes
LTC4261IUFD#PBF 4x5 QFN-24 I $10.21 $7.15 Yes
LTC4261IUFD#TRPBF 4x5 QFN-24 I $7.25 Yes
Buy NowRequest Samples
* The USA list pricing shown is for BUDGETARY USE ONLY, shown in United States dollars (FOB USA per unit for the stated volume), and is subject to change. International prices may differ due to local duties, taxes, fees and exchange rates. For volume-specific price or delivery quotes, please contact your local Linear Technology sales office or authorized distributor.

Demo Boards

Linear Technology offers many demo boards free of charge to qualified customers. Contact your local sales office or distributor to inquire about a demo board. Certain demo boards are also available for sale via credit card on this website. Demo boards are for evaluation purposes only. It remains the customer’s responsibility to verify proper and reliable operation in the actual end application.

Part Number Description Price Documentation
DC998A LTC4261 -48V Hot Swap w/ADC (req DC590) $100.00
Buy Now

Companion Boards

Part Number Description Price Documentation
DC2026C Linduino One Isolated USB Demo Board: An Arduino- and QuikEval-Compatible Code Development Platform $75.00
DC590B Isolated USB Serial Controller for Linear Technology QuikEval-Compatible Demo Boards $50.00
Buy Now
Click here to view our complete list of demo boards

Applications

  • AdvancedTCA Systems
  • Telecom Infrastructure
  • –48V Distributed Power Systems
  • Power Monitors

Product Notifications

Please login to your MyLinear account for notifications of datasheet updates, new document releases and LTspice model announcements for your favorite products. If you do not have a MyLinear account you may Sign Up Now.

Forgot your password? Click here.
Need help? Email mylinear@linear.com with questions and comments.

Design Tools

LTspice

LTspice® software is a powerful, fast and free simulation tool, schematic capture and waveform viewer with enhancements and models for improving the simulation of switching regulators. Click here to download LTspice

To launch a ready to run LTspice demonstration circuit for this part:

  • Step 1: If you have not installed LTspice on this computer, download and install LTspice
  • Step 2: Once LTspice is installed, click on the link(s) below to launch the simulation
  • Step 3: If LTspice does not automatically open after clicking the link above, you can instead run the simulation by right clicking on the link and selecting "Save Target As." After saving the file to your computer, start LTspice and open the demonstration circuit by selecting 'Open' from the 'File' menu

To explore other ready to run LTspice demonstration circuits, please visit our Demo Circuits Collection.

Models for the following parts are available in LTspice:
LTC4261

Linduino

Linduino is an Arduino compatible platform for developing and distributing firmware libraries and code for SPI and I²C-compatible integrated circuits. The Linduino One board interfaces to more than 300 QuikEval demonstration cards, supporting a variety of product types including analog-to-digital converters (ADCs)digital-to-analog converters (DACs)power monitors, and more. Firmware libraries for individual devices are written in C and designed to be portable to a wide variety of processors and microcontrollers. Each library has a demonstration program that can be uploaded to the Linduino One platform to allow the circuit and software to be quickly and easily verified.

Click here for more information on Linduino

Code

Linduino is Linear Technology's Arduino compatible system for developing and distributing firmware libraries and example code for Linear Technology’s integrated circuits. The code below can be downloaded or copied and pasted into your project. Please visit the Linduino Home Page for demo board, manual and setup information.

This part is Code Supported: There is example code available for this part. The code below may rely on other drivers available in the full library.

Download LTC4261 - DC998A Linduino.INO File

/*!
Linear Technology DC998A Demonstration Board.
LTC4261: Negative Voltage Hot Swap Controllers with ADC and I2C Monitoring.

@verbatim

NOTES
  Setup:
   Set the terminal baud rate to 115200 and select the newline terminator. Provide
   the board with an external power supply of -48 V. Ensure all jumpers on the
   demo board are installed in their default positions from the factory. Refer to
   Demo Manual DC998A.

   This program has options to measure voltage at ADIN pin (input voltage), SOURCE
   VOLTAGE (output voltage), and SENSE CURRENT (current through sense resisitor).
   There are also options to read and manipulate CONTROL register, ALERT register,
   and FAULT register.

   Mass write option can be achieved using Device Address = 0xBE. Refer to datasheet
   LTC4261.

USER INPUT DATA FORMAT:
 decimal : 1024
 hex     : 0x400
 octal   : 02000  (leading 0 "zero")
 binary  : B10000000000
 float   : 1024.0

@endverbatim

http://www.linear.com/product/LTC4261

http://www.linear.com/product/LTC4261#demoboards

REVISION HISTORY
$Revision: 3238 $
$Date: 2015-03-06 16:40:13 -0800 (Fri, 06 Mar 2015) $

Copyright (c) 2013, Linear Technology Corp.(LTC)
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of Linear Technology Corp.

The Linear Technology Linduino is not affiliated with the official Arduino team.
However, the Linduino is only possible because of the Arduino team's commitment
to the open-source community.  Please, visit http://www.arduino.cc and
http://store.arduino.cc , and consider a purchase that will help fund their
ongoing work.
*/

/*! @file
    @ingroup LTC4261
*/

// Headerfiles
#include <Arduino.h>
#include <stdint.h>
#include "Linduino.h"
#include "LT_I2C.h"
#include "LT_SPI.h"
#include "UserInterface.h"
#include "QuikEval_EEPROM.h"
#include "LTC4261.h"
#include <Wire.h>
#include <SPI.h>

// Function Declarations
void print_title();
void print_main_menu();
int8_t main_menu_1_continuous_mode();
int8_t main_menu_2_read_and_clear_faults();
int8_t main_menu_3_send_ARA();
int8_t main_menu_4_manage_alerts();
int8_t main_menu_5_settings();
int8_t main_menu_6_read_all_registers();

// Global Constants
const float resistor = .008;
const float current_lsb = 62.5E-06;
const float adin_lsb =  2.56/1023;    // Vref of ADC = 2.56V and 2^10 - 1 = 1023 (10 bit ADC.)
const float resistive_ratio = 432.2 / 10.2;
// Global Variables
static int8_t demo_board_connected; //!< Set to 1 if the board is connected
//static uint8_t alert_code = 0;      //!< Value stored or read from ALERT register.  Shared between loop() and restore_alert_settings()
const char ack_error[] = "Error: No Acknowledge. Check I2C Address."; //!< Error message

//! Initialize Linduino
void setup()
{
  char demo_name[] = "DC998A";      // Demo Board Name stored in QuikEval EEPROM
  quikeval_I2C_init();              //! Configure the EEPROM I2C port for 100kHz
  quikeval_I2C_connect();           //! Connects to main I2C port
  Serial.begin(115200);             //! Initialize the serial port to the PC
  print_title();
  demo_board_connected = discover_demo_board(demo_name);
  print_main_menu();
}

//! Repeats Linduino loop
void loop()
{
  if (demo_board_connected)
  {
    int8_t ack = 0;                            // I2C acknowledge indicator
    static uint8_t user_command;               // The user input command
    if (Serial.available())                     //! Do nothing if serial is not available
    {
      user_command = read_int();                //! Read user input command
      if (user_command != 'm')
        Serial.println(user_command);
      Serial.println();
      ack = 0;
      switch (user_command)                     //! Prints the appropriate submenu
      {
        case 1:
          ack |= main_menu_1_continuous_mode();       // continous mode
          break;
        case 2:
          ack |= main_menu_2_read_and_clear_faults(); // read and clear faults
          break;
        case 3:
          ack |= main_menu_3_send_ARA();// read address of alert
          break;
        case 4:
          ack |= main_menu_4_manage_alerts();         // manage alerts
          break;
        case 5:
          ack |= main_menu_5_settings();              // settings
          break;
        case 6:
          ack |= main_menu_6_read_all_registers();
          break;
        default:
          Serial.println("Incorrect Option");
          break;
      }
      if (ack != 0)
        Serial.println(ack_error);
      Serial.print(F("*****************************************"));
      print_main_menu();
    }
  }
}

//! Print the title block
void print_title()
{
  Serial.println(F("\n*****************************************************************"));
  Serial.print(F("* DC998A Demonstration Program                                  *\n"));
  Serial.print(F("*                                                               *\n"));
  Serial.print(F("* This program demonstrates how to send and receive data from   *\n"));
  Serial.print(F("* the Negative Voltage Hot Swap Controllers                     *\n"));
  Serial.print(F("* with ADC and I2C Monitoring                                   *\n"));
  Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
  Serial.print(F("*                                                               *\n"));
  Serial.print(F("*****************************************************************\n"));
}

//! Print the main menu
void print_main_menu()
{
  Serial.print(F("\n\nMain Menu\n"));
  Serial.print(F("  1. Read current and voltage on continous mode\n"));
  Serial.print(F("  2. Read and clear faults\n"));
  Serial.print(F("  3. Request for alert response address (ARA)\n"));
  Serial.print(F("  4. Manage alerts\n"));
  Serial.print(F("  5. Settings\n"));
  Serial.print(F("  6. Read all registers\n\n"));
  Serial.print(F("Enter a command: "));
}

//! Function to read Rsense current, ADIN voltage and ADIN2 voltage in continous mode
int8_t main_menu_1_continuous_mode()
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
{
  int8_t ack = 0;
  float current, adin_voltage, adin2_voltage;
  uint16_t current_code, adin_code, adin2_code;

  do
  {
    uint8_t faults;
    Serial.print(F("********** Press Enter to Exit ***********\n\n"));
    ack |= LTC4261_read(LTC4261_I2C_Address, LTC4261_FAULT_REG, &faults);
    if (faults != 0)
    {
      Serial.println(F("Faults Detected :"));
      if (faults & LTC4261_EXTERNAL_FAULT )
        Serial.println(F("  EXTERNAL FAULT DETECTED"));
      if (faults & LTC4261_PGIO_INPUT_HIGH )
        Serial.println(F("  PGIO INPUT HIGH DETECTED"));
      if (faults & LTC4261_FET_SHORT_FAULT )
        Serial.println(F("  FET SHORT DETECTED"));
      if (faults & LTC4261_EN_STATE_CHANGE)
        Serial.println(F("  !EN STATE CHANGE DETECTED"));
      if (faults & LTC4261_POWER_BAD_FAULT )
        Serial.println(F("  BAD POWER DETECTED"));
      if (faults & LTC4261_OVERCURRENT_FAULT )
        Serial.println(F("  OVERCURRENT DETECTED"));
      if (faults & LTC4261_UNDERVOLTAGE_FAULT )
        Serial.println(F("  UNDERVOLTAGE DETECTED"));
      if (faults & LTC4261_OVERVOLTAGE_FAULT )
        Serial.println(F("  OVERVOLTAGE DETECTED"));
    }
    else
      Serial.println(F("  NO FAULTS DETECTED"));

    ack |= LTC4261_read_10_bits(LTC4261_I2C_Address, LTC4261_SENSE_MSB_REG, &current_code);
    ack |= LTC4261_read_10_bits(LTC4261_I2C_Address, LTC4261_ADIN_MSB_REG, &adin_code);
    ack |= LTC4261_read_10_bits(LTC4261_I2C_Address, LTC4261_ADIN2_MSB_REG, &adin2_code);

    current = LTC4261_code_to_current(current_code, resistor, current_lsb);
    adin_voltage = LTC4261_ADIN_code_to_voltage(adin_code, adin_lsb, resistive_ratio);
    adin2_voltage = LTC4261_ADIN_code_to_voltage(adin2_code, adin_lsb, resistive_ratio);

    Serial.print(F("\nCURRENT CODE: "));
    Serial.println(current_code);
    Serial.print(F("CURRENT CALCULATED: "));
    Serial.println(current,4);
    Serial.print(F("\nADIN CODE: "));
    Serial.println(adin_code, HEX);
    Serial.print(F("VOLTAGE CALCULATED BY ADIN: "));
    Serial.println(adin_voltage,4);
    Serial.print(F("\nADIN2 CODE: "));
    Serial.println(adin2_code, HEX);
    Serial.print(F("VOLTAGE CALCULATED BY ADIN2: "));
    Serial.println(adin2_voltage,4);
    Serial.print("\n");
    delay(2000);
  }
  while (Serial.available()==false && ack== 0);
  if (Serial.available())
    read_int(); // clears the Serial.available()
  return (ack);
}

//! Function to read and clear fault register
int8_t main_menu_2_read_and_clear_faults()
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
{
  int8_t ack = 0;

  uint8_t faults;
  ack |= LTC4261_read(LTC4261_I2C_Address, LTC4261_FAULT_REG, &faults);
  if (faults != 0)
  {
    Serial.println(F("Faults Detected :"));
    if (faults & LTC4261_EXTERNAL_FAULT)
      Serial.println(F("  EXTERNAL FAULT DETECTED"));
    if (faults & LTC4261_PGIO_INPUT_HIGH)
      Serial.println(F("  PGIO INPUT HIGH DETECTED"));
    if (faults & LTC4261_FET_SHORT_FAULT)
      Serial.println(F("  FET SHORT DETECTED"));
    if (faults & LTC4261_EN_STATE_CHANGE)
      Serial.println(F("  !EN STATE CHANGE DETECTED"));
    if (faults & LTC4261_POWER_BAD_FAULT)
      Serial.println(F("  BAD POWER DETECTED"));
    if (faults & LTC4261_OVERCURRENT_FAULT)
      Serial.println(F("  OVERCURRENT DETECTED"));
    if (faults & LTC4261_UNDERVOLTAGE_FAULT)
      Serial.println(F("  UNDERVOLTAGE DETECTED"));
    if (faults & LTC4261_OVERVOLTAGE_FAULT)
      Serial.println(F("  OVERVOLTAGE DETECTED"));
  }
  ack |= LTC4261_write(LTC4261_I2C_Address, LTC4261_FAULT_REG, 0x00);
  Serial.print(F("  ALL FAULTS CLEARED \n\n"));

  return (ack);
}
//! Function to send alert response (0001100) and read back the address of device that pulled ALERT pin low.
int8_t main_menu_3_send_ARA()
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
{
  int8_t ack = 0;
  uint8_t address;
  ack |=LTC4261_ARA(LTC4261_I2C_ALERT_RESPONSE, &address);// send ARA
  Serial.print(F("  ALERT RESPONSE ADDRESS : 0x"));
  Serial.println(address,HEX);
  if (address == 0xFF && ack == 1)
  {
    ack = 0;
    Serial.print(F("  NO RESPONSE\n\n"));
  }
  return(ack);
}

//! Function to update alert register bits
int8_t main_menu_4_manage_alerts()
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
{
  int8_t ack = 0;
  uint8_t alert_settings = 0;
  int8_t user_command;
  do
  {
    Serial.println(F("EXTERNAL FAULT ALERT"));
    Serial.println(F("  1. Enable"));
    Serial.println(F("  2. Disable"));
    Serial.print(F("Enter a command: "));
    user_command = read_int();
    if (user_command == 'm')
      Serial.println("m");
    else
      Serial.println(user_command);
    Serial.println();
    if (user_command == 1)
      alert_settings |= LTC4261_EXTERNAL_FAULT_ENABLE;
    else if (user_command ==2)
      alert_settings &= LTC4261_EXTERNAL_FAULT_DISABLE;
    else if (user_command != 'm')
      Serial.println("Incorrect Option\n");
    else
      return(ack);

    Serial.println(F("PGIO OUTPUT"));
    Serial.println(F("  1. Enable"));
    Serial.println(F("  2. Disable"));
    Serial.print(F("Enter a command: "));
    user_command = read_int();
    if (user_command == 'm')
      Serial.println("m");
    else
      Serial.println(user_command);
    Serial.println();
    if (user_command == 1)
      alert_settings |= LTC4261_PGIO_OUTPUT_ENABLE;
    else if (user_command ==2)
      alert_settings &= LTC4261_PGIO_OUTPUT_DISABLE;
    else if (user_command != 'm')
      Serial.println("Incorrect Option\n");
    else
      return(ack);

    Serial.println(F("FET SHORT ALERT"));
    Serial.println(F("  1. Enable"));
    Serial.println(F("  2. Disable"));
    Serial.print(F("Enter a command: "));
    user_command = read_int();
    if (user_command == 'm')
      Serial.println("m");
    else
      Serial.println(user_command);
    Serial.println();
    if (user_command == 1)
      alert_settings |= LTC4261_FET_SHORT_ENABLE;
    else if (user_command ==2)
      alert_settings &= LTC4261_FET_SHORT_DISABLE;
    else if (user_command != 'm')
      Serial.println("Incorrect Option\n");
    else
      return(ack);


    Serial.println(F("!EN STATE CHANGE ALERT"));
    Serial.println(F("  1. Enable"));
    Serial.println(F("  2. Disable"));
    Serial.print(F("Enter a command: "));
    user_command = read_int();
    if (user_command == 'm')
      Serial.println("m");
    else
      Serial.println(user_command);
    Serial.println();
    if (user_command == 1)
      alert_settings |= LTC4261_EN_STATE_ENABLE;
    else if (user_command ==2)
      alert_settings &= LTC4261_EN_STATE_DISABLE;
    else if (user_command != 'm')
      Serial.println("Incorrect Option\n");
    else
      return(ack);

    Serial.println(F("POWER BAD ALERT"));
    Serial.println(F("  1. Enable"));
    Serial.println(F("  2. Disable"));
    Serial.print(F("Enter a command: "));
    user_command = read_int();
    if (user_command == 'm')
      Serial.println("m");
    else
      Serial.println(user_command);
    Serial.println();
    if (user_command == 1)
      alert_settings |= LTC4261_POWER_BAD_ENABLE;
    else if (user_command ==2)
      alert_settings &= LTC4261_POWER_BAD_DISABLE;
    else if (user_command != 'm')
      Serial.println("Incorrect Option\n");
    else
      return(ack);

    Serial.println(F("OVERCURRENT ALERT"));
    Serial.println(F("  1. Enable"));
    Serial.println(F("  2. Disable"));
    Serial.print(F("Enter a command: "));
    user_command = read_int();
    if (user_command == 'm')
      Serial.println("m");
    else
      Serial.println(user_command);
    Serial.println();
    if (user_command == 1)
      alert_settings |= LTC4261_OVERCURRENT_ENABLE;
    else if (user_command ==2)
      alert_settings &= LTC4261_OVERCURRENT_DISABLE;
    else if (user_command != 'm')
      Serial.println("Incorrect Option\n");
    else
      return(ack);

    Serial.println(F("UNDERVOLTAGE ALERT"));
    Serial.println(F("  1. Enable"));
    Serial.println(F("  2. Disable"));
    Serial.print(F("Enter a command: "));
    user_command = read_int();
    if (user_command == 'm')
      Serial.println("m");
    else
      Serial.println(user_command);
    Serial.println();
    if (user_command == 1)
      alert_settings |= LTC4261_UNDERVOLTAGE_ENABLE;
    else if (user_command ==2)
      alert_settings &= LTC4261_UNDERVOLTAGE_DISABLE;
    else if (user_command != 'm')
      Serial.println("Incorrect Option\n");
    else
      return(ack);

    Serial.println(F("OVERVOLTAGE ALERT"));
    Serial.println(F("  1. Enable"));
    Serial.println(F("  2. Disable"));
    Serial.print(F("Enter a command: "));
    user_command = read_int();
    if (user_command == 'm')
      Serial.println("m");
    else
      Serial.println(user_command);
    Serial.println();
    if (user_command == 1)
      alert_settings |= LTC4261_OVERVOLTAGE_ENABLE;
    else if (user_command ==2)
      alert_settings &= LTC4261_OVERVOLTAGE_DISABLE;
    else if (user_command != 'm')
      Serial.println("Incorrect Option\n");
    else
      return(ack);
    ack |= LTC4261_write(LTC4261_I2C_Address, LTC4261_ALERT_REG, alert_settings);
    Serial.print(F("\n  ALERTS UPDATED\n\n"));
    Serial.println(F("  m. Main Menu"));
    Serial.println(F("  1. Repeat"));
    Serial.print(F("Enter a command: "));
    user_command = read_int();
    if (user_command == 'm')
      Serial.println("m");
    else
      Serial.println(user_command);
    Serial.println();
  }
  while (!((user_command == 'm') || (ack)));
  return(ack);

}

//! Function to update control register bits
int8_t main_menu_5_settings()
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
{
  int8_t ack = 0;
  uint8_t settings =0;
  int8_t user_command;
  do
  {
    Serial.println(F("PGIO"));
    Serial.println(F("  1. !POWER GOOD"));
    Serial.println(F("  2. POWER GOOD"));
    Serial.println(F("  3. General Purpose Output"));
    Serial.println(F("  4. General Purpose Input"));
    Serial.print(F("Enter a command: "));
    user_command = read_int();
    if (user_command == 'm')
    {
      Serial.println("m");
      return(ack);
    }
    else
      Serial.println(user_command);
    Serial.println();
    switch (user_command)
    {
      case 1:
        settings |= LTC4261_PGIO_POWER_GOODX;
        break;
      case 2:
        settings |= LTC4261_PGIO_POWER_GOOD;
        break;
      case 3:
        settings |= LTC4261_PGIO_GENERAL_PURPOSE_OUTPUT;
        break;
      case 4:
        settings |= LTC4261_PGIO_GENERAL_PURPOSE_INPUT;
        break;
      default:
        if (user_command != 'm')
          Serial.println("Incorrect Option\n");
        break;
    }

    Serial.println(F("TEST MODE ENABLE"));
    Serial.println(F("  1. Enable"));
    Serial.println(F("  2. Disable"));
    Serial.print(F("Enter a command: "));
    user_command = read_int();
    if (user_command == 'm')
      Serial.println("m");
    else
      Serial.println(user_command);
    Serial.println();
    if (user_command == 1)
      settings |= LTC4261_TEST_MODE_ENABLE;
    else if (user_command ==2)
      settings &= LTC4261_TEST_MODE_DISABLE;
    else if (user_command != 'm')
      Serial.println("Incorrect Option\n");
    else
      return(ack);

    Serial.println(F("POWER BAD AUTO RETRY"));
    Serial.println(F("  1. Enable"));
    Serial.println(F("  2. Disable"));
    Serial.print(F("Enter a command: "));
    user_command = read_int();
    if (user_command == 'm')
      Serial.println("m");
    else
      Serial.println(user_command);
    Serial.println();
    if (user_command == 1)
      settings |= LTC4261_POWER_BAD_AUTO_RETRY_ENABLE;
    else if (user_command ==2)
      settings &= LTC4261_POWER_BAD_AUTO_RETRY_DISABLE;
    else if (user_command != 'm')
      Serial.println("Incorrect Option\n");
    else
      return(ack);


    Serial.println(F("FET STATUS"));
    Serial.println(F("  1. ON"));
    Serial.println(F("  2. OFF"));
    Serial.print(F("Enter a command: "));
    user_command = read_int();
    if (user_command == 'm')
      Serial.println("m");
    else
      Serial.println(user_command);
    Serial.println();
    if (user_command == 1)
      settings |= LTC4261_FET_ON;
    else if (user_command ==2)
      settings &= LTC4261_FET_OFF;
    else if (user_command != 'm')
      Serial.println("Incorrect Option\n");
    else
      return(ack);

    Serial.println(F("OVERCURRENT AUTO RETRY"));
    Serial.println(F("  1. Enable"));
    Serial.println(F("  2. Disable"));
    Serial.print(F("Enter a command: "));
    user_command = read_int();
    if (user_command == 'm')
      Serial.println("m");
    else
      Serial.println(user_command);
    Serial.println();
    if (user_command == 1)
      settings |= LTC4261_OVERCURRENT_AUTO_RETRY_ENABLE;
    else if (user_command ==2)
      settings &= LTC4261_OVERCURRENT_AUTO_RETRY_DISABLE;
    else if (user_command != 'm')
      Serial.println("Incorrect Option\n");
    else
      return(ack);

    Serial.println(F("UNDERVOLTAGE AUTO RETRY"));
    Serial.println(F("  1. Enable"));
    Serial.println(F("  2. Disable"));
    Serial.print(F("Enter a command: "));
    user_command = read_int();
    if (user_command == 'm')
      Serial.println("m");
    else
      Serial.println(user_command);
    Serial.println();
    if (user_command == 1)
      settings |= LTC4261_UNDERVOLTAGE_AUTO_RETRY_ENABLE;
    else if (user_command ==2)
      settings &= LTC4261_UNDERVOLTAGE_AUTO_RETRY_DISABLE;
    else if (user_command != 'm')
      Serial.println("Incorrect Option\n");
    else
      return(ack);


    Serial.println(F("OVERVOLTAGE AUTO RETRY"));
    Serial.println(F("  1. Enable"));
    Serial.println(F("  2. Disable"));
    Serial.print(F("Enter a command: "));
    user_command = read_int();
    if (user_command == 'm')
      Serial.println("m");
    else
      Serial.println(user_command);
    Serial.println();
    if (user_command == 1)
      settings |= LTC4261_OVERVOLTAGE_AUTO_RETRY_ENABLE;
    else if (user_command ==2)
      settings &= LTC4261_OVERVOLTAGE_AUTO_RETRY_DISABLE;
    else if (user_command != 'm')
      Serial.println("Incorrect Option\n");
    else
      return(ack);
    ack |= LTC4261_write(LTC4261_I2C_Address, LTC4261_CONTROL_REG, settings);
    Serial.print(F("\nSETTINGS UPDATED\n\n"));
    Serial.println(F("  m. Main Menu"));
    Serial.println(F("  1. Repeat"));
    Serial.print(F("Enter a command: "));
    user_command = read_int();
    if (user_command == 'm')
      Serial.println("m");
    else
      Serial.println(user_command);
    Serial.println();
  }
  while (!((user_command == 'm') || (ack)));
  return(ack);
}

//! Function to read all registers.
int8_t main_menu_6_read_all_registers()
//! @return Returns the state of the acknowledge bit after the I2C address read. 0=acknowledge, 1=no acknowledge.
{
  int8_t ack = 0;
  uint8_t faults;
  ack |= LTC4261_read(LTC4261_I2C_Address, LTC4261_FAULT_REG, &faults);
  Serial.print("  FAULT REGISTER : 0b");
  Serial.println(faults, BIN);
  ack |= LTC4261_read(LTC4261_I2C_Address, LTC4261_STATUS_REG, &faults);
  Serial.print("  STATUS REGISTER : 0b");
  Serial.println(faults, BIN);
  ack |= LTC4261_read(LTC4261_I2C_Address, LTC4261_ALERT_REG, &faults);
  Serial.print("  ALERT REGISTER : 0b");
  Serial.println(faults, BIN);
  ack |= LTC4261_read(LTC4261_I2C_Address, LTC4261_CONTROL_REG, &faults);
  Serial.print("  CONTROL REGISTER : 0b");
  Serial.println(faults, BIN);
  Serial.println();
  return ack;
}

Download LTC4261 Linduino Header File

/*!
LTC4261: Negative Voltage Hot Swap Controller with ADC and I2C Monitoring

@verbatim

The LTC4261/LTC4261-2 negative voltage Hot SwapTM controller allows a board
to be safely inserted and removed from a live backplane. Using an external
N-channel pass transistor, the board supply voltage can be ramped at an
adjustable rate. The devices feature independently adjustable inrush current
and overcurrent limits to minimize stresses on the pass transistor during
start-up, input step and output short conditions. The LTC4261 defaults
to latch-off while the LTC4261-2 defaults to auto-retry on overcurrent faults.

I2C DATA FORMAT (MSB FIRST):

Data Out:
Byte #1                                    Byte #2                       Byte #3

START  SA6 SA5 SA4 SA3 SA2 SA1 SA0 W SACK  C7  C6 C5 C4 C3 C2 C1 C0 SACK D7 D6 D5 D4 D3 D2 D1 D0 SACK  STOP

Data In:
Byte #1                                    Byte #2                                      Byte #3

START  SA6 SA5 SA4 SA3 SA2 SA1 SA0 W SACK  C7  C6  C5 C4 C3 C2 C1 C0 SACK  Repeat Start SA6 SA5 SA4 SA3 SA2 SA1 SA0 R SACK

Byte #4                                   Byte #5
MSB                                       LSB
D15 D14  D13  D12  D11  D10  D9 D8 MACK   D7 D6 D5 D4 D3  D2  D1  D0  MNACK  STOP

START       : I2C Start
Repeat Start: I2C Repeat Start
STOP        : I2C Stop
SAx         : I2C Address
SACK        : I2C Slave Generated Acknowledge (Active Low)
MACK        : I2C Master Generated Acknowledge (Active Low)
MNACK       : I2C Master Generated Not Acknowledge
W           : I2C Write (0)
R           : I2C Read  (1)
Cx          : Command Code
Dx          : Data Bits
X           : Don't care

Example Code:

Read ADIN and Current Values

    ack |= LTC4261_read_10_bits(LTC4261_I2C_Address, LTC4261_SENSE_MSB_REG, &current_code);   // reads current sense ADC
    ack |= LTC4261_read_10_bits(LTC4261_I2C_Address, LTC4261_ADIN_MSB_REG, &adin_code);       // reads ADIN ADC
    ack |= LTC4261_read_10_bits(LTC4261_I2C_Address, LTC4261_ADIN2_MSB_REG, &adin2_code);     // reads ADIN2 ADC

    //convert codes to voltage and current values
    current = LTC4261_code_to_current(current_code, resitor, current_lsb);
    adin_voltage = LTC4261_ADIN_code_to_voltage(adin_code, adin_lsb, resisive_ratio);
    adin2_voltage = LTC4261_ADIN_code_to_voltage(adin2_code, adin_lsb, resisive_ratio);

@endverbatim

http://www.linear.com/product/LTC4261

http://www.linear.com/product/LTC4261#demoboards

REVISION HISTORY
$Revision: 3238 $
$Date: 2015-03-06 16:40:13 -0800 (Fri, 06 Mar 2015) $

Copyright (c) 2013, Linear Technology Corp.(LTC)
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of Linear Technology Corp.

The Linear Technology Linduino is not affiliated with the official Arduino team.
However, the Linduino is only possible because of the Arduino team's commitment
to the open-source community.  Please, visit http://www.arduino.cc and
http://store.arduino.cc , and consider a purchase that will help fund their
ongoing work.
*/

/*! @file
    @ingroup LTC4261
    Header for LTC4261: Negative Voltage Hot Swap Controllers with ADC and I2C Monitoring
*/

#ifndef LTC4261_H
#define LTC4261_H

#include <Wire.h>

//! @name LTC4261 Address Assignment
//! @{
#define LTC4261_I2C_Address                     0x10
// #define LTC4261_I2C_Address                     0x11
// #define LTC4261_I2C_Address                     0x12
// #define LTC4261_I2C_Address                     0x13
// #define LTC4261_I2C_Address                     0x14
// #define LTC4261_I2C_Address                     0x15
// #define LTC4261_I2C_Address                     0x16
// #define LTC4261_I2C_Address                     0x17
#define LTC4261_I2C_ALERT_RESPONSE               0x0C
#define LTC4261_I2C_MASS_WRITE                   0x3E
//!@}

/*! @name LTC4261 Register Addresses
@{ */
// Register Addresses
#define LTC4261_STATUS_REG                       0x00
#define LTC4261_FAULT_REG                        0x01
#define LTC4261_ALERT_REG                        0x02
#define LTC4261_CONTROL_REG                      0x03
#define LTC4261_SENSE_MSB_REG                    0x04
#define LTC4261_SENSE_LSB_REG                    0x05
#define LTC4261_ADIN2_MSB_REG                    0x06
#define LTC4261_ADIN2_LSB_REG                    0x07
#define LTC4261_ADIN_MSB_REG                     0x08
#define LTC4261_ADIN_LSB_REG                     0x09
//!@}

/*! @name Command Codes
@{ */
#define LTC4261_PGIO_POWER_GOODX                 0x00
#define LTC4261_PGIO_POWER_GOOD                  0x80
#define LTC4261_PGIO_GENERAL_PURPOSE_OUTPUT      0x40
#define LTC4261_PGIO_GENERAL_PURPOSE_INPUT       0xC0

#define LTC4261_TEST_MODE_ENABLE                 0x20
#define LTC4261_TEST_MODE_DISABLE                0xDF

#define LTC4261_POWER_BAD_AUTO_RETRY_ENABLE      0x10
#define LTC4261_POWER_BAD_AUTO_RETRY_DISABLE     0xEF

#define LTC4261_FET_ON                           0x08
#define LTC4261_FET_OFF                          0xF7

#define LTC4261_OVERCURRENT_AUTO_RETRY_ENABLE    0x04
#define LTC4261_OVERCURRENT_AUTO_RETRY_DISABLE   0xFB

#define LTC4261_UNDERVOLTAGE_AUTO_RETRY_ENABLE   0x02
#define LTC4261_UNDERVOLTAGE_AUTO_RETRY_DISABLE  0xFD

#define LTC4261_OVERVOLTAGE_AUTO_RETRY_ENABLE    0x01
#define LTC4261_OVERVOLTAGE_AUTO_RETRY_DISABLE   0xFE
//!@}

/*! @name Fault Codes
@{ */
#define LTC4261_EXTERNAL_FAULT                  0x80
#define LTC4261_PGIO_INPUT_HIGH                 0x40
#define LTC4261_FET_SHORT_FAULT                 0x20
#define LTC4261_EN_STATE_CHANGE                 0x10
#define LTC4261_POWER_BAD_FAULT                 0x08
#define LTC4261_OVERCURRENT_FAULT               0x04
#define LTC4261_UNDERVOLTAGE_FAULT              0x02
#define LTC4261_OVERVOLTAGE_FAULT               0x01
//!@}

/*! @name Alert Codes
@{ */
#define LTC4261_EXTERNAL_FAULT_ENABLE           0x80
#define LTC4261_EXTERNAL_FAULT_DISABLE          0x7F
#define LTC4261_PGIO_OUTPUT_ENABLE              0x40
#define LTC4261_PGIO_OUTPUT_DISABLE             0xBF
#define LTC4261_FET_SHORT_ENABLE                0x20
#define LTC4261_FET_SHORT_DISABLE               0xDF
#define LTC4261_EN_STATE_ENABLE                 0x10
#define LTC4261_EN_STATE_DISABLE                0xEF
#define LTC4261_POWER_BAD_ENABLE                0x08
#define LTC4261_POWER_BAD_DISABLE               0xF7
#define LTC4261_OVERCURRENT_ENABLE              0x04
#define LTC4261_OVERCURRENT_DISABLE             0xFB
#define LTC4261_UNDERVOLTAGE_ENABLE             0x02
#define LTC4261_UNDERVOLTAGE_DISABLE            0xFD
#define LTC4261_OVERVOLTAGE_ENABLE              0x01
#define LTC4261_OVERVOLTAGE_DISABLE             0xFE
//!@}

//! Write an 8-bit code to the LTC4261.
//! @return The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
int8_t LTC4261_write(uint8_t i2c_address,   //!< I2C Address for the LTC4261
                     uint8_t command,     //!< The "command byte" for the LTC4261 that corresponds to register address
                     uint8_t code           //!< Value that will be written to the register
                    );

//! Reads an 8-bit adc_code from LTC4261
//! @return The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
int8_t LTC4261_read(uint8_t i2c_address,  //!< I2C Address for the LTC4261
                    uint8_t command,    //!< The "command byte" for the LTC4261 that corresponds to register address
                    uint8_t *code       //!< Value that will be read from the register
                   );

//! Reads a 10-bit adc_code from LTC4261
//! @return The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
int8_t LTC4261_read_10_bits(uint8_t i2c_address, //!< I2C Address for the LTC4261
                            uint8_t adc_command, //!< The "command byte" for the LTC4261 that corresponds to register address
                            uint16_t *adc_code   //!< Value that will be read from the register.
                           );

//! SMBus Alert Response Protocol: Sends an alert response command and releases /ALERT pin. LTC4261 responds with its address
//! @return The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
int8_t LTC4261_ARA(uint8_t alert_response_address,  //!< the Alert Response Address on the I2C bus
                   uint8_t *i2c_address             //!< the address of the alert source
                  );

//! Calculate the LTC4261 ADIN voltage
//! @return Returns the ADIN Voltage in Volts
float LTC4261_ADIN_code_to_voltage(uint16_t adc_code,         //!< The ADC value
                                   float LTC4261_ADIN_lsb,    //!< ADIN lsb weight
                                   float resistor_divider_ratio //!< the ratio that the voltages have been divided down
                                  );
//! Calculate the LTC4261 current with a sense resistor
//! @return The LTC4261 sense current
float LTC4261_code_to_current(uint16_t adc_code,                //!< The ADC value
                              float resistor,                   //!< The resistor value
                              float LTC4261_DELTA_SENSE_lsb     //!< Delta sense lsb weight
                             );
#endif // LTC4261_H

Download LTC4261 Linduino.CPP

/*!
LTC4261: Negative Voltage Hot Swap Controller with ADC and I2C Monitoring

@verbatim

The LTC4261/LTC4261-2 negative voltage Hot SwapTM controller allows a board
to be safely inserted and removed from a live backplane. Using an external
N-channel pass transistor, the board supply voltage can be ramped at an
adjustable rate. The devices feature independently adjustable inrush current
and overcurrent limits to minimize stresses on the pass transistor during
start-up, input step and output short conditions. The LTC4261 defaults
to latch-off while the LTC4261-2 defaults to auto-retry on overcurrent faults.

@endverbatim

http://www.linear.com/product/LTC4261

http://www.linear.com/product/LTC4261#demoboards

REVISION HISTORY
$Revision: 3238 $
$Date: 2015-03-06 16:40:13 -0800 (Fri, 06 Mar 2015) $

Copyright (c) 2013, Linear Technology Corp.(LTC)
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of Linear Technology Corp.

The Linear Technology Linduino is not affiliated with the official Arduino team.
However, the Linduino is only possible because of the Arduino team's commitment
to the open-source community.  Please, visit http://www.arduino.cc and
http://store.arduino.cc , and consider a purchase that will help fund their
ongoing work.
*/

//! @defgroup LTC4261 LTC4261: Negative Voltage Hot Swap Controllers with ADC and I2C Monitoring

/*! @file
  @ingroup LTC4261
  Library for LTC4261: Negative Voltage Hot Swap Controllers with ADC and I2C Monitoring
*/

#include <Arduino.h>
#include <stdint.h>
#include "Linduino.h"
#include "LT_I2C.h"
#include "LTC4261.h"
#include <Wire.h>

// Writes an 8-bit code to the LTC4261
int8_t LTC4261_write(uint8_t i2c_address, uint8_t command, uint8_t code)
// The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge
{
  int8_t ack;
  ack = i2c_write_byte_data(i2c_address,command,code);
  return ack;
}

// Reads an 8-bit code from the LTC4261
int8_t LTC4261_read(uint8_t i2c_address, uint8_t command, uint8_t *code)
// The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge
{
  int8_t ack;
  ack = i2c_read_byte_data(i2c_address,command,code);
  return ack;
}

// Reads a 10-bit adc_code from LTC4261
int8_t LTC4261_read_10_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t *adc_code)
// The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge
{
  int8_t ack;
  uint8_t values[2];
  ack = i2c_read_block_data(i2c_address,adc_command, 2,values);
  *adc_code = (uint16_t)(values[0]) <<2 | values[1]>>6;
  return ack;
}

// SMBus Alert Response Protocol: Sends an alert response command and releases /ALERT pin. LTC4261 responds with its address
int8_t LTC4261_ARA(uint8_t alert_response_address, uint8_t *i2c_address)
// The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge
{
  int8_t ack;
  ack = i2c_read_byte(alert_response_address, i2c_address);
  return ack;
}
// Calculates the LTC4261 ADIN voltage
float LTC4261_ADIN_code_to_voltage(uint16_t adc_code, float LTC4261_ADIN_lsb, float resistor_divider_ratio)
// Returns the ADIN Voltage in Volts
{
  float adc_voltage;
  adc_voltage = (float)adc_code*LTC4261_ADIN_lsb;   //! 1) Calculate voltage from code and ADIN lsb
  return(adc_voltage*resistor_divider_ratio);
}

// Calculates the LTC4261 current with a sense resistor
float LTC4261_code_to_current(uint16_t adc_code, float resistor, float LTC4261_DELTA_SENSE_lsb)
// Returns the LTC4261 sense current
{
  float voltage, current;
  voltage = (float)adc_code*LTC4261_DELTA_SENSE_lsb;    //! 1) Calculate voltage from ADC code and delta sense lsb
  current = voltage/resistor;                           //! 2) Calculate current, I = V/R
  return(current);
}

Technical Support