111
Dependencies: yezhong_main_controller_copy mbed1-dev
Diff: CAN/CAN.cpp
- Revision:
- 5:2503c88a564f
- Parent:
- 3:940a9e40d327
--- a/CAN/CAN.cpp Wed Jun 30 12:15:37 2021 +0000 +++ b/CAN/CAN.cpp Tue Jan 11 02:19:55 2022 +0000 @@ -1,5 +1,7 @@ #include "CAN.h" #include "used_leg_message.h" +#include "CAN3.h" +#include "mcp2515.h" @@ -8,7 +10,13 @@ CAN df_can(PB_12, PB_13); // CAN Rx pin name, CAN Tx pin name // 定义CAN消息 CANMessage pf_rxMsg, df_rxMsg; // 主控收到的CAN消息 -CANMessage PF_can, DF_can; // 主控发送的CAN消息 +CANMessage pf_txMsg, df_txMsg; //主控发送的CAN消息 + +SPI spi(PA_7,PA_6,PA_5);// mosi, miso, scl //SPI转can +CAN3 df1_can(spi,PA_4); //spi, ncs, itr + +CANMessage df1_txMsg; // 主控收到的CAN消息 +CANMessage df1_rxMsg; // 主控发送的CAN消息 //=================================函数=======================================// @@ -57,17 +65,21 @@ // 多个控制器联合打包准备发送 void PackAll(){ - pack_cmd(&PF_can, a_control.pf); - pack_cmd(&DF_can, a_control.df); + pack_cmd(&pf_txMsg, a_control.pf); + pack_cmd(&df_txMsg, a_control.df); + pack_cmd(&df1_txMsg, a_control.df1); } // 写联合打包的数据 void WriteAll(){ - pf_can.write(PF_can); + pf_can.write(pf_txMsg); + wait(.00002); + df_can.write(df_txMsg); wait(.00002); - df_can.write(DF_can); + df1_can.write(&df1_txMsg); wait(.00002); + } @@ -95,16 +107,21 @@ float t = uint_to_float(i_int, -T_MAX, T_MAX, 12); - if(id==0x03){ + if(id==0x01){ ankle->pf.p = p; ankle->pf.v = v; ankle->pf.t = t; } - else if(id==0x03){ + else if(id==0x02){ ankle->df.p = p; ankle->df.v = v; ankle->df.t = t; } + else if(id==0x03){ + ankle->df1.p = p; + ankle->df1.v = v; + ankle->df1.t = t; + } }