SPI communication design between MCU and DSP

Publisher:幸福满溢Latest update time:2012-04-13 Source: 单片机与嵌入式系统应用Keywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

introduction

In today's industrial control systems, in order to improve the real-time performance and applicability of the system, DSP is generally used to complete the core algorithm and control, while MCU is used to implement human-computer dialogue to achieve real-time control functions. In this way, DSP and MCU need an efficient data bus to complete the large amount of data transmission between them. The SPI bus is an ideal design solution because it occupies fewer interface lines, has high communication efficiency, and is supported by most processor chips.

In view of the actual use requirements of AC servo systems, TI's high-performance DSP controller TMS320LF2407A (referred to as "2407A") is used as the control core; MSP430F149 from the MSP430 series microcontroller produced by TI is selected as the control chip of the human-machine interface to realize the functions of button, data acquisition and display; SPI serial port communication is used to realize data transmission between the microcontroller and DSP.

1 System Hardware Composition

1.1 MSP430

The MSP430 series of microcontrollers are a new generation of microcontrollers developed by TI in recent years. The design of this microcontroller breaks the convention and adopts a brand-new concept. Its outstanding advantages are low power supply voltage, ultra-low power consumption, and multiple functions. Because its functions far exceed those of other series of microcontrollers, it is also called a "hybrid microcontroller". MSP430 has a very high degree of integration. It integrates multi-channel 12-bit A/D conversion, on-chip precision comparator, multiple timers with PWM function, on-chip USART, watchdog timer, on-chip digital control oscillator, a large number of I/O ports and large-capacity on-chip memory. At the same time, MSP430F149 is a Flash memory type microcontroller with good simulation development technology. It is equipped with a JTAG simulation interface and a high-level language compiler. Under the system support software, hardware debugging and software development of the target system can be realized online, including assembly language, C language, connection and dynamic debugging, single-step, multiple breakpoints and tracing, and all memories and registers are open, which can conveniently and reliably carry out software and hardware development of the system [12].

Based on the above characteristics, this series of microcontrollers are widely used in portable instruments, intelligent sensors, practical testing instruments, motor control, home automation and other fields.

1.2 TMS320LF2407A

2407A is designed by TI to meet the needs of industrial control applications, especially motor control. It integrates a high-performance DSP core and many peripherals into a single chip. The processing speed of 2407A is 40 MIPS, which can meet the needs of quickly processing large amounts of data and algorithms.

The 2407A has a rich set of peripheral modules: 3K words of Flash program memory, 1.5K words of data/program RAM, 544 words of dual-port RAM (DARAM) and 2K words of single-port RAM (SARAM), 2 event managers EVA and EVB, 16-channel input A/D converter, watchdog timer module (WDT), serial communication interface (SCI), 16-bit serial peripheral interface module (SPI), controller area network (CAN) 2.0B module, phase-locked loop-based clock generator, up to 40 general-purpose input/output pins that can be individually programmed or reused, and 5 external interrupts. It can be seen from this that the 2407A does have a strong real-time processing capability and is one of the ideal devices for high-performance servo drive control [3].

1.3 Hardware interface design and implementation of SPI communication

The hardware connection of SPI communication equipment only needs to connect the host's transmission with the slave's reception, connect the host's reception with the slave's transmission, and output the clock signal generated by the host to the slave's clock pin. The hardware connection between the microcontroller and the peripheral is shown in Figure 1.

Figure 1 Interface connection circuit between MSP430F149 and DSP

The single-chip microcomputer MSP430F149 is used as the host of serial communication, and the DSP 2407A is used as the slave. Among them, SPICLK is the SPI clock pin, SPISIMO is the SPI slave input/active output, SPISOMI is the slave output/active input, and SPISTE is the slave transmit enable.

As shown in Figure 1, SPI synchronizes the host and the slave through a clock lead. Therefore, its serial data exchange does not need to add start bits, stop bits and other format bits for synchronization. The data to be transmitted is directly written into the host's SPI transmit data register. This writing process automatically starts the host's transmission process, that is, the content of SPITXBUF is moved one bit at a time to the pin SPISIMO under the beat of the synchronous clock SPICLK; for the slave, the data appearing on the pin SPISIMO is also moved one bit at a time to the slave's shift register under the beat of SPICLK. After receiving a complete data block, the interrupt flag is set to notify the slave that the data block has been received, and at the same time, the content received by the shift register is copied to the slave's SPI receive data register SPIRXBUF. It can be seen that the user programming only needs to write data to the SPI transmit data register when sending data, and read the SPI receive data register when receiving data. The rest of the work is automatically completed by the SPI module [4]. [page]

2 Software Design

