Abstract: DSPs are widely used due to their high performance and flexible programmability. This article presents a method for achieving effective and reliable communication between a DSP and a PC, using a PC as the master and the DSP as the slave. Furthermore, it details how to use VB6.0 Professional Edition as the development tool and the SCI (Serial Communication Interface) module in the DSP to implement data transfer between the DSP and the microcomputer through a data transfer program example.
Keywords: DSP; serial communication interface; PC; TMS320C24X
1 Introduction
The TMS320C24X is a low-cost, high-performance 16-bit fixed-point DSP developed by Texas Instruments (TI) specifically for motor control (DMC) applications. This device integrates a high-performance DSP core with rich microcontroller peripheral functionality, providing an ideal solution for control system applications. The TMS320C24X's Serial Communication Interface (SCI) supports digital communication between the CPU and other asynchronous peripherals using the standard NRZ (Non-Return-to-Zero) format. Asynchronous mode uses two lines to connect to many standard devices such as terminals and printers using the RS-232-C format. Therefore, by utilizing the SCI module in the DSP to transfer instructions and data with the microcomputer, the microcomputer can achieve monitoring and control of the production site.
VB6.0 is an interactive visual integrated development environment that runs on Windows. Its powerful communication control (Microsoft Comm Active X Control 6.0) can easily realize communication between PC and DSP.
2. DSP Section
The serial communication interface of this DSP controller consists of two main parts: transmitting and receiving. The pins related to serial communication are as follows:
SCIRXD: Serial communication receive pin, which can also be used as a general I/O port.
SCITXD: Serial communication transmitter, which can also be used as general I/O.
The system clock of the DSP is set by SYSCLK, where SYSCLK is 2/CPUCLK and CPUCLK is 20MHz.
Over 65,000 different programmable baud rates can be obtained through a 16-bit baud rate selector in the TMS320C24x. The baud rate setting is related to SCIHBAUD and SCILBSUD, and the specific formula is as follows: BRR = SYSCLK / (SCI asynchronous baud rate * 8) - 1, where SYSCLK is 10MHz. This software uses a baud rate of 9600. The programmable data word length is from 1 bit to 8 bits, and the data format can be programmed via the SCICCR control register. This software uses an 8-bit data word length. Communication between the PC and DSP uses interrupt mode, which avoids the DSP CPU repeatedly polling the receive and transmit buffer full flags, thereby improving device utilization and ensuring sufficient real-time performance. The corresponding interrupt settings can be configured using SCICTL2.
Both receiving and transmitting data via the serial communication interface use the NRZ (Non-Return to Zero) format. This software uses an 8-bit data frame (one unit for receiving and transmitting).
After the serial port is initialized, only the data transmit buffer SCITXBUF and the data receive buffer SCIRXBUF need to be operated. To send data, a transmit interrupt will be generated whenever data is written to SCITXBUF. The addition of start, stop, and check bits, as well as the shifting to the transmit pin SCITXD/IO at the specified baud rate, can be handled by the serial communication SCI module itself. To receive data, an interrupt will be generated as soon as the DSP receives a complete frame. Then, the contents of SCIRXBUF can be read in the interrupt routine. The serial communication SCI module automatically removes the start, stop, and check bits from the information shifted from the SCITXD/IO pin before placing the data into SCIRXBUF.
For standalone communication, SLEPP settings can be omitted, and the idle-line multiprocessor mode can be used, with initialization completed in the main program via interrupts. A variable can also be set to determine whether to send data to the PC.
Next, the signal received from the PC should be considered in the interrupt receiving subroutine (the PC needs to convert the motor parameters required by the DSP into fixed-point numbers such as 1.15, 4.12, 8.8, and 10.4). In the sending subroutine, the DSP should send the received data back to the PC, which will then convert the fixed-point numbers back into motor parameters and display them. Alternatively, the DSP can send data starting at a specified internal address to the PC, which will then convert and process it according to the given format. The DSP program flowchart is shown in Figure 1.
The following is a portion of the SCI initialization procedure:
. bss SEND,1 ; Flag for sending data to the microcomputer LDP #00E0h SPLK #0017h SCICCR ; SCI reset, data length 8 bits SPLK #0013h SCICTL1 ; Serial input/output enable SPLK #0003h SCICTL2 ; Serial input/output interrupt enable SPLK #0000h SCICBAUD SPLK #0082h SCICBAUD ; Baud rate 9600 SPLK #0022h SCICPC2 ; Define pins SCITXD and SCIRXD as function pins SPLK #0033h SCICTL1; Serial input/output operation
3. VB section
The powerful ActiveX control MSCOMM provided by VB6.0 Professional Edition enables communication between a microcomputer and a DSP. In VB, the data transmitted via the serial communication port uses a BYTE byte array variable. This array can be converted to a Variant type for transmission. Similarly, when receiving data, it must be assigned to a Variant type variable before processing. BYTE indicates an integer data type, ranging from 0 to 255. Variant is a variant variable and can be of any data type. A flag variable must also be set to determine whether the DSP needs to send data to the PC. (See figure)
Because the DSP used in this software is in fixed-point format with a word length of 16 bits, this system cannot directly represent floating-point numbers. Format conversion is required. Due to space limitations, the specific conversion module can be found in the Fun8.bas.VB section of the program. The program flowchart is shown in Figure 2, and the human-machine interface is shown in Figure 3. During operation, clicking the 'Send' button sends data to the DSP, and clicking the 'Verify' button receives data sent by the DSP.
4. Conclusion
The DSP's serial communication interface (SCI) and the powerful object-oriented development tool VB6.0 Professional Edition can be used to easily achieve single-machine or multi-machine serial communication between the DSP and a PC. The software described in this article has been successfully tested on a PC and a TMS320F240 evaluation board.