MCUGear 12bit AD 8ch module for LPC1114. It contains wiring data.

Files at this revision

API Documentation at this revision

Comitter:
Info
Date:
Tue May 06 13:39:10 2014 +0000
Commit message:
MCUGear 12bit AD 8ch module for LPC1114.

Changed in this revision

AD8chModuleLPC1114.cpp Show annotated file Show diff for this revision Revisions of this file
AD8chModuleLPC1114.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AD8chModuleLPC1114.cpp	Tue May 06 13:39:10 2014 +0000
@@ -0,0 +1,83 @@
+
+#include "mbed.h"
+#include "MCUGearALPC1114.h"
+#include "MCUGearBaseALPC1114.h"
+#include "AD8chModuleLPC1114.h"
+
+AD8chModule::AD8chModule(SPI _spi, PinName _cs, MCUGear *mcugear)
+    :spi(_spi),cs(_cs) {
+        
+    //miso,mosi,sck,cs
+    mcugear->setWireA(IOMISO, IO_REG_IN_DIR, 0);
+    mcugear->setWireA(IOMOSI, IO_REG_OUT_DIR, 1);
+    mcugear->setWireA(IOSCK, IO_REG_OUT_DIR,2);
+    mcugear->setWireA(IOCS, IO_REG_OUT_DIR,3);
+}
+
+
+void AD8chModule::initAD8ch(MCUGear *mcugear){
+       cs = 1;
+       spi.frequency(2000000); //1MHz
+}
+
+int AD8chModule::readADm(MCUGear *mcugear, char ch){
+
+    char sendData;
+    int whoami[3];
+    char sendData2;
+    
+    //0000 0000 0110 00 00 [0000 0000 0000]
+    
+    if(ch < 8){
+        sendData = 0x18+ch; //0001 1000
+        sendData2 = sendData >> 2;
+        sendData = sendData << 6;
+        
+    }else{
+        return -1;
+    }
+    
+    //12bit AD Mobdule----------------
+    //mcugear->connectModule();   //connect---
+    cs = 0;
+    spi.write(sendData2);
+    whoami[2] = spi.write(sendData);
+    whoami[0] = whoami[2]<<8;
+    whoami[0] = whoami[0] + spi.write(0x00)-0xE000;   //get data from AD device
+    cs = 1;
+    //mcugear->disconnectModule();   //disconnect---
+    return whoami[0];
+    
+}
+
+int AD8chModule::readADa(MCUGear *mcugear, char ch){
+
+    char sendData;
+    int whoami[3];
+    char sendData2;
+    
+    //0000 0000 0110 00 00 [0000 0000 0000]
+    
+    if(ch < 8){
+        sendData = 0x18+ch; //0001 1000
+        sendData2 = sendData >> 2;
+        sendData = sendData << 6;
+        
+    }else{
+        return -1;
+    }
+    
+    //12bit AD Mobdule----------------
+    spi.frequency(2000000); //1MHz
+    cs = 1; //reset CS pin
+    mcugear->connectModuleA();   //connect---
+    cs = 0;
+    spi.write(sendData2);
+    whoami[2] = spi.write(sendData);
+    whoami[0] = whoami[2]<<8;
+    whoami[0] = whoami[0] + spi.write(0x00)-0xE000;   //get data from AD device
+    cs = 1;
+    mcugear->disconnectModule();   //disconnect---
+    return whoami[0];
+    
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AD8chModuleLPC1114.h	Tue May 06 13:39:10 2014 +0000
@@ -0,0 +1,15 @@
+
+#include "commonALPC1114.h"
+
+class AD8chModule
+{   
+    public:
+        AD8chModule(SPI _spi, PinName _cs, MCUGear *mcugear);
+        void IODAmodule(MCUGear *mcugear);
+        int readADm(MCUGear *mcugear, char ch);//manual connection
+        int readADa(MCUGear *mcugear, char ch);//automatic connection
+        void initAD8ch(MCUGear *mcugear);
+    protected:
+        SPI spi;
+        DigitalOut cs;
+};
\ No newline at end of file