-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
242 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,7 @@ struct dac_s { | |
|
||
struct can_s { | ||
LPC_CAN_TypeDef *dev; | ||
int index; | ||
}; | ||
|
||
struct i2c_s { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "mbed.h" | ||
|
||
Ticker ticker; | ||
DigitalOut led1(LED1); | ||
DigitalOut led2(LED2); | ||
CAN can1(p9, p10); | ||
CAN can2(p30, p29); | ||
char counter = 0; | ||
|
||
void printmsg(char *title, CANMessage *msg) { | ||
printf("%s [%03X]", title, msg->id); | ||
for(char i = 0; i < msg->len; i++) { | ||
printf(" %02X", msg->data[i]); | ||
} | ||
printf("\n"); | ||
} | ||
|
||
void send() { | ||
printf("send()\n"); | ||
CANMessage msg = CANMessage(1337, &counter, 1); | ||
if(can1.write(msg)) { | ||
printmsg("Tx message:", &msg); | ||
counter++; | ||
} | ||
led1 = !led1; | ||
} | ||
|
||
int main() { | ||
printf("main()\n"); | ||
ticker.attach(&send, 1); | ||
CANMessage msg; | ||
while(1) { | ||
printf("loop()\n"); | ||
if(can1.read(msg)) { | ||
printmsg("Rx message:", &msg); | ||
led2 = !led2; | ||
} | ||
wait(0.2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "mbed.h" | ||
|
||
Ticker ticker; | ||
DigitalOut led1(LED1); | ||
DigitalOut led2(LED2); | ||
CAN can1(p9, p10); | ||
CAN can2(p30, p29); | ||
char counter = 0; | ||
|
||
void printmsg(char *title, CANMessage *msg) { | ||
printf("%s [%03X]", title, msg->id); | ||
for(char i = 0; i < msg->len; i++) { | ||
printf(" %02X", msg->data[i]); | ||
} | ||
printf("\n"); | ||
} | ||
|
||
void send() { | ||
printf("send()\n"); | ||
CANMessage msg = CANMessage(1337, &counter, 1); | ||
if(can1.write(msg)) { | ||
printmsg("Tx message:", &msg); | ||
counter++; | ||
} | ||
led1 = !led1; | ||
} | ||
|
||
void read() { | ||
CANMessage msg; | ||
printf("rx()\n"); | ||
if(can1.read(msg)) { | ||
printmsg("Rx message:", &msg); | ||
led2 = !led2; | ||
} | ||
} | ||
|
||
int main() { | ||
printf("main()\n"); | ||
ticker.attach(&send, 1); | ||
can1.attach(&read); | ||
while(1) { | ||
printf("loop()\n"); | ||
wait(1); | ||
} | ||
} |
Oops, something went wrong.