A feature complete driver for the MCP4922 DAC from Microchip.
Dependents: MCP4922_HelloWorld NuMidi401 NuFM401 NuFM402
Diff: MCP4922.cpp
- Revision:
- 1:747ec9c5d80e
- Parent:
- 0:e994c6963c66
--- 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)