Both MSP430F149 and DSP allow users to program in C language and assembly language. In the system, DSP realizes real-time control of the motor and has strict requirements on the running speed, so the program is implemented in assembly language. MSP430 realizes functions such as key display, data management and instruction transmission, and has low requirements on the running speed, so it is implemented in C language.

The main tasks of software design are: initializing the corresponding registers; the microcontroller sends data on the corresponding interface; the DSP receives the data arriving at the serial port in a timely manner, identifies and saves the data.

2.1 Communication protocol settings

In order for two devices to communicate with each other, the protocol for transmitting data must first be specified. Generally speaking, the host sends commands and configuration information to the slave, and the slave sends feedback information to the host. The system mainly implements the MCU sending data information to the DSP. The MCU first sends command data to indicate the start of the process of the host sending data. If 0 is sent, it marks the beginning of the process. In order to avoid erroneous operation, the command data is sent twice. When the two data received by the DSP are both 0, the corresponding operation is performed, otherwise the command data is retransmitted. Then the data that the MCU needs to transmit is stored in an array and transmitted in sequence. For example, if 3 data are to be transmitted, arrays a[0] and a[1] are defined to store the command data, and a[2] to a[4] are defined to store the arrays to be transmitted.

2.2 Serial port initialization

The SPI initialization of the microcontroller includes: configuring the corresponding I/O port as an interface with SPI special functions, selecting the clock mode, selecting the baud rate, selecting the length of the data to be sent and received, and enabling the corresponding internal clock. All settings are implemented by designing the corresponding SPI control registers [5].

The initialization procedure is as follows:

WDTCTL=WDTPW+WDTHOLD; //Turn off the watchdog

BCSCTL1 = RSEL0 + RSEL1 + RSEL2; // XT2on

BCSCTL2 = SELM1 + SELS; //Select high-speed crystal oscillator as clock source

UCTL1 = CHAR + SYNC + MM + SWRST; //SPIZ master mode 8-bit data, MCU as active mode

UTCTL1=STC+SSEL1+CKPL; //Data is output on the falling edge, system master clock, three-wire mode

UBR01=0x02;

UBR11=0x00; //Baud rate is set to fclk/2

UMCTL1=0x00;

ME2=USPIE1; //Module enable 2

P5SEL|=0x0F; //The lower 4 bits are the module port function

P5OUT|=0xf0;

UCTL1&= ~SWRST; //Reset ends

The SPI initialization of 2407A is similar to that of the microcontroller, but the DSP is a slave device, so its baud rate is determined by the master device and no further design is required.

2.3 MSP430 sends data

The system has membrane buttons and LCD display, which can easily send data when needed. For example, after designing the parameters, a selection interface will appear, allowing the operator to choose whether to save the parameters, back up the parameters, or transfer the parameters to the DSP. The operator can choose the corresponding function according to his or her different needs. If the parameter transfer function is selected, the microcontroller will jump to the corresponding program segment to perform the parameter transfer task. The data sending program is as follows:

P5OUT &= 0x1f; //Chip select DSP chip

while((U1IFG & UTXIFG1) != UTXIFG1);

for(k=0;k<6;k++) {//Number of data transmitted

P5OUT &= 0x1f;

while((U1IFG & UTXIFG1) != UTXIFG1);

TXBUF1=a[k]; //Send data

while((UTCTL1&0x01)==0);//Sending completed

delay(10);

P5OUT &= 0x2f;

}

2.4 DSP receives data

DSP receives data sent by the microcontroller through interrupts, and an interrupt occurs every time a data is transmitted. After the main program completes the initialization of the DSP, it enters the waiting state. Once the interrupt signal of the microcontroller is received, the DSP enters the interrupt service subroutine and stores the received data in the storage unit starting at 70H. When all data transmissions are completed, these data are assigned to the corresponding variables. It should be noted here that the SPIRXBUF of the DSP is 16 bits, and the data sent by the microcontroller is 8 bits, so after the DSP receives the data, it needs to process it and mask the upper 8 bits. This can be achieved by ANDing with 00FF. The interrupt program flow is shown in Figure 2.

Figure 2 DSP interrupt program flow[page]

The interrupt procedure is as follows:

LDP #6

LACC K;K=K+1

ADD #1

SACL K

MAR *,AR2; AR2 is the storage unit address pointer

LDP #DP_PF1

LACC SPIRXBUF

AND #00FFH; high bit is blocked

SACL *+

LDP #6

LACC K

SUB #1; Determine whether it is instruction data

BCND L1,NEQ

LDP #0

LACC #70H

SUB #0

BCND L3, NEQ; if not 0, jump to L3

BL2; if it is 0, jump to L2

L1: ...; Determine whether it is the second data

L4: LACCK; determine whether the data transmission is completed

SUB #05H

BCND L5,EQ

BL2

L5: LDP #0; All data sent

LACC 72H

LDP #6

