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.

Dependencies:   mbed

Committer:
ggudgel
Date:
Fri Oct 31 22:13:47 2014 +0000
Revision:
0:855b6e84e744
First working revision. Test functionality of one mbed system controlling another through SPI, while utilizing CAN bus lines.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ggudgel 0:855b6e84e744 1 #include "spiMasterProtocol.h"
ggudgel 0:855b6e84e744 2
ggudgel 0:855b6e84e744 3 spiMasterProtocol::spiMasterProtocol() {
ggudgel 0:855b6e84e744 4 spiLine = new SPI(p5, p6, p7);
ggudgel 0:855b6e84e744 5 spiLine->format(8,3); // Setup: bit data, high steady state clock, 2nd edge capture
ggudgel 0:855b6e84e744 6 spiLine->frequency(1000000); // 1MHz
ggudgel 0:855b6e84e744 7
ggudgel 0:855b6e84e744 8 chipSelect = new DigitalOut(p8);
ggudgel 0:855b6e84e744 9 chipSelect->write(1);
ggudgel 0:855b6e84e744 10 }
ggudgel 0:855b6e84e744 11
ggudgel 0:855b6e84e744 12 int spiMasterProtocol::get42() {
ggudgel 0:855b6e84e744 13 int temp = write(0x42);
ggudgel 0:855b6e84e744 14 wait_us(5);
ggudgel 0:855b6e84e744 15 int data = write(0x00);
ggudgel 0:855b6e84e744 16 wait_us(5);
ggudgel 0:855b6e84e744 17 int dataExtra = write(0x00);
ggudgel 0:855b6e84e744 18
ggudgel 0:855b6e84e744 19 printf("get42():\n\r");
ggudgel 0:855b6e84e744 20 printf("temp = %d\n\r", temp);
ggudgel 0:855b6e84e744 21 printf("data = %d\n\r", data);
ggudgel 0:855b6e84e744 22 printf("dataExtra = %d\n\r", data);
ggudgel 0:855b6e84e744 23 printf("\n");
ggudgel 0:855b6e84e744 24
ggudgel 0:855b6e84e744 25 return data;
ggudgel 0:855b6e84e744 26 }
ggudgel 0:855b6e84e744 27
ggudgel 0:855b6e84e744 28 int spiMasterProtocol::get84() {
ggudgel 0:855b6e84e744 29 int temp = write(0x84);
ggudgel 0:855b6e84e744 30 wait_us(5);
ggudgel 0:855b6e84e744 31 int data1 = write(0x00);
ggudgel 0:855b6e84e744 32 wait_us(5);
ggudgel 0:855b6e84e744 33 int data2 = write(0x00);
ggudgel 0:855b6e84e744 34
ggudgel 0:855b6e84e744 35 printf("get84():\n\r");
ggudgel 0:855b6e84e744 36 printf("temp = %d\n\r", temp);
ggudgel 0:855b6e84e744 37 printf("data1 = %d\n\r", data1);
ggudgel 0:855b6e84e744 38 printf("data2 = %d\n\r", data2);
ggudgel 0:855b6e84e744 39 printf("\n");
ggudgel 0:855b6e84e744 40
ggudgel 0:855b6e84e744 41 return data2;
ggudgel 0:855b6e84e744 42 }
ggudgel 0:855b6e84e744 43
ggudgel 0:855b6e84e744 44 int spiMasterProtocol::write(int m) {
ggudgel 0:855b6e84e744 45 chipSelect->write(0);
ggudgel 0:855b6e84e744 46
ggudgel 0:855b6e84e744 47 int returnMess = spiLine->write(m);
ggudgel 0:855b6e84e744 48
ggudgel 0:855b6e84e744 49 chipSelect->write(1);
ggudgel 0:855b6e84e744 50
ggudgel 0:855b6e84e744 51 return returnMess;
ggudgel 0:855b6e84e744 52 }