3914| 1
|
[求助] 用arduino nano 和CAN BUS SHIELD v1.1做CAN 总线,实现arduino与整车... |
int YouWei=0; QD=digitalRead(CANSW); //读CAN模块启动开关状态 if(QD==0){ delay(20); QD=digitalRead(CANSW); //延时20ms后再次判断启动开关的状态 if(QD==0){ if(CAN_MSGAVAIL == CAN.checkReceive()) // check if data coming { CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf Serial.println("\r\n------------------------------------------------------------------"); Serial.print("Get Data From id: "); Serial.println(CAN.getCanId(),HEX); for(int i = 0; i<len; i++) // print the data { Serial.print("0x"); Serial.print(buf[i], HEX); Serial.print("\t"); } Serial.println(); } if(0x08F11EF3 == CAN.getCanId()) //读BMS故障报文 //发送周期500ms { Serial.println("OK01"); if((buf[0]==0)&&(buf[1]==0)) //如果BMS无故障,无电池温度过高、过低,总电压过高、过低,SOC过高、过低,绝缘检测正常。//BMS Err里的第0、 1 字节 // 改动前 //if((buf[0]&0xFF==0)&&(buf[1]&0xFF==0)) { Serial.println("OK02"); if(0x18F105F3 == CAN.getCanId()) //读BMS电压 //发送周期100ms { Serial.println("OK03"); ISGPower[0]=buf[0]; //将电压值写入ISG发电电压报文中,低字节 ISGPower[1]=buf[1]; //将电压值写入ISG发电电压报文中,高字节 SOC=buf[4]; //读SOC值 } Serial.print("SOC="); Serial.println(SOC); |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed