This application note describes how to configure the UART of a high-speed microcontroller or ultra-high-speed flash microcontroller to communicate with an SCI-enabled device. It begins with a brief discussion of the differences between SCI and UART modules and ends with a practical example of how to configure an 8051-based Dallas Semiconductor microcontroller UART to communicate with a SCI module.
introduce
The Serial Communications Interface (SCI) is a high-speed serial I/O port that allows synchronous or asynchronous communication between devices. It allows the microcontroller to be connected to a variety of similarly functional peripherals, as well as the standard RS-232 interface. The exact implementation of SCI varies by device manufacturer; many devices support features such as full-duplex communication in asynchronous mode, parity checking, error detection, and programmable character length in <> to <> bits.
All 8051-based Dallas Semiconductor microcontrollers are capable of communicating with SCI-capable devices, even if the SCI functionality is not explicitly listed in the microcontroller's feature list. All of our microcontrollers contain one to three 8051-type UARTs and can be configured to operate in most common SCI modes.
This application note describes how to configure the UART of a high-speed microcontroller or ultra-high-speed flash microcontroller to communicate with a SCI-enabled device. It begins with a brief discussion of the differences between SCI and UART modules and ends with a practical example of how to configure an 8051-based Dallas Semiconductor microcontroller UART to communicate with a SCI module. A code example is provided that demonstrates how to initialize the microcontroller and perform simple tests to ensure the device is communicating correctly.
Characteristics of SCI
As mentioned above, SCI is a high-speed serial interface. It has many similarities to the 8051-style UART on Dallas Semiconductor 8051-based microcontrollers. The following is a list of SCI functions in UART and their counterparts. Users should note that not all SCI modules support all features listed, so users should carefully read the data sheets of SCI-enabled devices to understand how to use them.
feature | SCI | Dallas Semiconductor UART |
asynchronous mode | Works with most implementations | Serial mode 1, 2, 3 |
synchronous mode | Available on some implementations | Serial mode only 0 |
character length | 1 to 9 (if optional character length is supported) | 8 or 9 |
parity | Available on some implementations | Supported by software in 9-bit mode |
Framing error | Yes | Yes |
idle character | Detect idle characters to wake up the device. | The UART cannot detect idle characters, but the UART microprocessor communication mode can be used to signal the UART to treat the next byte as an address/identifier. |
break character | SCI can send and receive interrupt characters (00h). | Interrupt characters can be transmitted by converting the serial port RX pin to logic 0. Receipt of a break character may cause framing errors, depending on the selected character length. |
example
Most SCI modules support asynchronous communication formats, many of which are exclusive. The example here demonstrates how to configure a Dallas Semiconductor 8051-based microcontroller to communicate asynchronously with an SCI-enabled device. In this case, we configure the microcontroller to communicate with the target SCI configured with the following characteristics:
10-bit asynchronous mode; 1 start, 8 data, 1 stop bit
Baud rate: 19200 bps
In order to communicate with this device we will make the following decisions to set up the Dallas Semiconductor microcontroller:
Use serial port 0 for communication
The external clock source is 22.1184MHz
The serial port will be configured in 10-bit asynchronous mode; 1 start, 8 data, 1 stop bit (this is serial port mode 1.
The baud rate generator clock source will be Timer 1 in auto-reload mode (Timer Mode 2).
Since all Dallas Semiconductor 8051-based microcontroller timers default to native divide-by-12 operating mode, this example has the advantage of being applicable to all Dallas Semiconductor devices regardless of the core's clock divisor. This is because the DS5000FP (divide by 12), the DS80C320 (divide by 4), and the DS89C450 (divide by 1) all use the same serial port timings if the timer's higher speed option is not selected. For details on UART operation, see the Serial I/O section of the appropriate user guide.
Since the SCI determines the format of the data, the Dallas Semiconductor microcontroller must next be initialized to the correct baud rate. The 8-bit auto-reload mode (Timer Mode 2) generates the baud rate via a user-selectable timer overflow driven by an external clock source. This adds considerable flexibility to the design and simplifies development since the baud rate can be easily selected in software, allowing multiple baud rates from the same clock source. The formula for determining the baud rate is as follows:
where osc_frequency is the frequency of the external clock source in MHz, TH1 is the 1-bit reload value placed in the Timer 8 MSB SFR, and SMOD_0 (PCON.7) is the serial port 0 multiplier enable bit. Alternatively, if the baud rate and oscillator frequency are known, the value of the 8-bit reload number TH1 can be solved for using the following formula:
Assuming the external clock source is 22.1184MHz, a TH1 value of FDh will produce a target baud rate of 19200 and clear the multiplier bit. For more information on baud rate selection, see the Serial I/O section of the appropriate user guide.
The following short assembly code example demonstrates how to initialize serial port 0 to communicate with an SCI module configured in 10-bit asynchronous mode at 19200 bps. On successful operation, it will echo any characters received. This functionality can be easily removed, making it a universal shell for any user requiring SCI communications applications.
;SCI emulation example
; Simple transmit test to demonstrate how to configure 8051 UART to
; emulate an SCI module. Test code embedded in this example echoes back
; received characters.
org 0h ;Reset vector.
ljmp start
org 23h ;Serial port 0 vector.
ljmp SP0_ISR
org 100h ;Start of code.
start: ;Initialize Serial Port 0 for mode 1, 19200 baud
MOV TMOD, #020h ;Set timer 1 for mode 2 (8-bit auto reload)
MOV SCON0, #050h ;SP0 10-bit asynchronous mode with receive enabled
;Now select the reload value based on baud rate and xtal frequency.
MOV TH1, #0FDh ;19200 baud at 22.11 MHz
;MOV TH1, #0FDh ;9600 baud at 11.059 MHz
;MOV TH1, #0FAh ;9600 baud at 22.11 MHz
SETB TR1 ;Serial port is initialized, now start timer
;Enable Interrupts
MOV IE, #90h ;This example supports interrupt-driven communications, so
; enable global and serial port 0 interrupts.
;Test code in receive interrupt routine echoes back any received characters
; when combined with the loop here.
loop: sjmp loop
SP0_ISR: ;Serial port 0 Interrupt Service Routine
jb RI0, RIO_INT ;Determine if receiver/transmitter was cause of interrupt.
TIO_INT: ;Interrupt was caused by transmission.
;
; Placeholder for transmitter routine
;
CLRTI0
RETI
RIO_INT: ;Interrupt was caused by reception
;
; Placeholder for receiver routine
;
MOV A, SBUF0 ;Test code that echoes back received character
MOV SBUF0, A ; Remove for real code.
CLRRI0
RETI
Summarize
The UART in Dallas Semiconductor's 8051-based microcontrollers can be easily configured to interface with SCI modules in many devices. This popular serial interface can operate in a variety of modes, but the most common is the 11/232-bit asynchronous mode used in RS-10 communications. Allowing Dallas Semiconductor microcontrollers to connect to SCI modules increases overall system flexibility as they can be connected to a wider range of embedded systems.
Although this example focuses on asynchronous mode of operation, the Dallas Semiconductor microcontroller can also be configured to interface with an SCI operating in synchronous mode. The SCI module's similarity to the 8051 UART allows this interface to be accomplished with minimal effort. For more information about synchronous mode (Serial Port Mode 0), see the Serial I/O section of the appropriate user guide.
Previous article:8051 microcontroller interrupt system structure and interrupt control principle
Next article:Design of temperature and humidity acquisition system based on 8051 microcontroller
Recommended ReadingLatest update time:2024-11-15 07:21
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- Principles and Applications of Single Chip Microcomputers 3rd Edition (Zhang Yigang)
- Principles and Applications of Single Chip Microcomputers and C51 Programming (3rd Edition) (Xie Weicheng, Yang Jiaguo)
- STC32G Series MCU Technical Reference Manual
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Why Python is the programming language of the future
- [SAMR21 new gameplay] 7. Use webusb
- Qorvo's BAW technology greatly improves the detection speed of new crown test kits
- Seeking long-term cooperation engineers to do part-time work: STM32 51 8S FPGA image processing
- Disassembled 5 surveillance cameras, 3 brands, to check the quality
- How does the Zigbee module connect to third-party gateways such as Philips Hue, Amazon alexa, etc. What is the standard protocol?
- 【Infineon XENSIV PAS CO2 sensor】Arduino routine test
- [RISC-V MCU CH32V103 Evaluation] +RTC Usage
- Loongson decided to abandon all American technology and make a truly pure domestic instruction set
- 【15th Anniversary】Want to meet up? Let's DIY an electronic tool box~You decide the functions