atsushi uno
/
CANHelloTest
Mbed Studio Test upload
Revision 0:22ffaa4d0128, committed 2019-05-11
- Comitter:
- aie
- Date:
- Sat May 11 01:59:39 2019 +0000
- Commit message:
- Mbed Studio up load
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 22ffaa4d0128 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat May 11 01:59:39 2019 +0000 @@ -0,0 +1,72 @@ +#include "mbed.h" + +Ticker ticker; +Ticker ticker2; + +DigitalOut led1(LED1); +DigitalOut led2(LED2); +DigitalOut led3(LED3); +DigitalOut led4(LED4); + +CAN can2(p9, p10); +CAN can1(p30, p29); +char counter = 0; + +void send() { + + led1 = !led1; + return; + + printf("send()\n"); + unsigned char d[8]; + d[0] = d[1] = 0xFF; + d[2] = 0x00; + d[3] = 0xaa; + d[4] = 0xc0; + d[5] = d[6] = d[7] = 0; + + if(can1.write(CANMessage(0x7C1, (char *)d, 8))) { + //printf("wloop()\n"); + counter++; + //printf("Message sent: %d\n", counter); + } + led1 = !led1; +} + void send2() { + printf("send()\n"); + unsigned char d[8]; + d[0] = d[1] = 0x55; + d[2] = 0x00; + d[3] = 0xaa; + d[4] = 0xc0; + d[5] = d[6] = d[7] = 0; + + if(can2.write(CANMessage(0x0301, (char *)d, 8))) { + //printf("wloop()\n"); + counter++; + //printf("Message sent: %d\n", counter); + } + led3 = !led3; +} +int main() { + printf("main()\n"); + can1.frequency(500000); + can2.frequency(500000); + ticker.attach(&send, 1); + ticker2.attach(&send2, 1); + + CANMessage msg; + while(1) { + //printf("loop()\n"); + if(can2.read(msg)) { + printf("Message received: %d\n", msg.data[0]); + led2 = !led2; + } + if(can1.read(msg)) { + printf("Message received: %d\n", msg.data[0]); + led4 = !led4; + } + + wait(0.1); + } +} \ No newline at end of file
diff -r 000000000000 -r 22ffaa4d0128 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat May 11 01:59:39 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/e7ca05fa8600 \ No newline at end of file