How to Get GPIO Reading Over CAN Bus
Prerequisites:
- Device is powered ON
- CAN bus is functioning properly
- Device address is set to 0
note
- All payloads use big-endian byte order
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) Setting this to 0 disables bank transmission |
Bank Selector
Up to 4 banks can be configured. Each bank can have different sampling rates and IDs.
Bank selector | Description |
---|---|
0x8 | Bank 0 |
0x9 | Bank 1 |
0xA | Bank 2 |
0xB | Bank 3 |
How to Calculate CAN ID
SID is 40, sender address is 7 -> (40 � 3) + 7 = 320 + 7 = 327 (DEC) = 0x147
Step 2: Receive Response
Messages will be received with the following CAN IDs based on the selected bank:
CAN ID | Bank |
---|---|
0x150 | 0 |
0x158 | 1 |
0x160 | 2 |
0x168 | 3 |
Structure of received messages:
Byte 0 | Byte 1 | Byte 2 - Byte 3 | Byte 4 - Byte 5 | Byte 6 - Byte 7 |
---|---|---|---|---|
Device signature Last bit is set if device is in error | Start ID | UINT16 value for Start ID | UINT16 value for start ID + 1 | UINT16 value for start ID + 2 |
note
For configurations with more than 3 IDs, the response values are multiplexed.
For the example above, you will receive these two messages with a 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] |