How to get GPIO reading over 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 |
---|---|
0x147 | 8 |
Byte 0 | Byte 1 | Byte 2 | Byte 3 | Byte 4 - Byte 5 | Byte 6 - Byte 7 |
---|---|---|---|---|---|
Receiver address 0x0 | Bank selector 0x8 | Start ID 0x8 (GPIO0) | End ID 0xC (GPIO4) | Sampling period [ms] 0x64 (100ms period) | Delay [ms] 0x64 (100ms) If you set 0 here, you will disable sending of this bank. |
Bank selector
You can configure up to 4 banks. Each bank can have different sampling rate and diferent IDs.
Bank selector | Description |
---|---|
0x8 | Bank 0 |
0x9 | Bank 1 |
0xA | Bank 2 |
0xB | Bank 3 |
How to compute CAN ID
SID is 40, sender address is 7 -> (40 « 3) + 7 = 320 + 7 = 327 (DEC) = 0x147
Step 2: Receive response
Depend on the selected bank, you will get message with these CAN IDs:
CAN ID | Bank |
---|---|
0x150 | 0 |
0x158 | 1 |
0x160 | 2 |
0x168 | 3 |
Structure of the received message is in the table below:
Byte 0 | Byte 1 | Byte 2 - Byte 3 | Byte 4 - Byte 5 | Byte 6 - Byte 7 |
---|---|---|---|---|
Device signature If device is in error, last bit is set. | Start ID | UINT16 value for Start ID | UINT16 value for start ID + 1 | UINT16 value for start ID + 2 |
note
If you configure bank for more than 3 IDs, the response multiplex the values.
For the example above, you will get these two messages, with 100ms delay between them:
CAN ID | DLC |
---|---|
0x150 | 8 |
Byte 0 | Byte 1 | Byte 2 - Byte 3 | Byte 4 - Byte 5 | Byte 6 - Byte 7 |
---|---|---|---|---|
0xA (SC controller, no error) | 0x8 (GPIO0) | UINT16 GPIO0 value [mV] | UINT16 GPIO1 value [mV] | UINT16 GPIO2 value [mV] |
CAN ID | DLC |
---|---|
0x150 | 6 |
Byte 0 | Byte 1 | Byte 2 - Byte 3 | Byte 4 - Byte 5 |
---|---|---|---|
0xA (SC controller, no error) | 0xB (GPIO3) | UINT16 GPIO3 value [mV] | UINT16 GPIO4 value [mV] |