All 8051-based Dallas Semiconductor microcontrollers are capable of communicating with SCI-enabled devices, even though SCI functionality is not explicitly listed on the microcontrollers list of features. All our microcontrollers incorporate one to three 8051-type UARTs which can be configured to operate in most of the common SCI modes.
This application note describes how to configure the UARTs 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 concludes with a practical example of how to configure an 8051-based Dallas Semiconductor microcontroller UART to communicate with an SCI module. A code example is provided that demonstrates how to initialize the microcontroller and perform a simple test to ensure that the devices are communicating correctly.
|Feature||SCI||Dallas Semiconductor UART|
|Asynchronous mode||Available on most implementations||Serial mode 1, 2, 3|
|Synchronous mode||Available on some implementations||Serial mode 0 only|
|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|
|Idle character||Detects idle characters to wake device.||UART can not detect idle characters, but the UART microprocessor communication mode can be used to signal the UART to treat the next byte as an address/identifer.|
|Break character||SCI can transmit and receive break characters (00h).||Can transmit break character by taking serial port RX pin to logic 0. Receipt of break character may cause a framing error, depending on selected character length.|
Because the SCI has dictated 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 from a user-selectable timer overflow driven by the external clock source. This adds a considerable flexibility to the design and simplifies development because the baud rate is easily selected in software, permitting a number of baud rates from the same clock source. The equation for determining baud rate is shown below:
where osc_frequency is the frequency of the external clock source in MHz, TH1 is the 8-bit re-load value placed into the Timer 1 MSB SFR, and SMOD_0 (PCON.7) is the serial port 0 doubler enable bit. Alternatively, the following equation can be used to solve for the value of the 8-bit reload number TH1, if the baud rate and oscillator frequency are known:
Assuming an external clock source of 22.1184MHz, a TH1 value of FDh will produce a target baud rate of 19200 with the doubler bit cleared. More information about baud rate selection can be found in Serial I/O section of the appropriate User's Guide.
The following brief assembly code example shows how to initialize serial port 0 to communicate with an SCI module configured for 10-bit asynchronous mode at 19200 bps. When operating successfully it will echo back any received characters. This function can be easily removed, making it a generic shell for any user-desired SCI communication application.
;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 ; CLR TI0 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. CLR RI0 RETI
Although this example concentrated on the asynchronous mode of operation, Dallas Semiconductor microcontrollers can also be configured to interface with SCIs operating in the synchronous mode. The similarity of the SCI module to the 8051 UART allows this interface to be accomplished with minimal effort. Details about the synchronous mode (serial port mode 0) are found in the Serial I/O section of the appropriate User's Guide.