Library for controlling an MCP4725 "12-Bit Digital-to-Analog Converter with EEPROM Memory". There is an accompanying test suite program "MCP_4725_Library_Test" that can be used to test this library.

Dependents:   IGGE_Power MCP4725_Library_Test MCP4725 SinWave ... more

Files at this revision

API Documentation at this revision

Comitter:
donalm
Date:
Thu Nov 07 19:05:29 2013 +0000
Parent:
4:e0d667c9b23b
Commit message:
Fixed memory leak.

Changed in this revision

mcp4725.cpp Show annotated file Show diff for this revision Revisions of this file
mcp4725.h Show annotated file Show diff for this revision Revisions of this file
diff -r e0d667c9b23b -r 3e6ffce1eea2 mcp4725.cpp
--- a/mcp4725.cpp	Sun Nov 03 11:37:55 2013 +0000
+++ b/mcp4725.cpp	Thu Nov 07 19:05:29 2013 +0000
@@ -1,10 +1,8 @@
 #include "mcp4725.h"
 #include "mbed.h"
 
-MCP4725::MCP4725(PinName sda, PinName scl, BusFrequency bus_frequency, int device_address_bits)
+MCP4725::MCP4725(PinName sda, PinName scl, BusFrequency bus_frequency, int device_address_bits): _i2c_interface(sda, scl)
 {
-    _i2c_interface = new I2C(sda, scl);
-    
     //Set the frequency
     int freq=0;
     switch(bus_frequency)
@@ -19,7 +17,7 @@
             freq = 3400000;
             break;
     }
-    _i2c_interface->frequency(freq);
+    _i2c_interface.frequency(freq);
     
     // Assemble the full I2C device address.
     _device_address = 0xC0; // Prime the full device address with the device code.
@@ -32,7 +30,7 @@
     int result;
     
     // Read the raw data from the device.
-    result = _i2c_interface->read(_device_address, data, sizeof(data)/sizeof(*data), false);
+    result = _i2c_interface.read(_device_address, data, sizeof(data)/sizeof(*data), false);
     
     // Parse the raw data, extracting our fields. Refer to MCP4725 ref manual, section 6.2
     if (result == 0)
@@ -76,5 +74,5 @@
     data[2] = (dac_value<<4);
     
     // Now write them to the device.
-    return _i2c_interface->write(_device_address, data, sizeof(data)/sizeof(*data), false);
+    return _i2c_interface.write(_device_address, data, sizeof(data)/sizeof(*data), false);
 }
\ No newline at end of file
diff -r e0d667c9b23b -r 3e6ffce1eea2 mcp4725.h
--- a/mcp4725.h	Sun Nov 03 11:37:55 2013 +0000
+++ b/mcp4725.h	Thu Nov 07 19:05:29 2013 +0000
@@ -82,7 +82,7 @@
     
     protected:
     /** mbed I2C interface driver. */
-    I2C * _i2c_interface;
+    I2C _i2c_interface;
     /** The full i2c device address. */
     int _device_address;