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.
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
- Popular Resources
- Popular amplifiers
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- How to self-test the fault of resistor parallel circuit?
- Auxiliary trainer for plank and push-up exercises
- MSP430 sets the main clock source, main clock source and auxiliary clock source
- What are the transmission distances of Zigbee and Bluetooth respectively? Which one has unlimited distance transmission?
- Impedance Matching and the Smith Chart: The Basics
- ATH10 temperature and humidity measurement is inaccurate
- Happy Little New Year! How many days off do you have for the New Year?
- [Pingtou Ge RVB2601 creative application development] 1. Understand Pingtou Ge chips and development platform
- Advantages of using pressure sensors in constant pressure water supply systems!
- How to Make DSP Digital Oscillator Generate Phase-Shifted Sine Wave