Design of serial communication between DSP and PC

Publisher:创意驿站Latest update time:2011-03-30 Keywords:DSP Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Abstract: Taking TMS320F240 series as an example, this paper briefly introduces the digital signal processor serial communication interface SCI module and RS485 serial port communication, and programs the serial communication interface circuit between TMS320F240 and PC.

1 Introduction

DSP is the abbreviation of both Digital Signal Processing and Digital Signal Processor. The former refers to the theory and method of digital signal processing, while the latter refers to the programmable microprocessor used for digital signal processing. The TMS320F240 series is a fixed-point DSP chip under the TMS320F2000TM platform. It is a 16-bit fixed-point DSP designed for digital motor control and other control application systems. It combines the high-speed computing function of DSP with the powerful control ability of motors, providing an ideal solution for control system applications. The TMS320F240 chip has a 16-bit synchronous serial peripheral interface (SPI), an SCI module for serial communication interface, dual 10-bit A/D converters, a watchdog timer module (WDT) with interrupts, and a phase-locked loop (PLL) clock generator. In addition, two event management modules EVA and EVB are integrated. Therefore, TMS320F240 not only has high-speed data processing capabilities, but also has control and event management capabilities, and can complete functions such as human-machine interface and serial communication with the host computer.

2 Serial communication interface (SCI) module

The SCI receiver and transmitter are double buffered, each with its own separate enable and interrupt flags. Both can work separately or simultaneously in full-duplex mode. To ensure data integrity, SCI performs discontinuity detection, parity check, timeout and frame error checks on the received data. Through a 16-bit baud rate selection register, the data transmission speed can be programmed to 65535 different modes. The SCI serial communication interface includes SCIRXD (serial communication data reception) and SCITXD (serial communication data transmission). When the SCI is not used, these two pins can also be used as general I/O ports. The transmission and reception operations can be completed by interrupt drive or query algorithm using the status flag. The main registers related to it are: transmit buffer register SCITXBUF, receive buffer register SCIRCBUF, receive emulation buffer register SCIRXEMU; communication control register SCICCR, interrupt enable and internal clock enable SCICTL1 and SCICTL2, baud rate selection high byte register SCIHBAUD, baud rate selection low byte register SCILBAUD, priority control register SCIPRI, pin control function SCIPC2 and SCIXST reflecting communication status, etc.

The serial communication interface module has two multiprocessor communication protocols: idle line multiprocessor mode and address multiprocessor mode. Idle line mode leaves a fixed space before the address. This mode has no additional address/data bits. It is more efficient than address bit mode in processing data blocks containing more than 10 bytes. Address bit mode adds an extra bit (address bit) in each byte to distinguish between address and data. This mode is more efficient when processing multiple small data blocks.

3 RS-485 serial communication

Although RS-232 is widely accepted, it has obvious disadvantages such as slow data transmission speed and easy interference between signals at the interface that have been exposed in modern network communications. RS-232 can only transmit 15 meters and cannot meet the requirements of long-distance transmission, while the maximum transmission distance of RS-485 is 1200 meters and the maximum transmission rate can reach 10Mb/s. Therefore, RS-485 is very attractive in remote communication and multi-machine bus systems. MAX48X/49X series transceiver chips are suitable for RS-422/RS 485 communication standards. Its main features are as follows:

Design of serial communication between DSP and PC

·Single +5V power supply;

Low power consumption: operating current 120~500μA:

Drive overload protection;

· 32 transceivers can be connected to the communication transmission line to form a half-duplex communication circuit;

Common mode input voltage range: -7V ~ +12V

MAX485 is an 8-pin package with the pin configuration shown in Figure 1 and the function description of each pin shown in Table 1.

Table 1

Design of serial communication between DSP and PC

