Share this

Design of DSP communication interface based on CAN bus and RS-485

2026-04-06 02:44:57 · · #1
Abstract: This paper studies the DSP communication control principle and interface design method based on CAN bus and RS-485. It introduces serial communication between a PC as the master and a TMS320LF2407 as the slave, based on RS-485, and the communication interface design between the TMS320LF2407 and the CAN bus. Keywords: CAN bus; RS-485 communication; DSP application 1. Overview Fieldbus is an open, digital, multi-point communication control system local area network, and is one of the most promising technologies in the field of automation today. CAN bus is a hot application area in fieldbus. Due to its high communication speed, good openness, short message length, strong error correction capability, simple control, strong expandability, and low system cost, CAN bus is attracting increasing attention. TI's TMS320LF2407 DSP microcontroller, with its strong processing power, high integration of peripheral functional modules, and large memory capacity, is widely used in digital control and communication fields. The CAN bus controller connects to the TMS320LF2407 microcontroller to enable CAN bus communication. The TMS320LF2407 microcontroller's embedded asynchronous serial port (SCI) supports digital communication between the CPU and other asynchronous peripherals using standard formats. Through the RS-485 interface, asynchronous serial communication between DSPs or between a DSP and a PC can be easily achieved. RS-485 is a multi-transmitter interface standard that extends the performance of RS-422A, allowing one transmitter to drive 32 load devices over a twisted pair. Load devices can be passive transmitters, receivers, or transceivers. RS-485 has a maximum transmission distance of 1200m and a maximum transmission rate of 10Mb/s. Therefore, RS-485 is highly attractive in remote communication and multi-machine bus systems and is widely used in practical designs. This design uses a PC as the master and a TMS320LF2407 as the slave, implementing RS-485-based serial communication between the master and slave, as well as communication between the TMS320LF2407 and the CAN bus. The RS-485 communication between the PC and the TMS320LF2407 uses the MAX48X/49X series transceiver chip manufactured by MAXIM to complete the standard RS-485 interface communication. Since the PC provides a standard RS-232C serial interface, an RS-232C/RS-485 converter is needed for interface conversion, as shown in Figure 1. The TMS320LF2407's embedded CAN module and bus interface chip PCA82C250 are used to achieve serial communication between the TMS320LF2407 and the CAN bus. 2. RS-485 Communication Design of TMS320LF2407 The TMS320LF2407 has strong serial communication capabilities and involves many control registers, which makes the system design more flexible. During the design, the control registers are first initialized, including setting parameters such as data format, interrupt enable, interrupt priority, and baud rate. After initialization, data can be sent and received. To send data, simply write the data into SCITXBUF, and the serial communication SCI module will automatically complete the data transmission. To receive data, simply read the contents of SCITXBUF (the information shifted from the SCITXD/IO pin is automatically debited by the serial communication SCI module itself, removing the start bit, stop bit, and parity bit, and then placing the data into SCITXBUF). The code is as follows: Initialize the SCI module of TMS320LF2407 *SCICCR=0x0007; // 1 stop bit, disable parity, 8-bit character *SCICTL1=0x0023; // Enable receive and send *SCICTL2=0x0003; // Enable receive interrupt *SCIHBAUD=0x0001; *SCILBAUD=0x0089; // Set baud rate = 9600bps, at this time the system clock is 30M *SCIPRI=0x0010; // High priority TMS320LF2407 receive host computer interrupt response program Void interrupt int1() // SCI high priority interrupt, belongs to DSP INT1 interrupt { if (*PIVR==0x0006) // Check the interrupt vector to determine whether a serial port receive interrupt has occurred { … // Process the received data arm(“clrc INTM”); // Enable global interrupt return; // Return } else { arm(“clrc INTM”); // Enable global interrupt return; // Return } TMS320LF2407 data sending program to host computer Void send(char *p) // Pass the data to be sent using pointer method { while (*p!='\0') // Data transmission not completed { while ((*SCICTL2&0x80)==0x0000); // DSP send buffer is not empty, wait for *SCITXBUF=*P; // Send a character to host computer P++; } } 3. Host PC Serial Communication Software Design The host PC uses the communication control of the high-level language VB to realize serial communication. In VB5.0 and above, a communication control called MSComm is provided, which provides basic serial communication functions for the application and can send and receive data through the serial interface. The data format of the PC serial port transmitter output and receiver input is frame information format, which is the same as the SCI format of TMS320LF2407. During communication, both parties pre-agree on the communication data transmission format, transmission rate and their respective working modes. In this design, both parties agree that the baud rate is 9600bps. The format of one frame of information is one start bit, eight data bits and one stop bit. Transmission method: The PC uses polling to receive data, and the TMS320F240 uses interrupt to receive data. 4. CAN communication design of TMS320LF2407 The CAN module embedded in TMS320LF2407 is a 16-bit peripheral device. Its communication characteristics are: (1) Fully supports CAN2.0B protocol; (2) Has 6 mailboxes, of which mailbox2 and mailbox3 can be configured as receiving or sending mailboxes according to engineering requirements, and the data length is 0-8 bytes; (3) When the transmission fails or data is lost during arbitration, the controller has an automatic retransmission function; (4) Can realize self-test function through software programming. 4.1 Hardware design The TMS320LF2407 microcontroller is used to form a CAN bus network for real-time data reception and transmission. The CAN controller interface provides the interface between the CAN protocol controller and the physical bus. The bus interface chip used is the PHILIPS PCA82C250, which can easily connect the CAN controller to the CAN bus network. The hardware system is divided into two layers. The first layer is the interface circuit between the CAN bus and the TMS320LF2407, realizing the physical interface between the CAN bus and the TMS320LF2407. The second layer is the information processing layer between the TMS320LF2407 and the CAN bus, as shown in Figure 2. The PCA82C250 provides differential transmission and differential reception to the CAN controller. Since the PCA82C250 is powered by a 5V power supply and the TMS320LF2407 is powered by a 3.3V power supply, a resistor divider is used to achieve level conversion. R2 and R3 are 1KΩ and 2KΩ respectively, and R1 is 10KΩ. For diode D1, a Schottky diode IN5819 with fast recovery capability is selected. 4.2 Software Design 4.2.1 Initializing the CAN Module The initialization of the CAN module includes initializing the bit time and initializing the mailbox. The initialization bit timing can be performed as follows (as shown in Figure 3): (1) Set the change configuration request bit in the MCR register: CANMCR=1000H; (2) Configure the BCR register: CANBCR2=0000H; CANBCR1=0157H; (3) Request normal mode: CANMCR=0000H; The mailbox can be initialized by configuring the mailbox as follows (as shown in Figure 4): (1) Disable writing 0 to CANMDER in the mailbox: CANMDER=0000H; (2) Set the change data field request in CANMCR: CANMCR=0100H; (3) Change the mailbox content: data can be set only in the sending mailbox; (4) Return to normal mode: CANMCR=0000H; (5) Enable the mailbox: CANMDER=0004H; 4.2.2 Sending messages In order to realize the message sending of the CAN module, the sending process needs to be configured according to the following steps: (1) Initialize the sending mailbox and prevent it from writing 0 to CANMDER: CANMDER=0000H; Set the change data field request in CANMCR: CANMCR=0100H; Set the message ID for the sending mailbox: CANMSGIDnH=0E00H; CANMSGIDnL=000FH; Set the message control field, i.e., write to CANMSGCTRLn: CANMSGCTRLn=0008H; Create a message and write it to CANMBXnA, CANMBXnB, CANMBXnC and CANMBXnD: CANMBXnA=0ABCDH; CANMBXnB=0123H; CANMBXnC=0EF32H; CANMBXnD=6789H; Reset the 8th bit of CANMCR and request normal operation: CANMCR=0000H; Allow the mailbox to write to the CANMDER register: CANMDER=0004H; (2) Set the TRS bit of the TCR register to request to send a message: TCR=0010H; (3) Wait for confirmation of transmission (TA=1 in the TCR register); (4) Reset TA and the transmit flag: TCR=1000H; 4.2.3 Receiving messages When the CAN module receives external messages, the CAN controller needs to be configured as follows: (1) Set the local receive mask register. LAM1H=8000H; (2) Set the mailbox identifier and control. Prohibit the mailbox from writing 0 to MDER: CANMDER=0000H; Write to MCR register to request a change of data field: CANMCR=0100H; Set message ID for the sending mailbox: CANMSGIDnH=0E00H; CANMSGIDnL=000EH; Set message control field: CANMSGCTRLn=0008H; Reset MCR bit 8 and request normal operation: CANMCR=0000H; Allow the mailbox to write to the MDER register: CANMDER=0044H; (3) Wait for the mailbox interrupt flag of CANIFR to receive confirmation. (4) Reset RMP and receive flag, and must write 1 to RMP: CANRCR=0040H; Figure 3 Initialization bit time programming flowchart 5. Conclusion The innovation of the author of this paper is: In the field of industrial control, it is often a host to control multiple slaves, and the long-distance communication between the host computer and the slave computer is realized through serial communication. This design comprehensively implements the RS-485 long-distance communication interface between the PC host and the DSP slave, as well as the data transmission interface between the DSP slave and the CAN fieldbus. It simultaneously possesses long-distance communication capabilities between master and slave devices and real-time communication functions with CAN fieldbus devices, demonstrating broad application prospects. The design fully utilizes the DSP's CAN module and SCI module, simplifying the interface design and enhancing operational reliability. References [1] Xu Kejun et al. CPU and peripherals of TMS320LF/LC24 series DSP [M]. Beijing: Tsinghua University Press, 2004. [2] Wu Kuanming. CAN bus principle and application system design [M]. Beijing: Beijing University of Aeronautics and Astronautics Press, 1996. [3] Liu Heping. TMS320LF240X DSP structure principle and application [M]. Beijing: Beijing University of Aeronautics and Astronautics Press, 2002. [4] Rao Yuntao et al. Fieldbus CAN principle and application technology [M]. Beijing: Beijing University of Aeronautics and Astronautics Press, 2003. [5] Wang Mingyan. A communication method based on RS-485 interface [J]. Microcomputer Information, 2006, 2-1: 220-222. [6] Fan Ruixia. Two solutions to the problem of CAN bus transmission distance [J]. Microcomputer Information, 2006, 8-1: 161-162.
Read next

CATDOLL 139CM Vivian (TPE Body with Soft Silicone Head)

Height: 139cm Weight: 23kg Shoulder Width: 33cm Bust/Waist/Hip: 61/56/69cm Oral Depth: 3-5cm Vaginal Depth: 3-15cm Anal...

Articles 2026-02-22
CATDOLL 126CM Laura

CATDOLL 126CM Laura

Articles
2026-02-22
CATDOLL 136CM Tami

CATDOLL 136CM Tami

Articles
2026-02-22
CATDOLL 166CM Hanako TPE

CATDOLL 166CM Hanako TPE

Articles
2026-02-22