Example of using the DS271 battery monitor on the ESP motor driver board using PC_12 as the OneWire interface (Any other GPIO can be used)

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
EmbeddedSam
Date:
Mon Mar 04 14:48:45 2019 +0000
Commit message:
Initial Commit;

Changed in this revision

OneWire_Methods.cpp Show annotated file Show diff for this revision Revisions of this file
OneWire_Methods.h Show annotated file Show diff for this revision Revisions of this file
ds2781.cpp Show annotated file Show diff for this revision Revisions of this file
ds2781.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OneWire_Methods.cpp	Mon Mar 04 14:48:45 2019 +0000
@@ -0,0 +1,175 @@
+#include "OneWire_Methods.h"
+#include "mbed.h"
+
+//Peripherals and typedefs
+extern DigitalInOut   one_wire_pin;
+
+unsigned char OneWire_ReadByte(void)
+{
+    unsigned char result=0;
+
+    for (int i = 0; i < 8; i++){    
+        result >>= 1;           // shift the result to get it ready for the next bit
+        // if result is one, then set MS bit
+        if (OneWire_ReadBit()){result |= 0x80;}    
+    }
+    return result;
+}
+
+void OneWire_WriteByte(unsigned char byte_to_write)
+{  
+    for (int i = 0; i<8; i++)     // Loop to write each bit in the byte, LS-bit first
+    {
+        OneWire_WriteBit(byte_to_write & 0x01);        
+        byte_to_write >>= 1;      // shift the data byte for the next bit
+    }
+}
+
+bool OneWire_ReadBit(void)
+{  
+    bool result;
+    one_wire_pin.output();
+    one_wire_pin = 0;
+    OneWire_Delay('A');
+    one_wire_pin.input();
+    one_wire_pin.mode(PullUp);
+    OneWire_Delay('E');
+    result = one_wire_pin.read();
+    OneWire_Delay('F');
+    return result;
+}
+
+void OneWire_WriteBit (bool bit_to_write){
+    
+    if (bit_to_write == 1)
+    {
+        // Write '1' bit
+        one_wire_pin.output();
+        one_wire_pin = 0;
+        OneWire_Delay('A');
+        one_wire_pin.input();
+        one_wire_pin.mode(PullUp);
+        OneWire_Delay('B');
+    }
+    else
+    {
+        one_wire_pin.output();
+        one_wire_pin = 0;
+        OneWire_Delay('C');
+        one_wire_pin.input();
+        OneWire_Delay('D');
+    }
+}
+bool OneWire_Reset (void)
+{
+    //Checks whether there is a device connected, returns true or false
+    //Debugging console output can be used if it is defined
+    bool result = false;
+    one_wire_pin.output();
+    one_wire_pin.write(0); //Pull the line high
+    OneWire_Delay('H');
+    one_wire_pin.input();
+    one_wire_pin.mode(PullUp);
+    OneWire_Delay('I');
+    if(one_wire_pin.read() == 0){ result = true;}
+    OneWire_Delay('J'); 
+    #ifdef Debugging
+        pc.printf("\n\rResult from reset: %d",result);
+    #endif
+    return result;
+}
+
+void OneWire_TestDelays(void)
+{
+    //Cycles the output pin through all the delays so you
+    //can see whether they are all the right timings.
+    one_wire_pin.output();
+    for(int i=0;i<6;i++){
+        one_wire_pin = !one_wire_pin; //toggle the pin 6 times to signal start of test at 100us
+        wait_us(100);   
+    }
+    OneWire_Delay('A');
+    one_wire_pin = !one_wire_pin;
+    OneWire_Delay('A');
+    one_wire_pin = !one_wire_pin;
+    
+    OneWire_Delay('B');
+    one_wire_pin = !one_wire_pin;
+    OneWire_Delay('B');
+    one_wire_pin = !one_wire_pin;
+    
+    OneWire_Delay('C');
+    one_wire_pin = !one_wire_pin;
+    OneWire_Delay('C');
+    one_wire_pin = !one_wire_pin;
+    
+    OneWire_Delay('D');
+    one_wire_pin = !one_wire_pin;
+    OneWire_Delay('D');
+    one_wire_pin = !one_wire_pin;
+    
+    OneWire_Delay('E');
+    one_wire_pin = !one_wire_pin;
+    OneWire_Delay('E');
+    one_wire_pin = !one_wire_pin;
+    
+    OneWire_Delay('F');
+    one_wire_pin = !one_wire_pin;
+    OneWire_Delay('F');
+    one_wire_pin = !one_wire_pin;
+    
+    OneWire_Delay('G');
+    one_wire_pin = !one_wire_pin;
+    OneWire_Delay('G');
+    one_wire_pin = !one_wire_pin;
+    
+    OneWire_Delay('H');
+    one_wire_pin = !one_wire_pin;
+    OneWire_Delay('H');
+    one_wire_pin = !one_wire_pin;
+    
+        
+    OneWire_Delay('I');
+    one_wire_pin = !one_wire_pin;
+    OneWire_Delay('I');
+    one_wire_pin = !one_wire_pin;
+    
+    OneWire_Delay('J');
+    one_wire_pin = !one_wire_pin;
+    OneWire_Delay('J');
+    one_wire_pin = !one_wire_pin;
+    
+}
+
+//Functions
+void OneWire_Delay(char letter)
+{
+    //Recommended delays from Maxim (standard speed not overdrive)
+    //https://www.maximintegrated.com/en/app-notes/index.mvp/id/126
+    
+    //Letter  Speed       Recommended (µs)
+    //A       Standard    6
+    //B       Standard    64
+    //C       Standard    60
+    //D       Standard    10
+    //E       Standard    9
+    //F       Standard    55
+    //G       Standard    0
+    //H       Standard    480
+    //I       Standard    70
+    //J       Standard    410
+    switch(letter)
+    {
+        case 'A': wait_us(1); break;
+        case 'B': wait_us(64); break;
+        case 'C': wait_us(60); break;
+        case 'D': wait_us(10); break;
+        case 'E': wait_us(5); break;
+        case 'F': wait_us(55); break;
+        case 'G': wait_us(0); break;
+        case 'H': wait_us(480); break;
+        case 'I': wait_us(70); break;
+        case 'J': wait_us(410); break;
+        default: break;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OneWire_Methods.h	Mon Mar 04 14:48:45 2019 +0000
@@ -0,0 +1,7 @@
+void OneWire_Delay(char letter);
+void OneWire_TestDelays(void);
+bool OneWire_Reset(void);
+void OneWire_WriteBit(bool bit_to_write);
+bool OneWire_ReadBit(void);
+void OneWire_WriteByte(unsigned char byte_to_write);
+unsigned char OneWire_ReadByte(void);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ds2781.cpp	Mon Mar 04 14:48:45 2019 +0000
@@ -0,0 +1,346 @@
+#include "ds2781.h"
+#include "OneWire_Methods.h"
+
+/* --------------------------------------------------------------------------
+   This file includes the functions needed to access and modify the registers
+   in a DS2781 using the 1-Wire protocol. The DS2781 is an IC that measures
+   voltage, current, accumulated current and temperature. It implements
+   capacity estimation algorithms for rechargeable batteries. However, this
+   file only includes routines to access the electrical parameters and not
+   the age-estimation registers.
+   --------------------------------------------------------------------------
+----------------------
+   NOTE_1: The functions that return parameters, do so in the units reported
+   in the description of each function. The user should implement the scaling
+   on his/her own.  
+   -------------------------------------------------------------------------- */
+
+/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
+ * Function name : ReadVoltage                                                 *
+ * Overview : Returns the voltage measured at the VIN input of the DS2781      *
+ *            in units of 9.76mV                                               *
+ * Return type : 16-bit unsigned int                                           *
+ * Parameters : None                                                           *
+ * Time : < 4.3ms                                                              *
+ *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
+
+int ReadVoltage (void)
+{
+    uint16_t result = 0;
+    if( OneWire_Reset() == true)
+    {       
+        OneWire_WriteByte( SKIP_NETADDRESS );
+        OneWire_WriteByte( READ_DATA );
+        OneWire_WriteByte( 0x0C );                      //Register Address
+        result  = OneWire_ReadByte()  << 8;     //MSB   
+        result |= OneWire_ReadByte() ;          //LSB
+    }
+    return (result >> 5);
+}
+
+/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
+ * Function name : ReadCurrent                                                 *
+ * Overview : Returns the current measured through Rsns external to DS2781 in  *
+ *            units of 1.5625uV/Rsns. Positive current indicates discharge     *
+ * Return type : 16-bit unsigned int                                           *
+ * Parameters : None                                                           *
+ * Time : < 4.3ms                                                              *
+ *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
+
+uint16_t ReadCurrent (void)
+{
+    uint16_t result = 0;
+    if( OneWire_Reset() == true)
+    {       
+        OneWire_WriteByte( SKIP_NETADDRESS );
+        OneWire_WriteByte( READ_DATA );
+        OneWire_WriteByte( 0x0E );                      //Register Address
+        result  = ((uint16_t)OneWire_ReadByte() ) << 8;     //MSB   
+        result |= ((uint16_t)OneWire_ReadByte() );          //LSB
+    }
+    return result;
+}
+
+/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
+ * Function name : ReadAccumulatedCurrent                                      *
+ * Overview : Returns the accumulated current at the DS2781 in units of        *
+ *            1.526nVhr/Rsns                                                   *
+ * Return type : 32-bit unsigned long                                          *
+ * Parameters : None                                                           *
+ * Time : < 5.8ms                                                              *
+ *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
+
+uint32_t ReadAccumulatedCurrent (void)
+{
+    unsigned long result = 0;
+    if( OneWire_Reset() == true)
+    {       
+        OneWire_WriteByte( SKIP_NETADDRESS );
+        OneWire_WriteByte( READ_DATA );
+        OneWire_WriteByte( 0x10 );                      //Register Address
+        result  = ((unsigned long)OneWire_ReadByte() ) << 24;       //MSB
+        result |= ((unsigned long)OneWire_ReadByte() ) << 16;
+        result |= ((unsigned long)OneWire_ReadByte() ) << 8;    
+        result |= ((unsigned long)OneWire_ReadByte() );         //LSB
+    }
+    return (result >>  4);
+}
+
+/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
+ * Function name : ResetAccumulatedCurrent                                     *
+ * Overview : Resets the accumulated current register at the DS2781            *
+ * Return type : Void                                                          *
+ * Parameters : None                                                           *
+ * Time : < 4.2ms                                                              *
+ *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
+
+void ResetAccumulatedCurrent (void)
+{
+    if( OneWire_Reset() == true)
+    {       
+        OneWire_WriteByte( SKIP_NETADDRESS );
+        OneWire_WriteByte( WRITE_DATA );
+        OneWire_WriteByte( 0x10 );                      //Register Address
+        OneWire_WriteByte( 0x00 );                      //MSB
+        OneWire_WriteByte( 0x00 );                      //LSB
+    }
+}
+
+/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
+ * Function name : ReadNetAddress                                              *
+ * Overview : Returns the net address of the DS2781                            *
+ * Return type : 64-bit unsigned long long                                     *
+ * Parameters : None                                                           *
+ * Time : < 7.3ms                                                              *
+ *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
+
+uint32_t ReadNetAddress (void)
+{
+    uint16_t result = 0;
+    if( OneWire_Reset() == true)
+    {       
+        OneWire_WriteByte( READ_NETADDRESS );
+        //result  = ((Quint16_t)OneWire_ReadByte() );       //MSB
+        //result |= ((Quint16_t)OneWire_ReadByte() ) << 8;
+        //result |= ((Quint16_t)OneWire_ReadByte() ) << 16;
+        //result |= ((Quint16_t)OneWire_ReadByte() ) << 24;
+        //result |= ((Quint16_t)OneWire_ReadByte() ) << 32;
+        //result |= ((Quint16_t)OneWire_ReadByte() ) << 40;
+        //result |= ((Quint16_t)OneWire_ReadByte() ) << 48; 
+        //result |= ((Quint16_t)OneWire_ReadByte() ) <<56;          //LSB
+    }
+    return result;
+}
+
+/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
+ * Function name : ReadTemperature                                             *
+ * Overview : Returns the temperature measured by the DS2781 in units of       *
+ *            0.125°C                                                          *
+ * Return type : 16-bit unsigned int                                           *
+ * Parameters : None                                                           *
+ * Time : < 4.3ms                                                              *
+ *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
+
+uint16_t ReadTemperature (void)
+{
+    uint16_t result = 0;
+    if( OneWire_Reset() == true)
+    {       
+        OneWire_WriteByte( SKIP_NETADDRESS );
+        OneWire_WriteByte( READ_DATA );
+        OneWire_WriteByte( 0x0A );                      //Register Address
+        result  = ((uint16_t)OneWire_ReadByte() ) << 8;     //MSB   
+        result |= ((uint16_t)OneWire_ReadByte() );          //LSB
+    }
+    return (result >> 5);
+}
+
+/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
+ * Function name : ReadCurrentOffset                                           *
+ * Overview : Returns the value of the current offset register of the DS2781   *
+ *            in units of 1.56uV/Rsns                                          *
+ * Return type : 8-bit uint8_t                                         *
+ * Parameters : None                                                           *
+ * Time : < 3.6ms                                                              *
+ *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
+
+uint8_t ReadCurrentOffset (void)
+{
+    uint8_t result = 0;
+    if( OneWire_Reset() == true)
+    {       
+        OneWire_WriteByte( SKIP_NETADDRESS );
+        OneWire_WriteByte( READ_DATA );
+        OneWire_WriteByte( 0x7B );                      //Register Address
+        result  = OneWire_ReadByte();
+    }
+    return result;
+}
+
+/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
+ * Function name : WriteCurrentOffset                                          *
+ * Overview : Writes to the current offset register of the DS2781 in units of  *
+ *            1.56uV/Rsns                                                      *
+ * Return type : Void                                                          *
+ * Parameters : Byte to be written to the register in 2's complement           *
+ * Time : < 3.6ms                                                              *
+ *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
+
+void  WriteCurrentOffset (uint8_t offset)
+{
+    if( OneWire_Reset() == true)
+    {       
+        OneWire_WriteByte( SKIP_NETADDRESS );
+        OneWire_WriteByte( WRITE_DATA );
+        OneWire_WriteByte( 0x7B );                      //Register Address
+        OneWire_WriteByte( offset );
+    }
+}
+
+/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
+ * Function name : AdjustCurrentOffset                                         *
+ * Overview : Adjusts the value of the current offset register of the DS2781   *
+ *            by taking into account the offset at no current. Should only     *
+ *            be called when the battery is supplying no current               *
+ * Return type : Void                                                          *
+ * Parameters : None                                                           *
+ * Time : < 3.62s                                                              *
+ *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
+
+void AdjustCurrentOffset (void)
+{
+    char offset = 0;
+    
+    WriteCurrentOffset ( 0x0 );                     //Reset Current Offset Register
+
+    //Delay100MSx(36);                                //Wait 3.6s for current register to update
+
+    if( OneWire_Reset() == true)
+    {       
+        OneWire_WriteByte( SKIP_NETADDRESS );
+        OneWire_WriteByte( READ_DATA );
+        OneWire_WriteByte( 0x0F );                      //Current Register LSB
+        offset  = OneWire_ReadByte();   
+    }
+
+    offset = 256 - offset;                          //2's complement Negating
+
+    if( OneWire_Reset() == true)
+    {       
+        OneWire_WriteByte( SKIP_NETADDRESS );
+        OneWire_WriteByte( WRITE_DATA );
+        OneWire_WriteByte( 0x7B );                      //Current Offset Register
+        OneWire_WriteByte( offset );    
+    }
+}
+
+/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
+ * Function name : UpdateControlRegister                                       *
+ * Overview : Writes to the Control register of the DS2781 using the values    *
+ *            supplied as a byte parameter. Writes to EEPROM addresses are     *
+ *            ignored for up to 15ms after this function is called.            *
+ * Return type : Void                                                          *
+ * Parameters : None                                                           *
+ * Time : < 6.4ms                                                              *
+ *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
+
+void UpdateControlRegister (uint8_t control)
+{
+    if( OneWire_Reset() == true )
+    {       
+        OneWire_WriteByte( SKIP_NETADDRESS );
+        OneWire_WriteByte( WRITE_DATA );
+        OneWire_WriteByte( 0x60 );                      //Register Address
+        OneWire_WriteByte( control );
+    }
+
+    if( OneWire_Reset() == true )
+    {       
+        OneWire_WriteByte( SKIP_NETADDRESS );
+        OneWire_WriteByte( COPY_DATA );
+        OneWire_WriteByte( 0x60 );                      //Register Address
+    }
+}
+
+/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
+ * Function name : ReadRAM                                                     *
+ * Overview : Reads a byte from the shadow RAM of the DS2781 at the given      *
+ *            memory address                                                   *
+ * Return type : 8-bit uint8_t                                         *
+ * Parameters : Address of register to be read                                 *
+ * Time : < 3.6ms                                                              *
+ *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
+
+uint8_t ReadRAM (uint8_t addr)
+{
+    uint8_t result = 0;
+    if( OneWire_Reset() == true)
+    {       
+        OneWire_WriteByte( SKIP_NETADDRESS );
+        OneWire_WriteByte( READ_DATA );
+        OneWire_WriteByte( addr );                      //Register Address
+        result  = OneWire_ReadByte();
+    }
+    return result;
+}
+
+/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
+ * Function name : WriteRAM                                                    *
+ * Overview : Writes the given byte to the shadow RAM of the DS2781 at the     *
+ *            given memory address                                             *
+ * Return type : Void                                                          *
+ * Parameters : Byte to be written, address of register                        *
+ * Time : < 3.6ms                                                              *
+ *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
+
+void WriteRAM (uint8_t byte, uint8_t addr)
+{
+    if( OneWire_Reset() == true)
+    {       
+        OneWire_WriteByte( SKIP_NETADDRESS );
+        OneWire_WriteByte( WRITE_DATA );
+        OneWire_WriteByte( addr );                      //Register Address
+        OneWire_WriteByte( byte );
+    }
+}
+
+/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
+ * Function name : CopyEEPROM                                                  *
+ * Overview : This function copies the contents of the EEPROM shadow RAM to    *
+ *            EEPROM cells for the EEPROM block containing thr given address.  *
+ *            Writes to EEPROM addresses are ignored for up to 15ms after this *
+ *            function is called.                                              *
+ * Return type : Void                                                          *
+ * Parameters : Memory address of shadow RAM to be copied                      *
+ * Time : < 2.9ms                                                              *
+ *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
+
+void CopyEEPROM (uint8_t addr)
+{
+    if( OneWire_Reset() == true)
+    {       
+        OneWire_WriteByte( SKIP_NETADDRESS );
+        OneWire_WriteByte( COPY_DATA );
+        OneWire_WriteByte( addr );
+    }
+}
+
+/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
+ * Function name : RecallEEPROM                                                *
+ * Overview : This function copies the contents of the EEPROM cells to the     *
+ *            shadow RAM for the EEPROM block containing the given address.    *                                           *
+ * Return type : Void                                                          *
+ * Parameters : Memory address of EEPROM to be copied                          *
+ * Time : < 2.9ms                                                              *
+ *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
+
+void RecallEEPROM (uint8_t addr)
+{
+    if( OneWire_Reset() == true)
+    {       
+        OneWire_WriteByte( SKIP_NETADDRESS );
+        OneWire_WriteByte( RECALL_DATA );
+        OneWire_WriteByte( addr );
+    }
+}
+/* EOF */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ds2781.h	Mon Mar 04 14:48:45 2019 +0000
@@ -0,0 +1,32 @@
+#include "stdint.h"
+
+/* ***** net address commands ***** */
+#define READ_NETADDRESS 0x33
+#define SKIP_NETADDRESS 0xCC
+
+
+/* ***** function commands ***** */
+#define READ_DATA 0x69
+#define WRITE_DATA 0x6C
+#define COPY_DATA 0x48
+#define RECALL_DATA 0xB8
+#define LOCK_EEPROM 0x6A    //DO NOT USE
+
+
+/* ***** function prototypes ***** */
+/* Function details can be found in the .c file */
+int ReadVoltage (void);
+uint16_t ReadCurrent (void);
+uint32_t ReadAccumulatedCurrent (void);
+void ResetAccumulatedCurrent (void);
+uint32_t ReadNetAddress (void);
+uint16_t ReadTemperature (void);
+uint8_t ReadCurrentOffset (void);
+void  WriteCurrentOffset (uint8_t offset);
+void AdjustCurrentOffset (void);
+void UpdateControlRegister (uint8_t control);
+uint8_t ReadRAM (uint8_t addr);
+void WriteRAM (uint8_t byte, uint8_t addr);
+void CopyEEPROM (uint8_t addr);
+void RecallEEPROM (uint8_t addr);
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Mar 04 14:48:45 2019 +0000
@@ -0,0 +1,21 @@
+#include <mbed.h>
+#include "OneWire_Methods.h"
+#include "ds2781.h"
+
+Serial pc(USBTX, USBRX);
+DigitalInOut   one_wire_pin(PC_12);
+int VoltageReading, CurrentReading;
+float Voltage, Current;
+
+int main() {
+
+  while(1) {
+      VoltageReading = ReadVoltage();
+      Voltage = VoltageReading*0.00976; //Returns the voltage measured at the VIN input of the DS2781      *
+ *                                      //in units of 9.76mV 
+      CurrentReading = ReadCurrent();
+      Current = CurrentReading/6400.0; //Returns the current measured through Rsns external to DS2781 in  *
+ *                                     //units of 1.5625uV/Rsns. Positive current indicates discharge 
+      pc.printf("\n\rVoltage = %0.3f, Current= %0.3f", Voltage, Current);
+  }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Mar 04 14:48:45 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file