This design uses PC as the host and TMS320F240 as the slave, and serial communication is carried out between the master and the slave. The interface circuit for half-duplex communication between TMS320F240 and PC using RS-485 standard is shown in Figure 2. Among them, the selection of receiver and driver is controlled by the XF/IOPC2 pin of TMS320F240. Since the standard RS 232 C serial interface is provided on the general PC, an RS 232C/RS485 converter is required for interface conversion.

Design of serial communication between DSP and PC

4. Software Design of Host PC

The host PC uses the high-level language C. When developing DSP applications with C language, one or several assembly languages ​​need to be embedded, such as the configuration of INTM, SXM and other bits in the initialization phase of the program. The embedding of single assembly language can be achieved by using the asm method.
Code Composer Studio, referred to as CCS, is an integrated development environment (IDE) launched by TI for developing TMS320 series DSP software. CCS works under the Windows operating system, similar to the integrated development environment of VC++, using a graphical interface, and providing editing tools and project management tools. There are two modes of serial communication in the CC environment: synchronous mode and asynchronous mode. Only the serial communication in the asynchronous mode is discussed here. The data format of the PC serial port transmitter output and the receiver input is the frame information format, which is the same as the SCI port format of TMS320F240. During communication, both parties must agree on the communication data transmission format, transmission rate and their respective working modes. In this paper, when the host computer requests communication, it first sends a request communication command, and the lower computer receives and judges it effectively, and sends a response code to the host computer after confirmation. After receiving the response code, the host computer will send the operation command. The two parties agreed: baud rate 208h; 8-bit character, 1 stop bit, no check; transmission mode: PC uses query mode to receive data, TMS320F240 uses interrupt mode to receive data.

5 DSP software design

5.1 Serial port initialization

First, set the register address, baud rate, data bit, stop bit, and parity bit.

void Set()

{

*SCICCR=0x7; //8-bit character, 1 stop bit, no parity

*SCICTL1=0X13; //Enable sending and receiving

*SCICTL2=0x03; //Enable receive and send interrupts

*SCIHBAUD=0x02; //Baud rate=208h, 40MHZ

*SCILBAUD=0x08; //208h=40*106/(9600*8)-1

*SCICTL1=0x33; //Enable sending and receiving, reset

*SCIPRI=0X60; //SCI interrupt (receive and send interrupt) is a low priority interrupt

}

5.2 Interrupt Initialization

a) Disable the general interrupt subroutine

void inline disable()

{

asm("setc INTM");

asm("setc SXM");

}

[page]

b) Enable the general interrupt subroutine

void inline enable()

{

asm("clrc INTM");

}

c) Interrupt Service Routine

void interrupt uarttr(){

switch (*PVIR){

//Based on the value of the interrupt vector register PVIR, distinguish whether it is a receive or send interrupt

case 6:UartRec();

//If PVIR=6, an accept interrupt occurs and the accept interrupt service routine is executed

}

}

d) When other interruptions are caused by interference, the interrupt enters this program and returns directly to the main program

void interrupt nothing(){

return; }

5.3 Interrupt Handling

void UartRec(){

unsigned int uwork;

int I, k;

k=0;

while(1) {

do{

uwork=(*SCIRXST);

}while((uwork&0x40= =0));

cReceive = (*SCIRXBUF);

cBuffer[k] = cReceive;

if(cReceive= ='.') {

cBuffer[k+1]='';

nlen=k+1;

Set();

Break;

}

k++; k%=16;

}

}
5.4 Program Initialization

#include "2407c.h"

// Initialize subroutine

Initial(){

*IFR=0xFFFF; //Clear interrupt flag

*WDCR=0Xe8; //Disable watchdog

*SCSR1=0x81FE; //CLKIN=6M, CLKOUT=24M

*MCRA=0x3; //use SCITXD, SCIRXD

*PADATDIR=0x100; //Set ADIR as output port

}

5.5 Main Program

