AD2ch Module library for MCU Gear with LPC1114. It contains wiring data.
Revision 0:0050ff39b5f7, committed 2014-05-06
- Comitter:
- Info
- Date:
- Tue May 06 07:14:31 2014 +0000
- Commit message:
- AD2ch Module library for MCU Gear with LPC1114.
Changed in this revision
AD2chModuleLPC1114.cpp | Show annotated file Show diff for this revision Revisions of this file |
AD2chModuleLPC1114.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AD2chModuleLPC1114.cpp Tue May 06 07:14:31 2014 +0000 @@ -0,0 +1,86 @@ + +#include "mbed.h" +#include "MCUGearALPC1114.h" +#include "MCUGearBaseALPC1114.h" +#include "AD2chModuleLPC1114.h" + +AD2chModule::AD2chModule(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 AD2chModule::initAD2ch(MCUGear *mcugear){ + + cs = 1; + + //12bit SPI DA module---------------- + spi.frequency(2000000); //1MHz +} + +int AD2chModule::readADm(MCUGear *mcugear, char ch){ + + char sendData; + int whoami[3]; + +// spi.frequency(2000000); //1MHz + if(ch == 0){ + sendData = 0x80; + }else if(ch == 1){ + sendData = 0xC0; + }else{ + return -1; + } + + //12bit AD Mobdule---------------- + //cs = 1; //reset CS pin +// mcugear->connectModule(); //connect--- + + cs = 0; + //FRDM KL25Z is 8-bit format. + whoami[2] = spi.write(0x01);//0000 0001 + whoami[2] = spi.write(sendData); + whoami[0] = whoami[2]<<8; + whoami[0] = whoami[0] + spi.write(0x00) - 0xE000;//0000 0000 +// whoami[2] = 0;//clear buffer + cs = 1; +// mcugear->disconnectModule(); //disconnect--- + return whoami[0]; + +} + +int AD2chModule::readADa(MCUGear *mcugear, char ch){ + + char sendData; + int whoami[3]; + + spi.frequency(2000000); //1MHz + if(ch == 0){ + sendData = 0x80; + }else if(ch == 1){ + sendData = 0xC0; + }else{ + return -1; + } + + //12bit AD Mobdule---------------- + cs = 1; //reset CS pin + mcugear->connectModuleA(); //connect--- + + cs = 0; + //FRDM KL25Z is 8-bit format. + whoami[2] = spi.write(0x01);//0000 0001 + whoami[2] = spi.write(sendData); + whoami[0] = whoami[2]<<8; + whoami[0] = whoami[0] + spi.write(0x00) - 0xE000;//0000 0000 +// whoami[2] = 0;//clear buffer + cs = 1; + mcugear->disconnectModule(); //disconnect--- + return whoami[0]; + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AD2chModuleLPC1114.h Tue May 06 07:14:31 2014 +0000 @@ -0,0 +1,15 @@ + +#include "commonALPC1114.h" + +class AD2chModule +{ + public: + AD2chModule(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 initAD2ch(MCUGear *mcugear); + protected: + SPI spi; + DigitalOut cs; +}; \ No newline at end of file