Driver for National Semiconductor ADC128Sxxx family of analog to digital converters

Files at this revision

API Documentation at this revision

Comitter:
shimniok
Date:
Fri Feb 18 20:52:59 2011 +0000
Child:
1:0edd6142cd67
Commit message:
Initial version

Changed in this revision

ADC128S.cpp Show annotated file Show diff for this revision Revisions of this file
ADC128S.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ADC128S.cpp	Fri Feb 18 20:52:59 2011 +0000
@@ -0,0 +1,21 @@
+// ADC128S   a library for the National Semiconductor ADC128S family of ADCs
+//
+// by Michael Shimniok - http://www.bot-thoughts.com/
+//
+#include "mbed.h"
+#include "ADC128S.h"
+
+ADC128S::ADC128S(PinName cs, PinName mosi, PinName miso, PinName sck) : _adc(mosi, miso, sck), _cs(cs) {
+    _adc.format(16,3);
+    _adc.frequency(8000000);
+}
+
+unsigned int ADC128S::read(int channel) {
+    unsigned int result = 0;
+    _cs = 0;
+    _adc.write(channel<<11); // send channel for next acquisition; XXXAAAXX XXXXXXXX
+    result = _adc.write(channel<<11); // get next acquisition
+    _cs = 1;
+    
+    return result;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ADC128S.h	Fri Feb 18 20:52:59 2011 +0000
@@ -0,0 +1,13 @@
+// ADC128S   a library for the National Semiconductor ADC128S family of ADCs
+//
+// by Michael Shimniok - http://www.bot-thoughts.com/
+//
+class ADC128S {
+public:
+    ADC128S(PinName cs, PinName mosi, PinName miso, PinName sck);
+    unsigned int read(int channel);
+
+private:
+    SPI _adc;
+    DigitalOut _cs;
+};
\ No newline at end of file