Design of serial communication between DSP and PC

Publisher:柔情细语Latest update time:2010-10-23 Keywords:DSP Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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:


·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


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.


4. Software Design of Host PC

The host PC uses high-level language C. When developing DSP applications in C language, one or more assembly language sentences need to be embedded, such as the configuration of INTM, SXM and other bits in the initialization phase of the program. The embedding of a single assembly language sentence can be achieved 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. Here we only discuss serial communication in the asynchronous mode. The data format of the PC serial port transmitter output and 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 respective working modes. In this paper, when the upper computer requests communication, it first sends a request communication command, the lower computer receives and judges it effectively, and sends a response code to the upper computer after confirmation. After receiving the response code, the upper computer sends the operation command. The two parties agreed on: baud rate 208h; 8-bit character, 1 stop bit, no parity; transmission method: PC uses query method to receive data, TMS320F240 uses interrupt method 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");

}

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:Interrupt Mechanism of TMS320C54x Series DSP
Next article:Fingerprint image contrast enhancement algorithm based on fuzzy logic

Recommended ReadingLatest update time:2024-11-16 16:35

DSP programming skills: must-read compilation instructions
  Pragma directives are probably the most complex of all preprocessor directives. They are used to set the state of the compiler or instruct the compiler to perform certain actions. The #pragma directive tells the compiler how to handle specific functions, objects, and code segments, and gives host (such as C28x) or o
[Embedded]
Underground Micro-Water Detection System Based on DSP
The micro-water test method is a method of instantaneously injecting or extracting a certain amount of water into a well, and obtaining the permeability coefficient of the aquifer near the well by observing the change of the well water level. For aquifers with high permeability, after instantaneously extracting or inje
[Test Measurement]
Underground Micro-Water Detection System Based on DSP
Innovative X-ray power system based on soft switching
1 Introduction AXI has become increasingly important in the field of nondestructive testing, especially for the inspection and evaluation of MEMS and MOEMS devices and packaging inspection such as CSPs and BGAs. Therefore, stable DC high-voltage power supplies used to generate X-rays have attracted great in
[Power Management]
Innovative X-ray power system based on soft switching
Design of 3G video helmet based on ARM11 and DSP collaborative video stream processing technology
  1. Introduction   In order to improve the controllability of on-site operations in high-risk workplaces, this paper adopts bionic principles and high-integration design to realize a 3G video helmet with the same viewing angle as the human eye. This design consists of a video helmet and a waist-span data processing
[Microcontroller]
Design of 3G video helmet based on ARM11 and DSP collaborative video stream processing technology
Ultra-low power non-touch gesture control is possible with the help of audio DSP platform
  Wolfson Microelectronics plc, a global leading supplier of mixed-signal semiconductor devices and audio solutions for consumer electronics, and Elliptic Labs, a leading supplier of ultrasonic touchless gesture recognition for consumer electronic devices, recently announced that the two parties have established a par
[Embedded]
Ultra-low power non-touch gesture control is possible with the help of audio DSP platform
Design and implementation of high-speed communication interface based on FPGA+DSP
Abstract: In the fields of radar signal processing and digital image processing, the real-time performance of signal processing is crucial. Due to the advantages of FPGA chips in the processing of underlying algorithms with large amounts of data and the advantages of DSP chips in the processing of complex algorithms,
[Analog Electronics]
Design and implementation of high-speed communication interface based on FPGA+DSP
Research on Synchronous Phase Measurement Device Based on DSP
With the widespread application of the global satellite positioning system (GPS), the real-time phasor measurement device PMU (Phase Measurement Unit) based on GPS has well solved the problem of wide-area spatial synchronous measurement of power systems, and formed a wide-area measurement system WAMS (Wide Area Measure
[Test Measurement]
Research on Synchronous Phase Measurement Device Based on DSP
A New Method to Improve DSP Sampling Accuracy Using AD7858
0 Introduction   The TMS320x series DSP produced by TI is designed for real-time signal processing. This series of DSP controllers integrates real-time processing capabilities and controller peripheral functions, providing an ideal solution for control system applications. When designing a new metal detector, the au
[Analog Electronics]
A New Method to Improve DSP Sampling Accuracy Using AD7858
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号