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. Slave unit.

Dependencies:   mbed-rtos mbed

Committer:
ggudgel
Date:
Fri Oct 31 22:14:03 2014 +0000
Revision:
0:a46303f3277c
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:a46303f3277c 1 #include "spiSlaveProtocol.h"
ggudgel 0:a46303f3277c 2
ggudgel 0:a46303f3277c 3 spiSlaveProtocol::spiSlaveProtocol(Serial* PC) {
ggudgel 0:a46303f3277c 4 spiLine = new SPISlave(p5, p6, p7, p8);
ggudgel 0:a46303f3277c 5 spiLine->format(8,3); // Setup: bit data, high steady state clock, 2nd edge capture
ggudgel 0:a46303f3277c 6 spiLine->frequency(1000000); // 1MHz
ggudgel 0:a46303f3277c 7
ggudgel 0:a46303f3277c 8 pc = PC; // tx, rx
ggudgel 0:a46303f3277c 9 pc->printf("======================================================\r\n");
ggudgel 0:a46303f3277c 10
ggudgel 0:a46303f3277c 11 timout = new Timer();
ggudgel 0:a46303f3277c 12
ggudgel 0:a46303f3277c 13 state = 0;
ggudgel 0:a46303f3277c 14 commandBytes = 0;
ggudgel 0:a46303f3277c 15 }
ggudgel 0:a46303f3277c 16
ggudgel 0:a46303f3277c 17 void spiSlaveProtocol::run() {
ggudgel 0:a46303f3277c 18 if (spiLine->receive()) {
ggudgel 0:a46303f3277c 19 int valueFromMaster = spiLine->read();
ggudgel 0:a46303f3277c 20
ggudgel 0:a46303f3277c 21 if (valueFromMaster == 0x42) {
ggudgel 0:a46303f3277c 22 spiLine->reply(0xAA); // Prime SPI with next reply
ggudgel 0:a46303f3277c 23 //pc->printf("Life rxvd, next line will reply with 0xAA\n\r");
ggudgel 0:a46303f3277c 24 }
ggudgel 0:a46303f3277c 25
ggudgel 0:a46303f3277c 26 else if (valueFromMaster == 0x84) {
ggudgel 0:a46303f3277c 27 spiLine->reply(0xAB);
ggudgel 0:a46303f3277c 28 spiLine->reply(0xAC);
ggudgel 0:a46303f3277c 29 //pc->printf("Life multiplyer, next line will reply with 2 x 0xBB\n\r");
ggudgel 0:a46303f3277c 30 }
ggudgel 0:a46303f3277c 31 }
ggudgel 0:a46303f3277c 32 }