【问题标题】:SeeedStudio CAN bus shield arduino ECU_RequestSeeedStudio CAN 总线屏蔽 arduino ECU_Request
【发布时间】:2015-05-24 20:16:46
【问题描述】:

我试图制作一个 ecuRequest,它将一个 PID 发送到一个 can 网络,然后接收一条消息。我从这篇文章http://skpang.co.uk/blog/archives/55 的演示草图中得到了这个想法。我尝试使用 https://github.com/Seeed-Studio/CAN_BUS_Shield 此处找到的 seeedstudio 库来模仿 ecu_req。以下是我到目前为止所拥有的。当我将缓冲区连接到我的汽车时,缓冲区会被填满,但它似乎不是正确的数据。

char MCP_CAN::pidRequest(unsigned char pid, INT8U buf,float& engineData)
{
INT8U len = 8;
float engine_data;
uint8_t data[8];
data[0] = 0x02;
data[1] = 0x01;
data[2] = 0x0c;
data[3] = 0x00;
data[4] = 0x00;
data[5] = 0x00;
data[6] = 0x00;
data[7] = 0x00;
//uint8_t *ptr = data;

mcp2515_modifyRegister(MCP_CANCTRL, (1<<7)|(1<<6)|(1<<5), 0); //change     mode_mask if doesnt work

 if(sendMsgBuf(0x7DF, 1, 0, 8, data)==CAN_OK) {
   delay(100);


if(checkReceive()==CAN_MSGAVAIL) {

    if (readMsgBuf(&len, buf)==CAN_OK) {
        //engine_data = ((buf[3]*256)+buf[4])/4;
        Serial.println(buf[0]);
        Serial.println(buf[1]);
        Serial.println(buf[2]);
        Serial.println(buf[3]); 
        Serial.println(buf[4]);
        Serial.println(buf[5]); 
        Serial.println(buf[6]);
        Serial.println(buf[7]);         
                        return 0;
    }
        else{
        return 1;
        }
}
    else{
    return 2;
    }
 }
 else{
 return 3;
 }

【问题讨论】:

    标签: c++ arduino can-bus


    【解决方案1】:

    您只检查一条消息,但总线上有许多不同的消息,无论您发送什么。

    您应该阅读每条消息,直到获得具有您期望的 CAN ID(可能是 CAN ID 0x7e8)的消息,或者在 MCP 芯片中设置适当的过滤器/掩码,这样它只会向您发送相关消息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多