Share this

USB-based CAN bus adapter design

2026-04-06 06:00:55 · · #1
Abstract: This paper proposes a scheme for connecting a CAN bus network to a computer using a USB interface. The hardware interface circuit between the CAN bus and the computer is discussed, along with the firmware programming method and USB driver design ideas. Keywords: USB, CAN bus, firmware programming adapter, fieldbus. As an emerging technology developed in the 1980s, fieldbus has been widely used in industrial settings. Among the more influential fieldbuses, the CAN bus, with its outstanding advantages, is not only widely used in industrial settings but has also made significant progress in civilian fields such as building automation and intelligent terminal equipment. The implementation of fieldbus network technology requires integration with a computer. Previously, the connection between the CAN bus network and the computer used RS232, ISA, or PCI interfaces. However, with the development of computer interface technology, the ISA interface has gradually been phased out; the RS232 interface has too low a data transmission rate; and although PCI remains the main channel for high-speed peripherals and computer interfaces, its main disadvantages are limited system resources, complex design, the need for high-quality drivers to ensure system stability, and inability to be used for portable computer expansion. With the successive formulation of USB 1.1 and USB 2.0 specifications, new development directions have been proposed for the interface between peripherals and computers. The main features of USB include: simple peripheral installation and hot-swapping capability; high communication speed, with USB 1.1 achieving a full-speed transmission rate of 12Mbps, approximately 100 times faster than standard serial ports; support for multiple device connections; and built-in power supply. This paper presents a design method for implementing a CAN bus adapter using the USB 1.1 protocol under Windows 2000. The entire design mainly involves developing the adapter's firmware and the computer's driver and application programs to achieve the goal of connecting to a field CAN bus network via a USB interface. 1 Adapter Hardware Interface Design The adapter hardware circuit consists of a microcontroller, a CAN bus interface, a USB bus interface, and a DC-DC isolated power supply module. The principle block diagram is shown in Figure 1. The microcontroller P89C51RD2 is an enhanced MCS-51 compatible microcontroller manufactured by Philips, integrating 64KB of flash memory and 1KB of extended RAM, dual data pointers, 4 interrupt priority levels, 7 interrupt sources, a built-in watchdog timer, and a programmable clock output. It operates in 6-clock mode, achieving twice the speed of a standard 51 microcontroller. In this mode, the external maximum frequency can reach 20MHz. This microcontroller is ideal for high-speed, large-scale, and small-to-medium-scale data processing applications. The CAN bus interface uses Philips' independent CAN bus controller SJA1000, with bus isolation provided by the optocoupler 6N136. The SJA1000 is an independent controller used for mobile target and area network control in general industrial environments, conforming to CAN 2.0A and 2.0B specifications, with a maximum speed of 1Mbps. The CAN bus transceiver uses the PCA82C250. The PDIUSBD12 is a full-speed USB interface device from Philips, fully compatible with the USB 1.1 specification. In Figure 1, the D+ pin signal level is internally pulled up by the device's SoftConnect command, thus indicating to the host that it is a full-speed device. The EOT pin automatically detects the VBUS voltage of the USB interface to determine whether the USB cable is connected to the host. SUSPEND is a bidirectional pin used to indicate to the microcontroller whether the device is suspended. When a USB bus event occurs, the pin sends an interrupt signal to the microcontroller. The PDIUSBD12 supports both multiplexed and non-multiplexed parallel interface modes to facilitate connection to different types of microcontrollers. Figure 1 uses a bus multiplexing method. Accessing the PDIUSBD12 with an odd-numbered address is considered a command, while accessing with an even-numbered address is considered data read/write. Each device requires an external clock signal, and they also have their own programmable clock output function, which facilitates the system's clock design. In the microcontroller's 6-clock operating mode in Figure 1, the external clock is a 12MHz crystal oscillator. The P1.1 pin of the P89C51RD2 generates a 6MHz square wave as the input clock for the PDIUSBD12; the CLKOUT output clock frequency is programmed to 24MHz through the PDIUSBD12's SetMode register, serving as the external input clock for the SJA1000. 2. Software Design The software design includes two parts: microcontroller firmware design and the computer-side USB driver. 2.1 Microcontroller Firmware Programming Firmware programming is an important concept in the terminal device programming of a USB data transmission system. The microcontroller exchanges data with the computer through the firmware program. The purpose of firmware design is to: enable the PDIUSBD12 to achieve the maximum transmission rate on USB; and increase the system's scalability and hardware independence. The firmware needs to implement the following: First, initialize the SJA1000, receive data from the CAN bus, collect CAN network status information, and send data from the host to the CAN network; second, initialize the PDIUSBD12, complete the USB bus connection process, and organize data transmission between the CAN network and the host. The design uses the Keil C51 software compilation environment and a mixed C51 and ASM programming approach. Both the SJA1000 and PDIUSBD12 have robust interrupt mechanisms, allowing the microcontroller to obtain bus events by reading their interrupt registers. To improve firmware efficiency, the main program enables interrupts after system initialization, analyzes and processes events in the interrupt service routine, and sets corresponding variable flags and data buffers. The main program then loops through the variable flags and calls the corresponding subroutines for processing. This program structure allows the main program to handle various data transmission tasks in the foreground while simultaneously processing bus events in the background via interrupts. 2.1.1 CAN Protocol Implementation The SJA1000 supports both BasicCAN and PeliCAN protocol modes. The adapter design uses the BasicCAN mode. The interrupt is set to level interrupt mode. The SJA1000 interrupt service routine flowchart is shown in Figure 2. 2.1.2 USB 1.1 Protocol Implementation The PDIUSBD12 supports all four USB data transfer modes. Control transfer, interrupt transfer, and bulk transfer are used in the adapter design. Control transfer is used only to transmit control information, using endpoint 0; interrupt transfer uses endpoint 1 to transmit CAN network status information; bulk transfer is used to implement data transfer between the host and CAN network nodes, using endpoint 2. 2.2 Driver Design The USB driver belongs to the WDM (Windows Driver Module) type. WDM drivers are layered, introducing two new classes, FDO (Function Device Object) and PDO (Physical Device Object), to describe hardware. Each physical hardware has one PDO, but can have multiple FDOs. The driver directly operates on PDOs and FDOs. The system identifies the driver through a globally unique identifier (GUID). When the application communicates with the WDM driver, the system packages each user request into an I/O request packet and sends it to the driver. The bottom of the system software block in Figure 3 shows the drivers provided by the Windows system, including the host controller driver (OPENHCI.SYS or UHCD.SYS), the HUB driver (USBHUB.SYS), and a class driver (USBD.SYS). The design tools for drivers under Windows 2000 are VC++ and the Win2000 DDK, but programming directly using the DDK is quite difficult. Currently, third-party software vendors provide driver development tools, such as Jungo's WinDriver and Compuware's DriverStudio. These tools are still based on the Windows DDK, but they have been repackaged and provide driver design wizards. DriverStudio was used as the driver development tool in the adapter design. By making selections and modifying a few parameters step by step using DriverWorks, a driver framework and a testbed application framework can be generated, providing excellent support for the common parts of USB devices. The program framework provides excellent support for the common parts of USB devices. Modifying the wizard-generated code in VC++ and adding processing code for the device's special functions, then compiling it into a *.SYS file using VC++, results in a complete driver. SoftIce is another debugging tool from DriverStudio, capable of operating system kernel-level tracing and debugging of drivers. After generating the driver, writing the corresponding INF file is a crucial step. The INF file, upon discovering new hardware, indicates to the system the driver to be installed, the services the system provides to the device, and the registry entries to be modified. The USB-based CAN bus adapter has been proven through testing to perform well in network communication tasks during small-to-medium scale and short-term large data block transmissions. The USB interface represents a development trend in computer peripherals, currently primarily used in low-to-medium speed applications. With the introduction of the USB 2.0 specification, it is gradually moving towards high-speed applications. Therefore, adapters connecting fieldbus networks and computer interfaces have broad application prospects.
Read next

CATDOLL Rosie Hybrid Silicone Head

The hybrid silicone head is crafted using a soft silicone base combined with a reinforced scalp section, allowing durab...

Articles 2026-02-22