Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:33432ad74af7
- Child:
- 1:f0e74f06b93b
diff -r 000000000000 -r 33432ad74af7 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Mar 04 09:33:28 2020 +0000 @@ -0,0 +1,34 @@ +#include "mbed.h" + +CAN can1(PB_5,PB_13); +Ticker ticker; +DigitalIn button(USER_BUTTON); +int x; +char can_data2[2]= {0,0}; +int data2; +void can_read() +{ + x=100; + CANMessage msg; + if(can1.read(msg)) { + if(msg.id == 1) { + x=(short)((msg.data[0]<<8)|msg.data[1]); + } else { + x=200; + } + } + printf("%d\r\n",x); + + data2=1000; + can_data2[0]=data2>>8; + can_data2[1]=data2&255; + if(can1.write(CANMessage(2,can_data2,2))) { + printf("send\r\n"); + } +} + +int main() +{ + can1.frequency(1000000); + ticker.attach(&can_read,0.01); +}