这是一个调用hal ,来控制CAN的程序

Dependencies:   mbed TextLCD

Revision:
2:4472d83236bc
Parent:
1:cac0160da4f7
--- a/main.cpp	Tue Mar 21 05:13:15 2017 +0000
+++ b/main.cpp	Tue Mar 21 15:26:16 2017 +0800
@@ -1,5 +1,6 @@
 #include "mbed.h"
 #include "stm32f1xx_hal.h"
+#include "TextLCD.h"
 DigitalOut myled(LED1);
 SPI device(PB_15, PB_14, PB_13,NC); // mosi, miso, sclk, ssel
 CAN_HandleTypeDef hcan;
@@ -9,7 +10,7 @@
 static void MX_CAN1_Init(void)
 {
   hcan.Instance = CAN1;
-  hcan.pTxMsg=&TxMessage;     //发送消息
+  hcan.pTxMsg=&TxMessage;     //发送消æ?
   hcan.Init.Prescaler = 6;
   hcan.Init.Mode = CAN_MODE_LOOPBACK;
   hcan.Init.SJW = CAN_SJW_1TQ;
@@ -25,19 +26,20 @@
   {
     //Error_Handler();
   }
+  
 }
 //       其他,失败;
 uint8_t CAN1_Send_Msg(uint8_t* msg,uint8_t len)
 {   
    uint16_t i=0;
-    hcan.pTxMsg->StdId=0X12;        //标准标识符
-    hcan.pTxMsg->ExtId=0X12;        //扩展标识符(29位)
-    hcan.pTxMsg->IDE=CAN_ID_STD;    //使用标准帧
-    hcan.pTxMsg->RTR=CAN_RTR_DATA;  //数据帧
+    hcan.pTxMsg->StdId=0X12;        //标准标识ç¬?
+    hcan.pTxMsg->ExtId=0X12;        //扩展标识ç¬?(29ä½?)
+    hcan.pTxMsg->IDE=CAN_ID_STD;    //使用标准å¸?
+    hcan.pTxMsg->RTR=CAN_RTR_DATA;  //数据å¸?
     hcan.pTxMsg->DLC=len;                
     for(i=0;i<len;i++)
     hcan.pTxMsg->Data[i]=msg[i];
-    if(HAL_CAN_Transmit(&hcan,10)!=HAL_OK) return 1;     //发送
+    if(HAL_CAN_Transmit(&hcan,10)!=HAL_OK) return 1;     //发é€?
     return 0;       
 }
 
@@ -84,8 +86,9 @@
     
      uint8_t canbuf[8]={1,2,3,4,5,6,7,8};
     MX_CAN1_Init();
+   
     while(1) {
-       CAN1_Send_Msg(canbuf,8);//发送8个字节 
+       CAN1_Send_Msg(canbuf,8);//发é€?8个字èŠ? 
        i2c.read(address, data, 2);
        device.write(0x55);
         myled = 1; // LED is ON