How to perform a task using CAN bus
What do you need to prepare before:
- The controller is turned ON
- CANbus works properly
- The controller CAN address is set to 0
note
- All the values are in big-endian
Step 1: Compose the CAN frame
CAN ID | DLC |
---|---|
0x0C7 | 8 |
Byte 0 | Byte 1 | Byte 2 | Byte 3 - Byte 7 |
---|---|---|---|
Receiver address 0x0 | Perform task 0x4 | task ID | 0x0 |
How to compute CAN ID
SID is 24, sender address is 7 -> (24 « 3) + 7 = 192 + 7 = 199 (DEC) = 0xC7
Task ID list
Task ID | Description |
---|---|
1 | Driver reinit. |
2 | Execute identlin |
3 | Execute identrun |
128 | Save parameters |
129 | Load parameters from flash |
255 | Request task result |
Other | Unsupported command (can be used as heardbeat) |
Step 2: Receive response
CAN ID | DLC |
---|---|
0x0C0 | 3 |
Byte 0 | Byte 1 | Byte 2 |
---|---|---|
Receiver address 0x7 | Perform task - response 0x44 | Task ID |
How to compute CAN ID
SID is 24, sender address is 0 -> (24 « 3) + 0 = 192 (DEC) = 0xC0
note
- If you get DLC = 7. Byte 3 - Byte 7 contains value -1. This means that the task is not supported.
- If there is unfinished task, the response will have the task ID of the unfinished task.
Step 3: Request the task result
CAN ID | DLC |
---|---|
0x0C7 | 8 |
Byte 0 | Byte 1 | Byte 2 | Byte 3 - Byte 7 |
---|---|---|---|
Receiver address 0x0 | Perform task 0x4 | Request resul 0xFF | 0x0 |
Task is still runing
You will get this message, there is running task.
CAN ID | DLC |
---|---|
0x0C0 | 3 |
Byte 0 | Byte 1 | Byte 2 |
---|---|---|
Receiver address 0x7 | Perform task - response 0x44 | Running task ID |
Task finished
With this response, you will get result of the latest task.
CAN ID | DLC |
---|---|
0x0C0 | 7 |
Byte 0 | Byte 1 | Byte 2 | Byte 3 - Byte 7 |
---|---|---|---|
Receiver address 0x7 | Perform task - response 0x44 | Running task ID | Task result |
Usually, if the result is 0, the task is successful. If the result is different from 0, the task is failed.