Each LPC1768 is capable of controlling 2 CAN bus lines. Linking multiple chips together via SPI allows for more bus lines to be monitored simultaneously. Master unit.
Revision 0:855b6e84e744, committed 2014-10-31
- Comitter:
- ggudgel
- Date:
- Fri Oct 31 22:13:47 2014 +0000
- Commit message:
- First working revision. Test functionality of one mbed system controlling another through SPI, while utilizing CAN bus lines.
Changed in this revision
diff -r 000000000000 -r 855b6e84e744 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Oct 31 22:13:47 2014 +0000 @@ -0,0 +1,26 @@ +#include "mbed.h" +#include "spiMasterProtocol.h" + +// https://developer.mbed.org/forum/helloworld/topic/2541/ + +Serial pc(USBTX, USBRX); // tx, rx + +int main() { + spiMasterProtocol* canDevice = new spiMasterProtocol(); + + pc.printf("======================================================\r\n"); + pc.printf("Press any key to start...\r\n"); + pc.getc(); // wait for keyboard + + while (1) { + + canDevice->get42(); + + wait(0.5); // Wait for 5 seconds for readability only + + canDevice->get84(); + + wait(0.5); + + } +} \ No newline at end of file
diff -r 000000000000 -r 855b6e84e744 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Oct 31 22:13:47 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/031413cf7a89 \ No newline at end of file
diff -r 000000000000 -r 855b6e84e744 spiMasterProtocol.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spiMasterProtocol.cpp Fri Oct 31 22:13:47 2014 +0000 @@ -0,0 +1,52 @@ +#include "spiMasterProtocol.h" + +spiMasterProtocol::spiMasterProtocol() { + spiLine = new SPI(p5, p6, p7); + spiLine->format(8,3); // Setup: bit data, high steady state clock, 2nd edge capture + spiLine->frequency(1000000); // 1MHz + + chipSelect = new DigitalOut(p8); + chipSelect->write(1); +} + + int spiMasterProtocol::get42() { + int temp = write(0x42); + wait_us(5); + int data = write(0x00); + wait_us(5); + int dataExtra = write(0x00); + + printf("get42():\n\r"); + printf("temp = %d\n\r", temp); + printf("data = %d\n\r", data); + printf("dataExtra = %d\n\r", data); + printf("\n"); + + return data; +} + + int spiMasterProtocol::get84() { + int temp = write(0x84); + wait_us(5); + int data1 = write(0x00); + wait_us(5); + int data2 = write(0x00); + + printf("get84():\n\r"); + printf("temp = %d\n\r", temp); + printf("data1 = %d\n\r", data1); + printf("data2 = %d\n\r", data2); + printf("\n"); + + return data2; +} + +int spiMasterProtocol::write(int m) { + chipSelect->write(0); + + int returnMess = spiLine->write(m); + + chipSelect->write(1); + + return returnMess; +} \ No newline at end of file
diff -r 000000000000 -r 855b6e84e744 spiMasterProtocol.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spiMasterProtocol.h Fri Oct 31 22:13:47 2014 +0000 @@ -0,0 +1,19 @@ +#ifndef _spiMaster_included_ +#define _spiMaster_included_ +#include "mbed.h" + +class spiMasterProtocol +{ + public: + spiMasterProtocol(); + int get42(void); + int get84(void); + + private: + SPI* spiLine; + DigitalOut* chipSelect; + + int write(int); + +}; +#endif \ No newline at end of file