Connect 8051 based microcontroller to SCI port

Publisher:TranquilSilenceLatest update time:2024-01-03 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.


featureSCIDallas Semiconductor UART
asynchronous modeWorks with most implementationsSerial mode 1, 2, 3
synchronous modeAvailable on some implementationsSerial mode only 0
character length1 to 9 (if optional character length is supported)8 or 9
parityAvailable on some implementationsSupported by software in 9-bit mode
Framing errorYesYes
idle characterDetect 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 characterSCI 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:

pYYBAGPy2H6AL0hRAAAHefSnmaY446.gif?imgver=1

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:

poYBAGPy2H-AAcPCAAAHZmrR-Us741.gif?imgver=1

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.


Reference address:Connect 8051 based microcontroller to SCI port

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

8051 MCU serial port and serial communication
1. Basic knowledge of serial communication The CPU needs to exchange information with other external devices, and sometimes a computer also needs to exchange information with other computers. This information exchange is called communication. There are two types of communication: parallel communication and serial co
[Microcontroller]
8051 MCU serial port and serial communication
Study on STC12 delay function
This writing method is to nest assembly in C. The exact delay time = 2*t*T+5*T, T is one machine cycle. For 8051, If t=1, then the execution of this function should be 7us. If it is STC12, then the delay of this delay function should be: if t=1, the precise delay = 2*1*1/12+5*1/12=(7/12)us. I checked the STC12
[Microcontroller]
Study on STC12 delay function
Main performance features and application solutions of high-performance motion control chip IRMCF343
IR Company's IRMCF343 is an advanced RAM-based motor control, which has the advantages of compactness and high efficiency for advanced frequency conversion electrical motor control. IRMCF343 integrates two computing engines: one is a sensorless permanent magnet motor controlled motion control engine (MCETM), and the o
[Microcontroller]
C8051f series development keil c single step debugging
The C8051f series microcontroller is a high-speed, highly integrated microcontroller with powerful functions. When I used this microcontroller to read the three-axis accelerometer of ST, I found that the output was always all 1. So, I used the single-step debugging function of Keil C. After debugging step by step, I f
[Microcontroller]
C8051f series development keil c single step debugging
Design of program-controlled three-phase AC power source based on C8051F016 microcontroller and power amplifier
Preface Program-controlled three-phase AC power sources are widely used in many industries such as metallurgy, communications, chemical industry, electric power and military industry. It is used in industrial automation control fields such as AC voltage regulation, power regulation, dimming and motor soft start. It ca
[Microcontroller]
Design of program-controlled three-phase AC power source based on C8051F016 microcontroller and power amplifier
8051 MCU interrupt sending
I recently used c8051 for development. When the serial port program was moved into the project, the whole program stopped running. I added breakpoints and debugged, and found that there was a problem with the serial port query and sending. When the query was sent, the program died here, that is, while (TI0==0). This s
[Microcontroller]
8051 MCU Basics 6: General Pointers and Directional Pointers
Reference source: Keil Help uVision Help Cx51 Compiler User's Guide Language Extensions Pointers Questions about pointers in C51 code int *ptr; /* points to: an int variable in any space, stored in: RAM (data) area, occupies: 3 bytes*/ int xdata *ptr; /* points to the int variable in RAM (xdata), stored in RA
[Microcontroller]
8051 MCU Basics 6: General Pointers and Directional Pointers
Application of 8051 microcontroller in robotics and medical fields
  It has been more than 40 years since the birth of the 8051 microcontroller. Due to the expiration of the patent, domestic 8051 microcontrollers are generally much cheaper in price. With the development of science and technology, the use of microcontrollers has reduced the size, cost and complexity of electronic prod
[Microcontroller]
Application of 8051 microcontroller in robotics and medical fields
Latest Microcontroller Articles
Change More Related Popular Components

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号