Hi there,
I've got a nice CAN bus board set up using a Teensy 3.2 which I've used successfully to interrogate an OBD port of my car using the Collin80 fork of FlexCAN. No issues with it, and my typical message forming code looks like this (for OBD use):
void CAN_Request(byte CAN_MODE, byte PID_CALL) {
can_MsgTx.ext = 0;
can_MsgTx.id = PID_REQUEST;
can_MsgTx.len = 8;
can_MsgTx.buf[0] = 0x02; //Length in number of bytes of remaining data (2 bytes = 02, 3 bytes = 03 etc)
can_MsgTx.buf[1] = CAN_MODE;
can_MsgTx.buf[2] = PID_CALL;
can_MsgTx.buf[3] = 0;
can_MsgTx.buf[4] = 0;
can_MsgTx.buf[5] = 0;
can_MsgTx.buf[6] = 0;
can_MsgTx.buf[7] = 0;
can_MsgTx.flags.extended = 0;
can_MsgTx.flags.remote = 0;
//Serial.print("CAN SENT: "); hexDump(8, can_MsgTx.buf); //Diagnostic - Dump message to Serial//@@@@@@@@@@@@@@@@@@@@@@@@@@@CAN DIAGNOSTICS@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//Serial.println(currentMillis / 10);
Can0.write(can_MsgTx); //Send message
}
My next challenge is that I want to try to use this to communicate with a Bosch wiper motor, for which I have the CAN message table, but I'm not entirely sure how to use it. I have a number of functions listed. I'll list three of them below as examples:
-
Teach Mode:
ID = 0x6000
Data = 1 or 0
Start bit = 14
Length = 1
Byte = 2 -
Torque Limit:
ID = 0x6006
Data = 00 or 01 or 10 or 11
Start bit = 54
Length = 2
Byte = 7 -
Wipe Command:
ID: 0x6000
Data: 0, 1, 2, 3, 4, 5, 6 or 7
Start bit: 8
Length = 3
Byte = 2
So to translate this into a format that my CAN code can interpret, do I need to convert this into Hex or can I input directly in binary?
As I understand it, for the first example, I would need to set it up like this:
ID = 0x6000,
Length = 1
Buf [0] = 00000010 = 0x02???
For example 2
ID = 0x6006
Length = 7
Buf[0] = 0
Buf[1] = 0
Buf[2] = 0
Buf[3] = 0
Buf[4] = 0
Buf[5] = 0
Buf[6] = 00000011 (for 11) = 0x03??
For example 3
ID = 0x6000
Length = 2
Buf[0] = 0
Buf[1] = 01100000 (for 6) = 0x60???
Does this look right to you guys? I've not seen message instructions written like this before so I'm a bit unsure... I'll hopefully have a unit to test this on in a couple of weeks but I want to try to make sure I have the correct message construction before attempting to communicate