0 Introduction
Serial Peripheral Interface (SPI) is a high-speed synchronous serial input/output port. In recent years, it has been widely used in the expansion of external devices such as shift registers, D/A converters, A/D converters, serial E2PROMs, LED display drivers, etc. The SPI interface can be shared, which is convenient for forming a system with multiple SPI interface devices. Its transmission rate is programmable, the number of connection lines is small, and it has good scalability.
1 Introduction to SPI interface
SPI is a synchronous serial communication interface introduced by Motorola, which is used for serial connection between microprocessors, microcontrollers and peripheral expansion chips. It has now developed into an industrial standard. At present, various semiconductor companies have launched a large number of chips with SPI interfaces and various functions, such as RAM, E2PROM, FLASH ROM, A/D converter, D/A converter, LED & LCD display driver, I/O interface chip, real-time clock, UART transceiver, etc., providing users with extremely flexible and inexpensive options for peripheral expansion. Since the SPI bus interface only occupies four I/O lines of the microprocessor, the use of the SPI bus interface can simplify the circuit design. It saves a lot of interface devices and I/O lines in conventional circuits and improves the reliability of the design. At present, some manufacturers' single-chip microcomputers have SPI interfaces, such as Philips' P89LPC900, Atmel's Atmega128, etc., but most single-chip microcomputers do not support the SPI interface. In practical applications, designers often want to use a microcontroller without an SPI interface to control peripheral devices with an SPI interface for reasons of product size, cost, and scalability. Taking the AT89C2051 microcontroller simulating the SPI bus to operate the serial AD7390 as an example, as shown in Figure 1, this paper introduces the implementation method of using the microcontroller's I/O port to simulate the SPI bus through software.
The four lines used by SPI are the serial clock line (SCK), the master input slave output line (MISO), the master output slave input line (MOSI), and the low-level effective enable signal line (CS). In this way, only 3 to 4 data lines and control lines are needed to expand various I/O devices with SPI interface.
The SPI bus has the following characteristics:
(1) Because of fewer connections, the circuit design can be simplified. The parallel bus expansion method usually requires 8 data lines, 8 to 16 address lines, and 2 to 3 control lines. The SPI bus design only requires 4 data lines and control lines to complete the functions realized by parallel expansion.
(2) The devices are uniformly addressed and have nothing to do with the system address, and the SPI operation is independent.
(3) The device operation follows a unified specification, which makes the system software and hardware have good versatility. [page]
2 Basic Structure and Working Principle
of AD7390 AD7390 is a 12-bit resolution voltage output digital/analog converter produced by AD1. This DAC provides users with a low-cost, high-precision controllable voltage solution, powered by a single power supply +3V system. The device guarantees that the current consumption is less than 100mA when the power supply voltage is 2.7~5.5V, so the device is suitable for some devices with high power requirements, such as battery-powered systems. The output voltage depends on the external reference input voltage. DACOUT outputs any value between REFIN and ground. Its internal block diagram is shown in Figure 2.
The internal double-buffered serial data interface provides high-speed conversion, and the microcontroller controls the device through a three-wire SPI, serial data (SDI), clock (CLK), and enable (LD) pins. In addition, the output can be cleared using the CLR input. The operation timing is shown in Figure 3.
3 Serial port control of AD7390
The computer sends a control signal to the MCU via RS 232, and then the MCU controls the AD7390 to complete the entire setting process. The software flow of controlling the AD7390 via the serial port is shown in Figure 4. Once data is written to the microcontroller, the microcontroller will reset the AD7390.
The microcontroller program is divided into three modules, namely the SPI control module, the serial port receiving module and the operation information feedback module.
The SPI control module generates CLK and LD, and before the rising edge of CLK arrives, it ensures the stability of the SDI data so that the AD7390 can accurately collect data. The frequency of the CLK clock is determined by the typical delay of the device. Different devices have different delays, so it determines that the clocks of different devices should be different.
The serial port receiving module completes receiving data from the computer and saves the data. A MAX 232 completes the conversion between RS 232 level and TTL level. Because the data is transmitted continuously, when writing the receiving program, pay attention to the shielding of the interrupt application to accurately receive all the data.
When debugging with the serial port debugging assistant, pay attention to the format of the sent data. Whether it is sent in hexadecimal will affect the received data. For example, if the letter "E" is sent in hexadecimal. The actual data sent is "15", while the received data is the ASCII code of "15", "49", "53"; if it is not sent in hexadecimal, the ASCII code of the letter "E" is "69'. From this, we can see the difference between them. Therefore, if the receiver wants to get the desired data, it needs to be converted. The conversion can be seen in the following program. [page]
AD7390 is a 12-bit digital/analog converter. The device receives 16-bit data. The data format is shown in Figure 5. The lower 12 bits are taken as valid data and the upper 4 bits are automatically discarded. Because the microcontroller transmits data in bytes (8 bits), the 16-bit transmission mode is adopted.
Some program codes are as follows:
4 Conclusion
Through the application of serial ports, the control of SPI devices becomes very convenient. Since serial ports occupy less resources, the increasingly widespread application of SPI interfaces in integrated chips will make this control mode a typical design in future systems.
Previous article:51 MCU + CPLD makes the system more efficient
Next article:Implementation of a digital frequency meter based on single chip microcomputer
Recommended ReadingLatest update time:2024-11-16 19:38
- Popular Resources
- Popular amplifiers
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Digilent Vivado library
- Teach you to learn 51 single chip microcomputer-C language version (Second Edition) (Song Xuefeng)
- Raspberry Pi Development in Action (2nd Edition) ([UK] Simon Monk)
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
- Can you guys give me some suggestions, and diagrams?
- The running light delay is realized by the single-chip timer, and the running light style is changed by external interrupt
- Implementation of a Super-resolution Direction Finding Algorithm for Spatial Spectrum Estimation Based on High-speed DSP Series Processors
- IAR FOR MSP430 V7 simulation problem, please solve
- IR2104 drive circuit HO no waveform
- TI C6000 CodecEngine integrated algorithm core calling principle
- Double 11 development board recommendation: MSP430 LaunchPad
- MCU with LCD control
- Working principle of LM393 voltage comparator
- What is the difference between Linux and Android?