1. Introduction to SCI Serial Port
With the widespread application of single-chip microcomputer systems and the popularization of computer network technology, the communication function of single-chip microcomputers has become increasingly important. Single-chip microcomputer communication refers to the information exchange between single-chip microcomputers and computers or between single-chip microcomputers. There are two communication methods: parallel and serial. Since the interface resources of single-chip microcomputers are relatively precious, the use of parallel port communication will occupy more interface resources, so the exchange of information mostly adopts serial communication.
(1) Parallel communication mode
Parallel communication usually uses multiple data lines to transmit each bit of a data byte at the same time. Each bit of data requires a data line. For an 8-bit data bus communication system, 8 data lines will be required to transmit 8 bits of data (one byte) at a time. In addition, a signal line and several control signal lines are required. This method is only suitable for short-distance data transmission. For example, older printers are connected to computers via parallel ports, but now they use USB interfaces with very fast transmission speeds. Parallel port communication is simple to control and has a relatively fast transmission speed, but due to the large number of transmission lines, the cost is high for long-distance transmission and it is difficult for the sender and receiver to receive each bit at the same time.
(2) Serial communication method
Serial communication is to divide the data bytes into bits and transmit them one by one on a transmission line. In this case, only one data line is needed, and at least 8 bits are needed to complete the transmission. The necessary process of serial communication is: when sending, the parallel data must be converted into serial data and sent to the line, and when receiving, the serial signal must be converted back into parallel data so that it can be processed by computers and other devices. Serial communication has fewer transmission lines, low cost for long-distance transmission, and can use existing equipment such as telephone networks, but the data transmission control is more complicated than parallel communication.
There are two types of serial communication: asynchronous serial communication and synchronous serial communication.
(3) Asynchronous serial communication method
Asynchronous serial communication refers to the process in which the sending and receiving devices of the communication use their own clocks to control the sending and receiving of data. In order to coordinate the sending and receiving of both parties, the clocks of the sending and receiving devices are required to be as consistent as possible. Asynchronous communication is transmitted in units of characters (frames), and the gaps (time gaps) between characters are arbitrary, but each bit in each character is transmitted at a fixed time, that is, there is not necessarily an integer multiple relationship of "bit interval" between characters, but the distance between bits in the same character is an integer multiple of the "bit interval".
The SCI module of Freescale's microcontroller uses asynchronous serial communication. The so-called SCI is the name given by Freescale itself. It has the same function as the UART serial port of other microcontrollers.
A frame of character information in SCI serial communication consists of 4 parts: start bit, data bit, parity bit and stop bit, as shown in the figure below. SCI data format uses 8-bit data format and 9-bit data format.
Characteristics of asynchronous communication: It does not require strict consistency of the clocks of both the sender and the receiver, is easy to implement, and has low equipment overhead, but each character must be added with 2 to 3 bits for the start bit, check bit, and stop bit, so the transmission efficiency is not high. When communicating between single-chip microcomputers and between single-chip microcomputers and computers, asynchronous serial communication is usually used.
(4) Synchronous serial communication mode
In synchronous communication, the sender's clock directly controls the receiver's clock so that both parties are completely synchronized. At this time, the distance between the bits of the transmitted data is an integer multiple of the "bit interval", and there is no gap between the transmitted characters, that is, the bit synchronization relationship is maintained, and the character synchronization relationship is also maintained. We will introduce the synchronous serial communication method in detail in future experiments.
(5) Serial communication standard
Simplex. Simplex means that data can only be transmitted in one direction and cannot be transmitted in the reverse direction.
Half-duplex. Half-duplex means that data transmission can be in both directions, but it needs to be done in time.
Full-duplex. Full-duplex means that data can be transmitted in both directions at the same time.
Error checking for serial communications
①Parity check
When sending data, the 1 bit following the data bit is the parity bit (1 or 0). When odd parity is used, the sum of the number of 1s in the data and the number of parity bits 1 should be an odd number; when even parity is used, the sum of the number of 1s in the data and the number of parity bits 1 should be an even number. When receiving characters, the number of 1s is checked. If it is inconsistent, it means that an error has occurred during the data transmission process.
②Code and verification
The code and checksum is that the sender sums the data block (or XORs each byte) to generate a one-byte checksum character (checksum) and appends it to the end of the data block. When receiving data, the receiver sums the data block (except the check byte) (or XORs each byte) at the same time, and compares the result with the sender's "checksum". If they match, there is an error. Otherwise, it is considered that an error occurred during the transmission process.
③Cyclic redundancy check
This type of verification is to realize the cyclic verification between valid information and check bits through some mathematical operations, which is often used for the transmission of disk information, integrity verification of storage areas, etc. This verification method has strong error correction capability and is widely used in synchronous communication.
In order for the SCI serial port of the microcontroller to communicate with the serial port of the computer, the level conversion must also be performed. The level standard of the XEP100 microcontroller is TTL level, 5V represents logic "1", 0V represents logic "0"; the serial port level of the computer is RS-232 level, -12V represents logic "1", 12V represents logic "0". In order for the computer to receive data from the microcontroller, the TTL level must be converted to RS-232 level; in order for the microcontroller to receive data from the computer, the RS-232 level must be converted to TTL level. The chips that realize these two level conversions mainly include MAX232, MAX202, HIN232, etc. In this experiment, MAX232 is used to realize the interchange of the levels of the two serial ports. The circuit schematic is shown in the figure below.
The SCI module of Freescale microcontrollers allows full-duplex, asynchronous, serial communication between the microcontroller and remote devices (including other microcontrollers). The SCI consists of a baud rate generator, a transmitter, and a receiver. The transmitter and receiver operate independently, although they use the same baud rate generator. During normal operation, the microcontroller monitors the status of the SCI, writes data to be sent, and processes received data.
The functional block diagram of the SCI module of the XEP100 microcontroller is shown in the figure below
2. Routine Test
In this experiment, we use the SCI serial port of the microcontroller to communicate with the computer. You need to use a serial port to USB cable, which will simulate a serial port on the computer's USB port. In addition, you need a serial port assistant software sscom, the interface is shown in the figure below
Now that we have prepared what we need, let's take a look at the code. The main code related to SCI is the SCI initialization, sending, and receiving functions, as shown below.
/*************************************************************/
/* Initialize SCI */
/*************************************************************/
void INIT_SCI(void)
{
SCI0BD = BUS_CLOCK/16/BAUD; //Set the SCI0 baud rate to 9600
SCI0CR1 = 0x00; //Set SCI0 to normal mode, eight data bits, no parity check
SCI0CR2 = 0x2c; // Allow receiving and sending data, and allow receiving interrupt function
}
/*************************************************************/
/*Serial port sending function */
/*************************************************************/
void SCI_send(unsigned char data)
{
while(!SCI0SR1_TDRE); //Wait for the send data register (buffer) to be empty
SCI0DRL = data;
}
/*************************************************************/
/* Serial port receiving function */
/*************************************************************/
unsigned char SCI_receive(void)
{
while(!SCI0SR1_RDRF); //Wait for the send data register to be full
return(SCI0DRL);
}
In the initialization code, first set the baud rate of the SCI serial port to 9600 according to the bus clock, then set the SCI to normal mode, 8 data bits, no parity bit, and finally set the SCI0CR2 register to allow reception and transmission, and enable the receive interrupt. In the SCI send function, first determine whether the send buffer is empty. If it is empty, assign the data to be sent to the SCI data register. In the SCI receive function, wait for the receive flag to be set to 1. If it is set to 1, it means that the data has been read, and then return the data.
Previous article:Freescale 16-bit MCU (VIII) - PWM module test
Next article:Freescale 16-bit MCU (VI) - Phase-locked loop test
Recommended ReadingLatest update time:2024-11-23 15:10
- Popular Resources
- Popular amplifiers
- Practical Development of Automotive FlexRay Bus System (Written by Wu Baoxin, Guo Yonghong, Cao Yi, Zhao Dongyang, etc.)
- Automotive Electronics KEA Series Microcontrollers——Based on ARM Cortex-M0+ Core
- Automotive integrated circuits and their applications
- ADS2008 RF Circuit Design and Simulation Examples (Edited by Xu Xingfu)
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- Nantong Fujitsu: The scale of packaging and testing will reach 9 billion units next year
- hfss18 version 3D image setting problem
- [BearPi-HM Nano, play Hongmeng "touch and pay"] -7-"pseudo touch and pay" LED control
- Application of a variable parameter PID controller in the servo system of a casting robot
- The first post about motors: Sharing codes and experiences about speed in motor development
- Huawei is frantically poaching semiconductor talents, and many companies have filed collective complaints!
- Frequency Phone Lock Circuit
- Smartphone Antenna Inductor Selection
- [SC8905 EVM Evaluation] How to use I2Ctool on Nanxin Power Board
- Use of CSL library for DSP GPIO module