Home

Software UART for the Z8 Encore! XP® MCU

image

Contents

1. Set valid_data flag FALSE Crm Figure 11 Receiving Data Flow AN014705 0208 Page 11 of 12 Software UART for the Z8 Encore XP MCU ey cr TN Z iO CJ t U Xf WH aa AN Warning DO NOT USE IN LIFE SUPPORT LIFE SUPPORT POLICY ZILOG S PRODUCTS ARE NOT AUTHORIZED FOR USE AS CRITICAL COMPONENTS IN LIFE SUPPORT DEVICES OR SYSTEMS WITHOUT THE EXPRESS PRIOR WRITTEN APPROVAL OF THE PRESIDENT AND GENERAL COUNSEL OF ZILOG CORPORATION As used herein Life support devices or systems are devices which a are intended for surgical implant into the body or b support or sustain life and whose failure to perform when properly used in accordance with instructions for use provided in the labeling can be reasonably expected to result in a significant injury to the user A critical component is any component in a life support device or system whose failure to perform can be reasonably expected to cause the failure of the life support device or system or to affect its safety or effectiveness Document Disclaimer 2008 by Zilog Inc All rights reserved Information in this publication concerning the devices applications or technology described is intended to suggest possible uses and may be superseded ZILOG INC DOES NOT ASSUME LIABILITY FOR OR PROVIDE A REPRESENTATION OF ACCURACY OF THE INFORMATION DEVICES OR TECHNOLOGY DESCRIBED IN THIS DOCUMENT ZILOG ALSO DOES NOT ASSUME LIABILITY FOR INTELLECTUAL PRO
2. Z8 amp Encore xp Flash Microcontrollers Z8 Encore XP Flash Microcontrollers Zilog s Z8 Encore XP products are based on the new eZ8 CPU and introduce Flash memory to Zilog s extensive line of 8 bit microcontrollers Flash mem ory in circuit programming capability allows for faster development time and program changes in the field The high performance register to register based architecture of the eZ8 core maintains back ward compatibility with Z8 MCU Z8 Encore XP microcontrollers combine a 20 MHz core with Flash memory linear register SRAM and an extensive array of on chip peripherals These peripherals make the Z8 Encore XP suitable for a variety of applications including motor control secu rity systems home appliances personal electronic devices and sensors Discussion The UART protocol is based on the EIA RS 232C standard published in the year 1969 The standard was popular with the introduction of personal com puters and it is one of the most commonly used serial interfaces Originally defined as a 25 pin interface with several modem handshake and control signals the basic UART interface requires only three lines Receiver Rx Transmitter Tx and Ground GND The handshake is executed in software by transmitting special XON and XOFF characters In most of the MCU applications half duplex communication is sufficient that is each side is either a receiver or a transmitter at any given time
3. Copyright 2008 by Zilog Inc All rights reserved www zilog com In an asynchronous serial data communication data is transmitted sequentially one bit at a time The Ty idle state of the UART is High A High to Low tran sition of the Start bit initiates the transmission Eight data bits follow before the Stop bit pulls High again 1 c Data Field gt EL Stop Bit s Idle State of Line Isb msb 1 l 0 I Pat a f 2 l Figure 1 Basic 8 bit UART Protocol In an asynchronous operation the clock is not trans mitted The receiver must operate with the same baud rate as the transmitter and the data rate is usually derived from a local oscillator The receiver must also synchronize the baud rate to the falling edge of the Start bit and sample the incoming data in middle of a bit Developing a Software UART for the Z8 Encore XP MCU The Z8 Encore XP software UART supports the basic 8 N 1 format which is 8 data bits no parity and 1 stop bit It communicates in half duplex mode In Ry mode the program waits to receive a character then stores it in the Ry Data buffer In Ty mode the program sends the character that is stored in the Ty Data buffer Options Several options at assembly time can be selected to adapt the program to the appropriate operation ANO014705 0208 Software UART for the Z8 Encore XP MCU Zilog Table lcontains a list of these options Table 1 Options at Assemb
4. XP Development Board with a 9 pin serial cable to a standard PC running Windows NT 3 Launch the HyperTerminal application Go to File Properties and in the Properties dia log box under the Connect to tab select the COM2 port in the Connect using text field AN014705 0208 Software UART for the Z8 Encore XP MCU ITAN ZILOQ 4 Click the Configure button and in the Port Settings dialog box enter the following in the text fields Bits per second 9600 Data bits 8 Parity None Stop bits 1 Flow control None 5 Click OK button to get back to the Connect to tab Click the Settings tab and click the ASCH Setup button In the ASCII Setup dialog box check the Echo typed characters locally option Click OK button until the Properties dialog box closes 6 Download the test application program using zpsit 7 The default mode is Ry When a character is entered in HyperTerminal it is echoed back to the screen After a brief delay the same character is displayed again in the HyperTerminal window indicating that the character was received by the software UART s Rx Data buffer transferred to the Ty Data buffer and transmitted back to HyperTerminal to be displayed on the screen 8 The C coded software UART can be used to test for data overrun conditions when an over run error is generated To test overrun error generation disable the Set__Tx_Mode call by commenting the call in the Test_Uart
5. func tion before downloading the code once again 9 When a character is entered in HyperTerminal an OVERRUN ERROR message appears indi cating that a data overrun occurred 1 For the Assembly coded software UART no prompt appears in the HyperTerminal window upon downloading the code The HyperTerminal prompt Z8 Encore XP appears only when the C coded software UART is downloaded Page 6 of 12 Software UART for the Z8 Encore XP MCU Zilog 10 This procedure is repeated for all the baud rates indicated in Table 2 To change the baud rates the Constants definition BAUD is used see Table 1 on page 2 gt Note The ZDSII Debugger checks the value of the Ry Data buffer This value must be equivalent to the hex value of the entered character Results The following results are obtained 1 Inthe Table 2 testing with the baud rates and clock frequency settings are indicated 2 In Rx mode the software UART samples the data bit in the middle 50 of the bit cell for all baud rates mentioned in the Table 2 3 The received data is unaffected by jitter because the test program validates the Start bit before receiv ing any data Table 2 Baud Rates Tested for Ry and Tx Modes at 20 MHz Clock Frequency Baud Rates Tested Mode 300 600 1200 2400 4800 9600 19200 38400 57600 Rx P P P P P P P P Tx P P P P P P P P baud rate option is not available with the HyperTerminal Summary The software
6. 1 Rx Sampling Figure 3 Rx Sampling when Receiving Data If the middle of the first bit is a zero it indicates that the received bit is a valid Start bit and not a glitch The serial_in function performs the following tasks 1 To receive transmission the serial_in function ensures that the received bit is not a glitch sets the valid_data flag to TRUE and sets the receive bit counter Rx COUNT to 0 2 The data is sampled in the middle of the next bit 3 The data bit is stored in the appropriate bit position in the Ry Data register and Rx_COUNT is incremented When Rx_COUNT 8 then Rx COUNT is reset and the timer is disabled 4 The timer start value is reloaded The valid_data flag is set to FALSE and the Port A interrupts are enabled Figure 11 on page 11 displays the flowchart for the Data Reception Routine Transmitting Data To transmit data the start value of the timer register is set to zero and the timer reload value is set to gen erate interrupts at one bit intervals See Figure 4 on page 4 Page 3 of 12 StatO 1 2 3 4 5 6 7 Stop 0x51 0 Tx Sampling Figure 4 Ty Sampling when Transmitting Data The function serial_out performs the following tasks 1 To start transmission the transmit bit counter Tx_COUNT is set to 0 and the Tx line PAO is pulled Low to send the Start bit Tx_COUNT is incremented 2 The Tx_DATA register contains t
7. Application Note MCU AN014705 0208 Abstract This Application Note describes the implementation of a software emulated universal asynchronous receiver transmitter UART for Zilog s Z8 Encore XP 8 bit microcontrollers Software UART imple mentation is useful for applications in which an extra UART is required in addition to the hardware UART s available with Z8 Encore XP devices The hardware UARTs operate in full duplex mode where as the software UART implementation is half duplex The software UART is also an event driven and sup ports an 8 N 1 protocol using an RS 232 interface Data transfer is achievable at baud rates from 300 to 57600 The software features APIs for basic opera tions such as an initialization and data reception transmission Source code for the software UART implementation is provided in Assembly and C lan guages with an exception of Z8F642x support for which code is provided only in C gt Note The following source codes associ ated with this Application Note are available for download at www zilog com e ANO0147 SCO1 Assembly code for the 8 KB Z8 Encore XP MCU Z8F082x e ANO147 SCO2 C code for the 8 KB Z8 Encore XP MCU Z8F082x e ANO0147 SC03 Assembly code for the 64 KB Z8 Encore XP MCU Z8F640x e ANO147 SC04 C code for the 64 KB Z8 Encore XP MCU Z8F640x e ANO147 SCO5 C code for the 64 KB Z8 Encore XP MCU Z8F642x Software UART for the Z8 Encore XP
8. PBO ANAO H28 x lt o 01pF 2 pasiscL PB1 ANA1 H2 lt gt 3 PATISDA PB2 ANA2 28 cts Q RESET PB3 ANA3 22 5 XIN 3 vss PBA ANAA 24 x lt amp xin VREF 23 XOUT avss H2 nal sour vob Aavo Hi 1 x H pcsimiso DBG e MHz x 10 pcamosi pc1T10uT H2 x 14 pcasck PAS5 TXDO 18x 12 pc2iss PA4 RXDO 1Z R14 12 PAOTOIN PA3 CTSO 18 PA1 TOOUT PA2 DEO 15x 00K Z8F0822 e ie es apr TapF PA4_RXDO VOR oe PAS5_TXDO bt 0 1pF c3 u10 O1pFo 2 C 8 V 3 4 cs cr vz 5 O 1pF C2 c7 ce 6 c2 0 1pF 0 1pF __ CONSOLE 13 TIN tiout HZ 100 PI VEE way H Tn T20uT H x lt i E PA3_CTSO X15 R10UT Ruin H6 OTSO R3 10 9 RXDO 40K R2OUT R2IN t id EN nc H x Fa oi 20d SHDN nc Hi x DB9 Female MAX3222 U4A 7 J n 7ALvco4 SO Notes 1 Connect PA1 to PA4 and PAO to PAS only when testing with Z8F0822 MCU GND 2 To test the software UART on Z8F64 MCUs user defined port and pin connections may be used to connect to PA4 and PAS 3 When testing the Software UART application enter the crystal frequency according to the crystal available on user development board Figure 6 Schematic for Software UART Implementation Using the Z8 Encore XP MCU ANO014705 0208 Page 8 of 12 Software UART for the Z8 Encore XP MCU Zilog Appendix B Flowcharts Figure 7 displays the main software UART routine li Initialize Port A Bit 0 as outp
9. PERTY INFRINGEMENT RELATED IN ANY MANNER TO USE OF INFORMATION DEVICES OR TECHNOLOGY DESCRIBED HEREIN OR OTHERWISE The information contained within this document has been verified according to the general principles of electrical and mechanical engineering Z8 and Z8 Encore XP are registered trademark of Zilog Inc All other product or service names are the property of their respective owners AN014705 0208 Page 12 of 12
10. UART implemented in this Application Note supports the most common UART protocol 8 N 1 The Assembly and C language codes achieve data transfer at baud rates as high as 57600 at 20 MHz clock fre quency The size of the Assembly code is approximately 160 bytes which is ideal for small Z8 Encore XP modules such as the Z8F08xx Conversely the C language code is approximately KB in size and is suitable for larger Z8 Encore XP modules such as the Z8F64xx Although the software UART can operate only in the half duplex mode it is otherwise functionally comparable to the hardware UARTs on the Z8 Encore XP MCU and can provide an additional UART when required Reference The documents associated with Z8 Encore XP MCU available at www zilog com are provided below e eZ8 CPU User Manual UM0128 e Z8 Encore XP 64K Series Flash Microcontrollers Product PS0199 e Z8 Encore XP 8K 4K Series Development Kit User Manual UM0150 e Z8 Encore XP Flash Microcontroller Development Kit User Manual UM0146 ANO14705 0208 Page 7 of 12 Appendix A Schematics Figure 6 displays the software UART implementation using the Z8 Encore XP MCU Software UART for the Z8 Encore XP MCU Zilog VCC 3 3V pi R3 10K RESET s L 5 oO SWE C10 x H pcomiin
11. edure to test the software UART developed for the Z8 Encore XP MCU Equipment Used The following equipments are used for testing e Z8 Encore XP Development Kit Z8ENCOREO00ZCO0 D featuring the Z8F640x MCU e Z8 Encore XP Development Kit Z8F08200100 featuring the Z8F082x MCU e Z8 Encore XP Development Kit Z8F64200100KIT featuring the Z8F642x MCU e ZDSILIDE for the Z8F08xx Z8F640x and the Z8F642x MCUs e HyperTerminal application on the PC Page 5 of 12 gt Note The XTAL is 20 MHz and the default baud rate is 9600 for Ry Ty mode The software UART test setup for Z8 Encore XP software UART with the Z3ENCORE000ZCO0 Development Kit Z8F640x MCU is displayed in Figure 5 Z8ENCORE000ZCO Z8F6403 Development Kit 1 Z8 Encore XP PA0H Tx PA5 PC with RS 232 C Port Pywnm XPZ PA4 gt PAZ Canoe P1 3 1 Rx lt Figure 5 Test Setup for the Z8 Encore XP MCU Software UART Appendix A Schematics on page 8 displays the test setup schematic for the Z8 Encore XP software UART with the Z8F08200100 Development Kit Z8F082x MCU Procedure Follow the steps below to test the software UART application 1 Connect the PAO pin to the PA5 pin Connect the PA1 pin to the PA4 pin The available serial driver MAX 232A on the Z8 Encore XP Development Board is displayed in Figure 5 2 Connect the Z8 Encore
12. equire This is achieved by modifying the code in the sio h file provided in the source code zip file It can be modified the Ty pin port Rx pin port and the baud rate for software UART by changing the definitions provided in the sio h file as detailed below e To modify the crystal frequency and baud rate the following settings are modified Set the crystal frequency and BAUD rate defin XTAL 20000000ul Crystal frequency defin BAUD 9600ul Baud rate 300 600 1200 2400 4800 9600 19200 38400 57600 e The following settings are modified to alter the Rx pin and port gt Note Use only those ports and pins on which interrupts can be set as the Ry data line Page 4 of 12 Select the port pin for Ry bit define SW _UART_RX_PORTPAADDR select port define SW _UART_RX_PORT_CTLPACTL select port control define SW_UART_RX_PORT_INPAIN select port data input vegister define SW _UART_RX_PORT_OUTPAOUT select port data output register define SW_UART_RX_PIN_POS1 set pin position no 0 7 for Ry bit define SW_UART_RX_DATA_BITBIT1 set bit Bit 0 7 for Ry data e To set the interrupt functionality for the Ry bit the following configuration settings are modi fied Set interrupt functionality for Ry bit define SW_UART_RX_PORT_INTP1AD set vector for ISR only for Port A D 4 low
13. er 4 bit only for port C define SW _UART_RX_CLR_INTIROQ1 clear interrupt IRQ1 for port A D and IRQ2 for Port C define SW_UART_RX_SET_INTIRQI1ENH set priority interrupt IRQIENH for port A D and IRQ2ZENH for Port C define SW _UART_RX_PORT_ENBIT1 Here Port pin is used to enable the port interrupt define SW_UART_RX_PORT_DIS BIT1 Here Port pin is used to disable the port interrupt define SW_UART_RX_PORT_SLCIRQPS define SW_UART_RX_PORT_ADOx00 select 0x00 for port A and OxFF for port D to generate the interrupt ANO014705 0208 Software UART for the Z8 Encore XP MCU Zilog e The following settings are modified to alter the Tx pin port position Select the port pin for Ty bit define SW_UART_TX_PORTPAADDR select port RT_TX_PORT_CTLPACTL select port control RT_TX_PORT_INPAIN select port data input register RT_TX_PORT_OUTPAOUT select port data output register RT_TX_PIN_POSO set pin position no 0 7 for Ty bit define SW_UART_TX_DATA_BIT BITO set bit Bit 0 7 Ty data gt Note The Ty bit and the Ry bit must not be set for the same pin define SW_U Od tdefine SW_U ct define SW_U O Gk ft define SW_U NN a a a PN BP for Testing the Software UART Application This section describes the equipment and proc
14. he valid data to be transmitted It is read loaded into an intermediate buffer and shifted out to Port AO one bit at a time from bit 0 to bit 7 Tx_COUNT is incremented after each bit is transmitted see Figure 4 3 To stop transmission the Ty line PAO is pulled High to signal the end of transmission the timer is disabled Figure 10 on page 10 displays the flowchart for the data transmission routine Features Specific to C implementation of Software UART Two additional features are provided with the soft ware UART implemented in C language They are described below Flow Control Two functions APIs are provided to control the flow of data while receiving and transmitting data These APIs are l Z Start_Commu 2 Z_Stop_Commu ANO014705 0208 Software UART for the Z8 Encore XP MCU line ZILOQ Calling the Z2_Start_Commu API resumes communication Calling Z_Stop_Commu stops the communication between the communicating devices Overrun Error A data overrun error occurs when the Ry Data buffer receives data before previously received data is read and emptied An Over_Run flag is set when an overrun occurs and it is reset when the data in the Rx Data buffer is read and emptied Setting the Port and Pin for Software UART Ty Rx The software UART implementation by default uses Port A Pin 0 and Pin 1 as the Ty and Ry data pins respectively However the pins and the port can be changed as r
15. ly Time Variable Name Description BAUD Baud rate 300 to 57600 When BAUD is specified the program selects all the appropriate tim ings Default is 9600 RAM_TOP Top of RAM default is EFF ROM_TOP Top of Flash default is FFFF MODE Rx or Tx Hardware Architecture The Figure 2 displays the hardware setup of Z8 Encore XP MCU connected by a MAX 232A line driver to a PC running a HyperTerminal program with a setting of no handshake Only Ry and Tx lines are used ZBENCORE000ZCO Z8F6403 Development Kit i Z8 Encore XP Tx oe a M p42 Tx Port AQ A i gt 2 PC with 2 A RS 232 C Port P1 3 1 1 Rx Port AT lt Figure 2 Block Diagram of Z8 Encore XP Connected to PC Both the communicating UARTs in this case the PC and the Z8 Encore XP MCU must be programmed with the same baud rate one as transmitter and one as receiver the Ry and Ty lines are crossed Pin PAO is used for Ty and pin PA is used for Ry Page 2 of 12 Software Implementation The software UART implementation comprises of three basic operations initialization receiving data and transmitting data The implementation of these operations is common for the software UART which is coded in Assembly and C languages Initialization In this implementation PAO is the Ty pin and PAI is the Ry pin The following operations are performed sequentially during i
16. nitialization 1 Pin PAO is set to OUTPUT mode and a High is output at PAO 2 PALI is set to INPUT mode and initialized to generate interrupts at the falling edge of the signal 3 The timer which is used as a counter and is set in the CONTINUOUS mode of operation to generate interrupts upon reaching a set counter value To sample the received data at the center of the bit the start value of the timer register is set to half the value of the reload register 4 The timer is enabled during the Tg mode and disabled otherwise Port A interrupts are enabled during Ry mode and disabled other wise Figure 7 on page 9 displays the flowchart of the Main Software UART Routine Receiving Data To receive data the Start bit must be detected The Start bit is detected by the falling edge of the signal at pin PAI when a port interrupt is generated This interrupt is handled by the Port ISR see Figure 8 on page 9 wherein the timer is enabled and the port interrupts are disabled to receive the remainder of the data bits The timer reload value is set to generate interrupts at one bit intervals The start value of the Ry Sampling when Receiving Data timer register is set to half the reload value to ensure that the first interrupt generated after enabling the timer is at the middle of the Start bit See Figure 3 ANO014705 0208 Software UART for the Z8 Encore XP MCU 4 StatO 12 3 4 5 6 7 Stop 0 PL 0x5
17. ut for Tx Initialize Port A Bit 1 as input for Rx Set Port A to generate interrupt at Low edge Set Mode of operation as Rx Tx Initialze timerO for continuous mode timer start value half reload value lt v Wait in a do nothing loop Figure 7 Main Software UART Routine Figure 8 displays the port interrupt service routines Start v Enable Timer Disable Port Interrupt IRET Figure 8 Port ISR Flow ANO014705 0208 Page 9 of 12 Software UART for the Z8 Encore XP MCU Figure 9 displays the timer interrupt service routines Y Yy Call serial_in Call serial_out function function IRET Figure 9 Timer ISR Flow Figure 10 displays the flow of the transmitting data Serial Data Out Test bit counter 00 l Send Start bit Test bit counter 08 Send Data bit Yes Return Send Stop bit Figure 10 Transmitting Data Flow ANO014705 0208 Zilog Page 10 of 12 Software UART for the Z8 Encore XP MCU Zilog Figure 11 displays the flow of the receiving data Serial Data In Yes No valid_data lag TRUE Read data bit Increment Rx counter Is the bit a glitch Yes Set valid_data flag TRUE Disable timer Set Rx counter 0 Reload timer start value Clear Rx buffer Enable port interrupt

Download Pdf Manuals

image

Related Search

Related Contents

20954-6NL-10 PNOZ X2.7P / PNOZ X2.8P  navigazione bilance di precisione    Philips CID2680 User Guide Manual - CaRadio  FEMA ELECTRÓNICA  LED BAR 163 FC Manuel d`utilisation  112736  WaterFall 250 User Manual  

Copyright © All rights reserved.
Failed to retrieve file