A feature complete driver for the MCP4922 DAC from Microchip.

Dependents:   MCP4922_HelloWorld NuMidi401 NuFM401 NuFM402

Files at this revision

API Documentation at this revision

Comitter:
neilt6
Date:
Thu May 15 23:51:38 2014 +0000
Parent:
0:e994c6963c66
Commit message:
Constructor now initializes the internal variables, and performs an initial write to make sure they're in sync

Changed in this revision

MCP4922.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r e994c6963c66 -r 747ec9c5d80e MCP4922.cpp
--- a/MCP4922.cpp	Thu May 15 17:33:40 2014 +0000
+++ b/MCP4922.cpp	Thu May 15 23:51:38 2014 +0000
@@ -18,9 +18,17 @@
 
 MCP4922::MCP4922(PinName mosi, PinName sclk, PinName cs, int hz) : m_SPI(mosi, NC, sclk), m_CS(cs, 1)
 {
+    //Initialize the member variables
+    m_DacValueA = 0;
+    m_DacValueB = 0;
+
     //Set the SPI format and bus frequency
     m_SPI.format(16, 0);
     m_SPI.frequency(hz);
+
+    //Perform an initial write to both DACs so the variables are in sync
+    writeDac(m_DacValueA | (DAC_A << 15));
+    writeDac(m_DacValueB | (DAC_B << 15));
 }
 
 MCP4922::ReferenceMode MCP4922::referenceMode(DAC dac)