DA module library for MCU Gear with LPC1114FN28. This library contains wiring setting function.
Revision 0:177e80bbbd3b, committed 2014-05-05
- Comitter:
- Info
- Date:
- Mon May 05 10:40:11 2014 +0000
- Commit message:
- DA module library for MCU Gear with LPC1114FN28 mbed.; This library contain wiring setting for DA module.
Changed in this revision
DAmoduleLPC1114.cpp | Show annotated file Show diff for this revision Revisions of this file |
DAmoduleLPC1114.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 177e80bbbd3b DAmoduleLPC1114.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DAmoduleLPC1114.cpp Mon May 05 10:40:11 2014 +0000 @@ -0,0 +1,74 @@ + +#include "mbed.h" +#include "MCUGearALPC1114.h" +#include "MCUGearBaseALPC1114.h" +#include "DAmoduleLPC1114.h" + +DAmodule::DAmodule(SPI _spi, PinName _cs, PinName _dout1, MCUGear *mcugear) + :spi(_spi),cs(_cs), dout1(_dout1) { + + //Dout,mosi,sck,cs + mcugear->setWireA(IOout1, IO_REG_OUT_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 DAmodule::initDA(MCUGear *mcugear){ + + cs = 1; + dout1=1; //reset ratch signal + + //12bit SPI DA module---------------- + spi.frequency(20000000); //10MHz +} + +void DAmodule::writeDAm(MCUGear *mcugear, int data){ + + //12bit SPI DA module---------------- + //DA signl uses the data of AD 0ch. + //cs = 1; + //dout1=1; //reset ratch signal + + //12bit SPI DA module---------------- + //spi.frequency(20000000); //10MHz + //connection + //mcugear->connectModuleA(); //connect--- + cs = 0; + spi.write((0x30)+((data>>8)&0x0F));//write 0011 0000 + spi.write(data&0xFF);//write 0011 1000 0000 0000 + + wait_us(1); //over 15nsec + cs = 1; //CS high + wait_us(1); //over 40nsec + dout1=0; //ratch for DA out enable + wait_us(1); //over 100nsec + dout1=1; //reset ratch signal + //mcugear->disconnectModule(); //disconnect--- + //wait_us(1); //wait after disconnect +} + +void DAmodule::writeDAa(MCUGear *mcugear, int data){ + + //12bit SPI DA module---------------- + //DA signl uses the data of AD 0ch. + cs = 1; + dout1=1; //reset ratch signal + + //12bit SPI DA module---------------- + spi.frequency(20000000); //10MHz + //connection + mcugear->connectModuleA(); //connect--- + cs = 0; + spi.write((0x30)+((data>>8)&0x0F));//write 0011 0000 + spi.write(data&0xFF);//write 0011 1000 0000 0000 + + wait_us(1); //over 15nsec + cs = 1; //CS high + wait_us(1); //over 40nsec + dout1=0; //ratch for DA out enable + wait_us(1); //over 100nsec + dout1=1; //reset ratch signal + mcugear->disconnectModule(); //disconnect--- +}
diff -r 000000000000 -r 177e80bbbd3b DAmoduleLPC1114.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DAmoduleLPC1114.h Mon May 05 10:40:11 2014 +0000 @@ -0,0 +1,16 @@ + +#include "commonALPC1114.h" + +class DAmodule +{ + public: + DAmodule(SPI _spi, PinName _cs, PinName _dout1, MCUGear *mcugear); + void IODAmodule(MCUGear *mcugear); + void writeDAm(MCUGear *mcugear, int data);//manual connection + void writeDAa(MCUGear *mcugear, int data);//automatic connection + void initDA(MCUGear *mcugear); + protected: + SPI spi; + DigitalOut cs; + DigitalOut dout1; +}; \ No newline at end of file