SACL SPEED; assign value to corresponding variable

……

L3: SPLK K,0;K=0

LDP #0

LAR AR2,#70H; address pointer points back to 70H

L2: CLRC INTM; open interrupt

RET

3 Conclusion

Experiments have shown that the use of SPI communication for serial communication between the MSP430 microcontroller and the DSP fully meets the real-time requirements of the servo system. At the same time, due to the relatively complete functions of the SPI interface, clear communication protocols, and simple timing, serial communication of data between the DSP and the host can be easily realized without the addition of other components, which simplifies the system design and enhances the system's real-time processing capabilities and application scope. The structure is highly flexible and easy to expand, while reducing the burden on the main CPU and improving the reliability of the system.

References

[1] Hu Dake. Principles and Applications of MSP430 Series Ultra-Low Power 16-bit Microcontrollers[M]. Beijing: Beijing University of Aeronautics and Astronautics Press, 2000.

[2] Texas Instruments.MSP430x1xx Family Users Guide (SLAU049B.pdf), 2002.

[3] Liu Heping, Yan Liping, Zhang Xuefeng, et al. TMS320LF240X DSP structure, principle and application [M]. Beijing: Beijing University of Aeronautics and Astronautics Press, 2002.

[4] Ren Zhibin, Che Changzheng. Application of Serial Peripheral Interface SPI[J]. Application of Electronic Technology, 2002, 29(10):2022.

[5] Wei Xiaolong. MSP430 series microcontroller interface technology and system design examples [M]. Beijing: Beijing University of Aeronautics and Astronautics Press, 2002.

Keywords:MCU Reference address:SPI communication design between MCU and DSP

Previous article:Design and implementation of shortwave RF frequency source based on DDS
Next article:Working principle of IC card smart water meter based on MSP430F41

Recommended ReadingLatest update time:2024-11-16 17:48

Sim900+ MCU development, making phone calls and sending text messages
1. Introduction        This module is a submodule of our "Elderly Care System Based on the Internet of Things". The function it implements is: when an abnormal temperature is detected, it calls or sends a text message to the designated guardian 2. Required Equipment         Sim900 development board, sim card, microcon
[Microcontroller]
C program for microcontroller to control 18-way servos
About this program: Q: Timer 1 controls 9 PWM channels. I have heard from experts that 8 channels are usually appropriate because it seems that one cycle of the servo is divided into 8 parts to control them separately. If it exceeds 8 channels, it seems that the cycle may change. A: Yes, each PWM channel has about 2
[Microcontroller]
PIC32 microcontroller application in gas chromatograph, software and hardware collaboration
1 Main content 1.1 Purpose and significance of the project Gas chromatograph is a precision instrument with a wide range of uses. It is widely used in petroleum, chemical industry, pesticide, public security, liquor, environmental testing, health and epidemic prevention, as well as colleges and universities, scien
[Microcontroller]
PIC32 microcontroller application in gas chromatograph, software and hardware collaboration
51 MCU instruction cycle
      There is a high-gain inverting amplifier inside the 8051 chip, which is used to form an oscillator. The input end of the inverting amplifier is XTAL1, and the output end is XTAL2. A quartz crystal and two capacitors are connected across XTAL1 and XTAL2 to form a stable self-excited oscillator. The capacitors C1
[Microcontroller]
51 MCU instruction cycle
Detailed explanation of the definitions, characteristics and relationships of microcontrollers, ARM, MCU, DSP, FPGA and embedded systems
First of all, "embedded" is a concept. There is no accurate definition. Different books have their own definitions. But the main idea is the same. Compared with general systems such as PCs, embedded systems are special systems with a streamlined structure. Only the necessary parts are retained in both hardware and sof
[Microcontroller]
STC15 MCU ADC thermistor temperature measurement source program
Pinno Electronics STC15W4K-Experiment 29-ADC Thermistor Measuring Temperature The microcontroller source program is as follows: /************************************************************************************ * * Experimental platform: Pivot Electronics STC15W4K core board + Pivot Electronics "Pioneer" expansi
[Microcontroller]
Design of brushless DC motor control system based on single chip microcomputer
1 Brushless DC motor control principle The brushless DC motor system consists of four parts: motor, rotor position sensor, electronic switch circuit and drive circuit. Its working principle diagram is shown in Figure 1. The DC power supply supplies power to the stator winding of the motor through the
[Microcontroller]
Design of brushless DC motor control system based on single chip microcomputer
Principles to be followed in designing single chip microcomputer hardware system
The hardware circuit design of a single-chip microcomputer application system includes two parts: one is system expansion, that is, when the functional units inside the single-chip microcomputer, such as ROM, RAM, I/O, timer/counter, interrupt system, etc., cannot meet the requirements of the application system, they
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components
Guess you like

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号