# SANPO USB to FDCAN SANPO USB to FDCAN sends and receives CAN FD standard and extended frames through USB serial, with up to 64 data bytes per frame. Firmware always enables BRS for transmitted CAN FD frames. For classic CAN, see [SANPO USB to CAN](usb_can). To use standard Linux `canX` interfaces, see [SocketCAN](socketcan). ## Connection and Setup 1. Open the USB serial port for the target MCU. 2. Send `AT+SETFDCAN?` and confirm that arbitration and data-phase bitrates match the bus. 3. To change them, send `AT+SETFDCAN=,` as text with `CRLF`. 4. Send complete frames from this page in hexadecimal or binary mode. Factory defaults are 1 Mbps arbitration and 5 Mbps data. See [Communication Settings](baudrate_config) for supported values. ## Select a CAN FD Channel | Current USB port | Channel | Target | | --- | --- | --- | | Port for CAN-1/2 | `0x01` | CAN-1 | | Port for CAN-1/2 | `0x02` | CAN-2 | | Port for CAN-3/4 | `0x03` | CAN-3 | | Port for CAN-3/4 | `0x04` | CAN-4 | | Either USB port | `0x00` | Both CAN FD interfaces on the current MCU | For transmission, `1/3` select the first local interface and `2/4` select the second. Replies only use local Channel `1/2`. ## Data Length Code CAN FD supports only these length codes: | Code | Data bytes | Code | Data bytes | | --- | ---: | --- | ---: | | `00` | 0 | `08` | 8 | | `01` | 1 | `09` | 12 | | `02` | 2 | `0A` | 16 | | `03` | 3 | `0B` | 20 | | `04` | 4 | `0C` | 24 | | `05` | 5 | `0D` | 32 | | `06` | 6 | `0E` | 48 | | `07` | 7 | `0F` | 64 | The actual data length must match the code. ## CAN FD Extended Frame Transmit and receive use the same format: | Field | Length | Description | | --- | ---: | --- | | Header | 2 bytes | Fixed `45 46` (`EF`) | | Channel | 1 byte | CAN FD interface number | | CAN ID | 4 bytes | 29-bit extended ID, most significant byte first | | Length code | 1 byte | `00` to `0F` | | Data | 0 to 64 bytes | Size selected by the length code | | Tail | 2 bytes | Fixed `0D 0A` | Send 16 bytes to extended ID `0x1F100101` on Channel 1: ```text 45 46 01 1F 10 01 01 0A 01 01 01 01 42 00 00 00 01 01 64 00 78 56 34 12 0D 0A ``` `0A` selects 16 data bytes. ## CAN FD Standard Frame | Field | Length | Description | | --- | ---: | --- | | Header | 2 bytes | Fixed `53 46` (`SF`) | | Channel | 1 byte | CAN FD interface number | | Reserved | 2 bytes | Fixed `00 00` | | CAN ID | 2 bytes | 11-bit standard ID, most significant byte first | | Length code | 1 byte | `00` to `0F` | | Data | 0 to 64 bytes | Size selected by the length code | | Tail | 2 bytes | Fixed `0D 0A` | Send 12 bytes to standard ID `0x142` on Channel 2: ```text 53 46 02 00 00 01 42 09 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0A ``` ## Parse Replies Motor feedback returns in the same `SF` or `EF` format. Use the header to identify standard or extended frames, the length code to determine data size, and Channel to identify the first or second local interface. USB is a byte stream. One serial `read()` may return part of a frame, one frame, or multiple frames. Parse continuously using the header and length code rather than assuming each read returns exactly one frame. ## Troubleshooting | Symptom | Action | | --- | --- | | Classic CAN device does not reply | Use `ST/ET` for classic CAN, not `SF/EF` | | CAN FD device does not reply | Check arbitration bitrate, data bitrate, BRS, termination, and CAN FD support on the peer | | Invalid transmit length | Use only 0 to 8, 12, 16, 20, 24, 32, 48, or 64 bytes | | Reply Channel only shows 1/2 | Replies use local numbering; this is normal | | Multiple frames arrive together | Parse continuously by header, length code, and tail rather than serial read boundaries |