Basic libraries for functionality of the MCP4822 DAC, an easy to use DAC outputting up to 4.096V.

Dependencies:   DAC

Revision:
0:a10e8793cf0a
diff -r 000000000000 -r a10e8793cf0a DAC_SPI/DAC_SPI.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DAC_SPI/DAC_SPI.cpp	Thu Jun 14 03:58:16 2012 +0000
@@ -0,0 +1,29 @@
+#include "DAC_SPI.h"
+
+/*SPI Channels */
+SPI SPI_A(p5, NC, p7);  //since we only have two SPI channels, which must be shared, define them here.
+SPI SPI_B(p11, NC, p13);
+
+/*Initialize DAC */
+DAC_SPI::DAC_SPI(int SPIchannelNum, PinName _CS, PinName _LDAC) : CS(_CS), LDAC(_LDAC){  
+    if (SPIchannelNum ==1){
+        DACspi = &SPI_B;
+    }  
+    else{
+        DACspi = &SPI_A;
+    }
+    messageBits(16);
+}
+
+/** Manually change the SPI frequency 
+* Must be a value supported by the mbed and DAC
+*/
+void DAC_SPI::frequency(int freq){
+    (*DACspi).frequency(freq);    
+}
+
+
+//specify the number of bits used in message packets to the DAC.
+void DAC_SPI::messageBits(int bits){
+    (*DACspi).format(bits,0);
+}
\ No newline at end of file