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:
- 1:32f484ba74a2
- Parent:
- 0:33432ad74af7
--- a/main.cpp Wed Mar 04 09:33:28 2020 +0000
+++ b/main.cpp Wed Dec 15 09:46:21 2021 +0000
@@ -1,34 +1,45 @@
#include "mbed.h"
-CAN can1(PB_5,PB_13);
+CAN can(p30,p29);
Ticker ticker;
-DigitalIn button(USER_BUTTON);
-int x;
-char can_data2[2]= {0,0};
-int data2;
-void can_read()
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+
+char can_data1[2]= {0,0};
+int data1=0;
+CANMessage msg1;
+int y;
+void can1()
{
- x=100;
- CANMessage msg;
- if(can1.read(msg)) {
- if(msg.id == 1) {
- x=(short)((msg.data[0]<<8)|msg.data[1]);
- } else {
- x=200;
+ can_data1[0]=data1>>8;
+ can_data1[1]=data1&255;
+ if(can.write(CANMessage(1,can_data1,2))) {
+ led1 =1;
+ led2=0;
+ printf("can1 send\r\n");
+ } else {
+ led1=0;
+ led2=1;
+ printf("can1 no send\r\n");
+ }
+ if (can1.read(msg1))
+ {
+ if (msg1.id == 2)
+ {
+ y = (short)((msg1.data[0] << 8) | msg1.data[1]);
+ if(y==1000){
+ printf("get responese from can2\r\n");
+ data1++;
+ if(data1>1000)data1=1000;
+ }
}
}
- 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);
-}
+ ticker.attach(&can1,0.001);
+}
\ No newline at end of file