How to read/write drive parameter over CAN bus
In this example, we will read/write the parameter /driver/limiter/ppos
. This parameter has ID 80 (0x50). And we will write the value 1000.0 to it and then read it back.
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 to write a parameter
note
- A list of available parameters can be found here
- Always check the parameter type. Most of them are float, but some integers are also used.
CAN ID | DLC |
---|---|
0x0C7 | 8 |
Byte 0 | Byte 1 | Byte 2 | Byte 3 | Byte 4 | Byte 5 | Byte 6 | Byte 7 |
---|---|---|---|---|---|---|---|
Receiver address 0x0 | Write parameter 0x3 | Parameter ID 0x50 | Array index 0x0 | Float LSB 0x00 | Float 0x00 | Float 0x7A | Float MSB 0x44 |
note
- How to compute CAN ID: SID is 24, sender address is 7 -> (24 « 3) + 7 = 192 + 7 = 199 (DEC) = 0xC7
- Dec
1000.0
is in float0x447a0000
Step 2: Receive a response
CAN ID | DLC |
---|---|
0x0C0 | 6 |
Byte 0 | Byte 1 | Byte 2 | Byte 3 | Byte 4 - Byte 5 |
---|---|---|---|---|
Receiver address 0x7 | Write parameter response 0x43 | Parameter ID 0x50 | 0xFF = error Parameter ID if success | Error code (INT16) |
Step 3: Read back the parameter
CAN ID | DLC |
---|---|
0x0C7 | 8 |
Byte 0 | Byte 1 | Byte 2 | Byte 3 | Byte 4 - Byte 7 |
---|---|---|---|---|
Receiver address 0x0 | Read parameter 0x2 | Parameter ID 0x50 | Array index 0x0 | 0x0 |
Step 4: Receive a response with parameter value
CAN ID | DLC |
---|---|
0x0C0 | 5-8 Depend on parameter type |
Byte 0 | Byte 1 | Byte 2 | Byte 3 | Byte 4 - Byte 5 |
---|---|---|---|---|
Receiver address 0x7 | Read parameter response 0x42 | Parameter ID 0x50 | 0xFF = error Parameter ID if success | Parameter value - 0x00007A44 Error code (INT16) in case of error |
Error code
Error code | Description |
---|---|
-1 | Parameter ID out of bound |
-2 | Parameter not found |
-3 | Variable is not parameter |
-4 | Set value is below minimum |
-5 | Set value is above maximum |
-6 | Parameter is preset type and value is not in the list |