12-Bit DAC with internal Vref and SPI interface
Fork of MCP4822 by
Diff: MCP4822.cpp
- Revision:
- 1:d97fd6c6e2e4
- Parent:
- 0:929babff65b1
diff -r 929babff65b1 -r d97fd6c6e2e4 MCP4822.cpp --- a/MCP4822.cpp Mon Mar 23 07:53:55 2015 +0000 +++ b/MCP4822.cpp Wed Jan 20 10:55:01 2016 +0000 @@ -27,15 +27,9 @@ // Public functions //============================================================================= - MCP4822::MCP4822(SPI& spi, PinName nLDAC, PinName nCs) : _spi(spi), _nLDAC(nLDAC), _nCs(nCs) + MCP4822::MCP4822(SPI& spi, PinName nCs, PinName nLDAC) : _spi(spi), _nCs(nCs), _nLDAC(nLDAC) { - - } - - - MCP4822::MCP4822(PinName nLDAC, PinName mosi, PinName miso,PinName sck, PinName nCs) : _nLDAC(nLDAC), _mosi(mosi), _miso(miso), _sck(sck), _nCs(nCs) - { - SPI _spi(_mosi,_miso,_sck); + _nCs = 1; } void MCP4822::a(bool gain, int data) @@ -53,9 +47,20 @@ _nLDAC = ~act; } + bool MCP4822::ldac() + { + return _nLDAC; + } + void MCP4822::shdn(bool output, bool act) { - _write(output, 1, ~act, 0x00); + _write(output, 1, ~act, 0x00); + _SHDN_STATUS = act; + } + + bool MCP4822::shdn() + { + return _SHDN_STATUS; } //============================================================================= @@ -66,7 +71,7 @@ { char responce = 0; - if(output == '0') + if(output == 0) { responce = responce | CB_OUTPUT_A; } @@ -75,7 +80,7 @@ responce = responce | CB_OUTPUT_B; } - if(gain == '0') + if(gain == 0) { responce = responce | CB_GAIN_2X; } @@ -84,7 +89,7 @@ responce = responce | CB_GAIN_1X; } - if(shdn == '0') + if(shdn == 0) { responce = responce | CB_NSHDN; } @@ -93,7 +98,7 @@ responce = responce | CB_SHDN; } - if(data > 0xff && data < 0xfff) + if(data > 0xff && data <= 0xfff) { responce = responce | (data >> 8); } @@ -116,4 +121,4 @@ _spi.write(_upper_half); _spi.write(_lower_half); _nCs = 1; - } \ No newline at end of file + }