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 "mbed.h"
ggudgel 0:a46303f3277c 2 #include "rtos.h"
ggudgel 0:a46303f3277c 3 #include "CAN_thread.h"
ggudgel 0:a46303f3277c 4
ggudgel 0:a46303f3277c 5 DigitalOut led1(LED1);
ggudgel 0:a46303f3277c 6 DigitalOut led2(LED2);
ggudgel 0:a46303f3277c 7 CAN can1(p9, p10);
ggudgel 0:a46303f3277c 8 CAN can2(p30, p29);
ggudgel 0:a46303f3277c 9 char counter1 = 0;
ggudgel 0:a46303f3277c 10
ggudgel 0:a46303f3277c 11 void sendBUS1(void const *args) {
ggudgel 0:a46303f3277c 12 if(can1.write(CANMessage(1337, &counter1, 1))) {
ggudgel 0:a46303f3277c 13 counter1++;
ggudgel 0:a46303f3277c 14 }
ggudgel 0:a46303f3277c 15 led1 = !led1;
ggudgel 0:a46303f3277c 16 }
ggudgel 0:a46303f3277c 17
ggudgel 0:a46303f3277c 18 void CAN_thread (void const *args) {
ggudgel 0:a46303f3277c 19 can1.frequency(125000);
ggudgel 0:a46303f3277c 20 can2.frequency(125000);
ggudgel 0:a46303f3277c 21
ggudgel 0:a46303f3277c 22 RtosTimer CAN1send(sendBUS1, osTimerPeriodic);
ggudgel 0:a46303f3277c 23 CAN1send.start(1000);
ggudgel 0:a46303f3277c 24 CANMessage msg;
ggudgel 0:a46303f3277c 25 while(1) {
ggudgel 0:a46303f3277c 26 if(can2.read(msg)) {
ggudgel 0:a46303f3277c 27 led2 = !led2;
ggudgel 0:a46303f3277c 28 }
ggudgel 0:a46303f3277c 29 Thread::wait(10);
ggudgel 0:a46303f3277c 30 }
ggudgel 0:a46303f3277c 31 }