Main(){

Set();

Disable(); //Disable all interrupts

Initial(); //System initialization

Enable(); //Enable general interrupt

While(1) {

unsigned int uwork;

For (intI=0;I<10;I++){

Do{

Uwork=(*SCICTL2);

}while (uwork&0x0c0!=0x0c0);

(*SCITXBUF)=cAnswer[i];

*IFR=0x0010;

Enable();

}

Do{

Uwork=(*SCICTL2);

}while (uwork&0x0c0!=0x0c0);

(*SCITXBUF)='"';

}

for (;;) {

:

}

}

6 Conclusion

The author's innovation: Using the DSP's serial communication interface (SCI) and the powerful development environment CCS, it is easy to realize single-machine or multi-machine serial communication between DSP and PC. The actual operation shows that using the SCI module of TMS320 to realize communication between DSPs or with PC is simpler in circuit, more flexible in setting, faster in operation, and more reliable and stable in performance than the traditional C51 single-chip microcomputer.

Keywords:DSP Reference address:Design of serial communication between DSP and PC

Previous article:Design of Multi-channel Video Monitoring System Based on Dual DSP
Next article:How to reduce power consumption when using FPGA for design

Recommended ReadingLatest update time:2024-11-16 22:23

DSP Programming Tips 2: Unveiling the Mystery of Compilers and Processor Options
  Maybe you have been using CCS for many years, but when a cl2000-related error occurs one day, you are suddenly confused; for example, if you use an old version of  CCS that does not support C2000 FPU to compile a 28335 program, cl2000 will prompt you that it is not supported and then report an error and will
[Embedded]
Suspension motion control design based on 32-bit DSP and motor driver chip
  With the popularity of 32-bit DSP, 32-bit processors have become the mainstream products in the control field. Compared with traditional microprocessors, they are faster, more powerful, and more resource-rich, and more in line with the pace of development. TMS320F28027 is a 32-bit DSP with the advantages of fast com
[Embedded]
Suspension motion control design based on 32-bit DSP and motor driver chip
Research on Ship Collision Avoidance System Based on AIS
The Automatic Identification System (AIS) was born in the 1990s. It is a new multidisciplinary high-tech navigation aid and safety information system that integrates communications, networks and information technologies. 1 Research on key technologies of AIS AIS cooperates with the Global Positioning S
[Embedded]
How to upgrade from single chip microcomputer to DSP
In the past few decades, the widespread application of single-chip microcomputers has realized simple intelligent control functions. With the progress of informatization and the rapid development of computer science and technology, signal processing theory and methods, the amount of data that needs to be processed i
[Embedded]
The key to extending battery life in DSP systems: DC/DC regulators
introduction A long-standing challenge for designers of MP3 players, personal media players, digital cameras, and other portable consumer applications is to achieve high performance and low power consumption. These battery-powered systems typically use an embedded digital signal processor (DSP) that reaches maximum pr
[Power Management]
The key to extending battery life in DSP systems: DC/DC regulators
DSP Hardware and Software Design in IEEE1394 Video Vision System
This paper introduces the software and hardware design scheme for realizing video stream control processing function by using digital signal processor. The paper focuses on how to design DSP software and peripheral hardware to complete the detailed process of IEEE1394 device self-identification and data transmission
[Embedded]
DSP Hardware and Software Design in IEEE1394 Video Vision System
Implementation of serial communication between TMS320C54XX series DSP and PC
  DSP has been increasingly widely used in the electronics industry. In the design of DSP application systems, the design of various communication interfaces is essential. Compared with parallel interfaces, the biggest feature of serial interfaces is that it reduces the number of device pins and reduces the complexity
[Embedded]
Using DSP to realize the subdivision of incremental photoelectric encoder
1 Introduction At present, grating devices are widely used as sensitive elements for speed and position measurement in various servo drives and their applications. In addition, two orthogonal square waves are widely used, and the real-time performance of the system is extremely high. Therefore, for the main processi
[Test Measurement]
Using DSP to realize the subdivision of incremental photoelectric encoder
Latest Embedded Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号