2019 Off season development Test of CAN communication Nucleo Board STM32 F303K8

Dependencies:   mbed

Revision:
0:76c82256b57e
diff -r 000000000000 -r 76c82256b57e main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Mar 12 14:32:13 2020 +0000
@@ -0,0 +1,58 @@
+/** NucleoF303k8 CAN TEST CODE **/
+/** 2019/11/28 Coding by Nagito Sukegawa **/
+//MotorDriver
+//https://os.mbed.com/users/YutaTogashi/code/robocon2019_TBCMotorDriver_Ver5/
+
+#include "mbed.h"
+
+void canRcv(void);
+char RcvData[8];
+DigitalOut myled(PB_3);   //Nucleoの時
+DigitalOut led1(PA_3);  //チップ の時
+DigitalOut led2(PA_4);  //チップ の時
+DigitalOut led3(PA_5);  //チップ の時
+Serial pc(PA_2,NC,115200);    //Nucleoの時
+//Serial pc(PA_9,PA_10,115200);    //チップ の時
+CAN can(PA_11, PA_12,500000);
+CANMessage msg(0x456,CANStandard);
+
+int main()
+{
+    pc.printf("\033[2J\033[1;1HSTART\n");
+    can.attach(&canRcv,CAN::RxIrq);
+    while(1) {
+        led1 = !led1;
+//        pc.printf("\033[2;1HCAN DATA[0]: 0x%x", RcvData[0]);
+//        pc.printf("\033[3;1HCAN DATA[1]: 0x%x", RcvData[1]);
+//        pc.printf("\033[4;1HCAN DATA[2]: 0x%x", RcvData[2]);
+//        pc.printf("\033[5;1HCAN DATA[3]: 0x%x", RcvData[3]);
+//        pc.printf("\033[6;1HCAN DATA[4]: 0x%x", RcvData[4]);
+//        pc.printf("\033[7;1HCAN DATA[5]: 0x%x", RcvData[5]);
+//        pc.printf("\033[8;1HCAN DATA[6]: 0x%x", RcvData[6]);
+//        pc.printf("\033[9;1HCAN DATA[7]: 0x%x", RcvData[7]);
+        wait(0.1);
+    }
+}
+
+
+/** CAN受信関数 **/
+void canRcv(void)
+{
+    myled =!myled;
+    led2=!led2;
+    can.read(msg);
+    pc.printf("\033[1;1HCAN TRANSID: 0x%x", msg.id);
+//    if(msg.id == 0x456) {
+    for(uint8_t i=0; i<8; i++) {
+        RcvData[i] = msg.data[i];
+    }
+    pc.printf("\033[2;1HCAN DATA[0]: 0x%x", RcvData[0]);
+    pc.printf("\033[3;1HCAN DATA[1]: 0x%x", RcvData[1]);
+    pc.printf("\033[4;1HCAN DATA[2]: 0x%x", RcvData[2]);
+//        pc.printf("\033[5;1HCAN DATA[3]: 0x%x", RcvData[3]);
+//        pc.printf("\033[6;1HCAN DATA[4]: 0x%x", RcvData[4]);
+//        pc.printf("\033[7;1HCAN DATA[5]: 0x%x", RcvData[5]);
+//        pc.printf("\033[8;1HCAN DATA[6]: 0x%x", RcvData[6]);
+//        pc.printf("\033[9;1HCAN DATA[7]: 0x%x", RcvData[7]);
+//    }
+}
\ No newline at end of file