AD7680 Library

Files at this revision

API Documentation at this revision

Comitter:
wacomg
Date:
Wed Apr 19 09:58:17 2017 +0000
Commit message:
AD7680 library

Changed in this revision

ad7680.cpp Show annotated file Show diff for this revision Revisions of this file
ad7680.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 91b4ea0c12f8 ad7680.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ad7680.cpp	Wed Apr 19 09:58:17 2017 +0000
@@ -0,0 +1,49 @@
+/***************************************************************************
+ * @author Wacomg
+ *
+ * @section LICENSE
+ *
+ * Copyright (c) 2017 Wacomg
+ *
+ * @section DESCRIPTION
+ *
+ *  AD7680.CPP
+ *  Source file for AD7680 class library
+ *  The AD7680 is a 16-bits, 1-channel, SPI-interfaced ADC from Analog Devices
+ *  
+*****************************************************************************/
+
+#include "ad7680.h"
+
+
+// Constructor
+AD7680::AD7680(PinName MISO, PinName SCLK, PinName CS, int frequency) : _spi(NC, MISO, SCLK), _cs(CS) {    
+    _spi.frequency(frequency);
+    _spi.format(24, 0);
+    _cs = 1;
+    _q = (double) 5.0/65535.0;;
+};
+
+
+    
+void AD7680::readRAW(int16_t *rawDataBuffer) {
+    uint8_t lowByte, medByte, highByte;
+    _cs = 0; 
+        highByte = _spi.write(0x00);    
+        medByte = _spi.write(0x00);    
+        lowByte = _spi.write(0x00);
+
+        *(rawDataBuffer + 0) = (int16_t) ((highByte << 12) + (medByte<<4) + (lowByte>>4));    
+    _cs = 1;
+}
+
+void AD7680::readAnalog(double *analogDataBuffer) {
+    uint8_t lowByte, medByte, highByte;
+    _cs = 0; 
+        highByte = _spi.write(0x00);    
+        medByte = _spi.write(0x00);    
+        lowByte = _spi.write(0x00);
+
+        *(analogDataBuffer +0 ) = (double) (uint16_t)((highByte << 12) + (medByte<<4) + (lowByte>>4))*_q;    
+    _cs = 1;
+}
diff -r 000000000000 -r 91b4ea0c12f8 ad7680.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ad7680.h	Wed Apr 19 09:58:17 2017 +0000
@@ -0,0 +1,32 @@
+/***************************************************************************
+ * @author Wacomg
+ *
+ * @section LICENSE
+ *
+ * Copyright (c) 2017 Wacomg
+ *
+ * @section DESCRIPTION
+ *
+ *  AD7680.H
+ *  Header file for AD7680 class library
+ *  The AD7680 is a 16-bits, 1-channels, SPI-interfaced ADC from Analog Devices
+ *  
+*****************************************************************************/
+#ifndef AD7680_H
+#define AD7680_H
+
+#include "mbed.h"
+
+class AD7680 {
+    private:
+        SPI _spi;
+        DigitalOut _cs;
+        double _q;
+
+    public:
+        AD7680(PinName MISO, PinName SCLK, PinName CS, int frequency); // Constructor
+        void readRAW(int16_t *); // Read raw values from ADC
+        void readAnalog(double *); // Read analog values
+};
+
+#endif
\ No newline at end of file