SANPO USB to CAN

SANPO USB to CAN lets a Windows or Linux serial application control classic CAN devices. The host adds a channel number around the CAN ID and data, and the board converts between USB serial and the CAN bus.

Use V47 or later firmware. To use Linux canX, cansend, candump, or python-can directly, see SocketCAN.

Connection and Setup

A complete board normally exposes two USB serial ports. One controls CAN-1 and CAN-2, and the other controls CAN-3 and CAN-4. COM or /dev/ttyACM* numbering may not follow board silkscreen order. For first use, connect only one CAN device to identify the correct port.

  1. Open the corresponding USB serial port in a serial application or program.

  2. Set the serial bitrate to match the CAN device. The factory default is 1 Mbps.

  3. Send AT+ET as text with a CRLF line ending. After receiving OK, use the frame format on this page.

  4. Send CAN frames as hexadecimal or binary data.

Supported CAN bitrates are 100000, 125000, 250000, 500000, and 1000000. The bitrate selected when opening a USB serial port applies to both CAN channels controlled by that port.

Select a CAN Channel

Interfaces controlled by the current USB port

Channel

Target

CAN-1, CAN-2

0x01

CAN-1

CAN-1, CAN-2

0x02

CAN-2

CAN-3, CAN-4

0x03

CAN-3

CAN-3, CAN-4

0x04

CAN-4

Either USB port

0x00

Both CAN channels controlled by the current port

Received frames use local channel numbering: 0x01 is the first channel and 0x02 is the second. Feedback from CAN-3 and CAN-4 therefore also appears as 0x01 and 0x02 on the second USB serial port.

CAN Extended Frames

Transmit and receive use the same format:

Field

Length

Description

Header

2 bytes

Fixed 45 54

Channel

1 byte

CAN interface number

CAN ID

4 bytes

29-bit extended ID, most significant byte first

Data length

1 byte

0 to 8

CAN data

0 to 8 bytes

Actual data

Tail

2 bytes

Fixed 0D 0A

Send 8 bytes to extended ID 0x0000FD01 on Channel 1:

45 54 01 00 00 FD 01 08 01 00 00 00 00 00 00 00 0D 0A

CAN Standard Frames

Transmit and receive use the same format:

Field

Length

Description

Header

2 bytes

Fixed 53 54

Channel

1 byte

CAN interface number

Reserved

2 bytes

Fixed 00 00

CAN ID

2 bytes

11-bit standard ID, most significant byte first

Data length

1 byte

0 to 8

CAN data

0 to 8 bytes

Actual data

Tail

2 bytes

Fixed 0D 0A

Send 4 bytes to standard ID 0x142 on Channel 1:

53 54 01 00 00 01 42 04 11 22 33 44 0D 0A

Save the Default CAN Bitrate

To use a specific bitrate after startup, send as text:

AT+SETCAN=1000000\r\n

Success returns OK\r\n, and the setting remains after a power cycle. Opening the USB serial port later applies the bitrate selected by the host again, so keep the two settings consistent.

CyberGear Example

Example: USB to CAN CyberGear

Windows:

python usb2can_cybergear_sine_demo_v4.py --port COM8 --motors 1 --channel 1

Linux:

sudo python3 usb2can_cybergear_sine_demo_v4.py --port /dev/ttyACM0 --motors 1 --channel 1

Update the serial port, CAN channel, and motor ID to match the wiring. The example defaults to 1 Mbps.

Troubleshooting

Symptom

Action

No USB serial port

Check the cable, driver, and connector, then reconnect the board

Unsure which two CAN channels a port controls

Connect one device and test each USB serial port

Device does not reply

Check the serial/CAN bitrate, Channel, CAN ID, termination, wiring, and device power

Frame is sent on both CAN channels

Channel 0x00 broadcasts to both channels controlled by the current port; select a specific channel

Reply format changed after using another application

Send AT+ET\r\n as text, wait for OK, and retry

USB port is busy

Close other serial or host applications using the port