| The Datasheet Archive - 100 Million Datasheets from 7500 Manufacturers. |
Technical Notes using Analog Devices' components development tools
Top Searches for this datasheetEE-89 Technical Notes using Analog Devices' components development tools Copyright 1999, Analog Devices, Inc. rights reserved. Analog Devices assumes responsibility customer product design application customers' products infringements patents rights others which result from Analog Devices assistance. trademarks logos property their respective holders. Information furnished Analog Devices Applications Development Tools Engineers believed accurate reliable, however responsibility assumed Analog Devices regarding technical accuracy content provided Analog Devices' Engineer-to-Engineer Notes. Implementing Software UART ADSP-2181 EZ-KIT-LITE EE-89 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com Table Contents Page Number INTRODUCTION BACKGROUND Serial Communication Asynchronous Serial Communication Universal Asynchronous Receiver/Transmitter HARDWARE SOFTWARE Data Format Program Flow Automatic Baud Rate Detection Routine Initialization Routine Processing Time Interrupt Service Routine Transmit Routine EXAMPLE PROGRAM Introduction Program Files Main Routine EE-89 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com INTRODUCTION This document describes software implementation Universal Asynchronous Receiver Transmitter (UART). UART implemented program running ADSP-2181 Lite. This document will also provide basic background serial asynchronous transmission. BACKGROUND Serial Communication Digital data transmitted along paths that physically consist wires, radio waves, microwaves. Such paths often referred data buses. digital data that carried such buses encoded digital format such BCD, ASCII, 8-bit words. When data transmitted serially, only data path required since data sent time. Cabling costs lower than other methods communication since serial communication requires minimum amount wires. Serial transmission methods characterized many bits second they transmit. This unit measurement call baud bit/s). Common baud rates serial systems 110, 300, 600, 1200, 2400, 4800, 9600 19200. Asynchronous Serial Communication Most serial interfacing done asynchronous manner. this method, transmitter sends character whenever available. there synchronization clock pulse between transmitter receiver control start character. This method relatively slow since requires handshake each character data transfer. serial asynchronous systems, however, handshaking performed using start stop bits beginning each character that transmitted shown Figure start logic stop logic high. parity sometime added after data bits receiver detect transmission error. number such start, stop, parity bits must agreed upon both transmitter receiver. EE-89 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com Start Data Bits Parity Stop idle state idle state Figure ASCII character with start bit, even parity stop Universal Asynchronous Receiver/Transmitter Universal Asynchronous Receiver/Transmitter (UART) dedicated single chip that controlled internal clock. This chip converts characters into series pulses series pulses back into characters. Using clock, UART transmitter controls duration pulses with delay between them sends character. receiver always monitors incoming line when start detected, UART will clock bits baud rate. When receiver collected data bits, converts them into character stops sampling. Digital Signal Processor (DSP) programmed perform same operation dedicated UART chip. This accomplished three methods. first method data receive line interrupt input processor that when start comes along, processor gets interrupted. This lets processor perform some other task interrupts occur whenever data comes along serial line. second method have transmit receive lines serial device connected FLAG FLAG pins DSP. Processor will have poll FLAG continuously using timer start present. This method processor. third method uses serial port instead timer FLAG sample output data. main advantage this technique that uses timer interrupt, keeping timer free other operations. Also, overhead will produced with timer interrupt service routine times bits services). example program UART driver this example polls FLAG continuously uses timer implement UART. this example, ADSP-2181 transmits receives serial data asynchronously connecting transmit receive lines serial device FLAG EE-89 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com FLAG pins. When there character sent DSP, software transmitter converts sequence zeros ones, sends them down line contiguously, (Least Significant Bit) first. When finishes sending character, line goes into idle (high) state until transmitter sends other character. When character available received, software receiver shifts bits constructs words sampling FLAG pin. HARDWARE serial cable used connect Lite board serial device. ADSP-2181 interfaced RS-232 line driver which turn connected RS-232 compatible device. line driver used convert volt logic level ADSP-2181 proper RS-232 line voltages, vice versa. Figure shows connection between ADSP-2181 line driver ADM232AAR. FLAG FLAG pins used independent receive transmit lines. ADM232AAR RS-232 Connector ADSP-2181 Figure Lite System Configuration EE-89 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com SOFTWARE Data Format UART program supports most common baud rates. However, autobaud feature only detect 2400, 3600, 9200 19200 baud. word transmitted received should have data bits parity bit. program adds start stop automatically when transmitting. Program Flow UART program consists following subroutines: Automatic baud rate detection routine (autobaud) Initialization routine processing timer interrupt service routine (uart_isr) Transmit routine (trans_bit) Automatic baud rate detection routine must called first after system reset. This subroutine will wait ASCII character downloaded from serial device. Then this subroutine configures Serial Port FLAG FLAG receiving transmitting. Once character received, routine figures current baud rate setting serial device pass initialization routine. Initialization routine must called after automatic baud rate detection routine. This routine reads detected baud rate constant from autobaud routine sets internal timer UART match baud rate. Then this subroutine configures Serial Port FLAG FLAG receiving transmitting. status flags UART reset here indicate that UART ready operation. After autobaud initialization routines called upon after system reset, processing timer interrupt service routine called. This happens every time timer expires issues interrupt. This routine will reset FLAG transmit time there character sent out. routine then checks there bits received from FLAG polling FLAG EE-89 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com continuously look start (logic low). start detected, routine will shift time signal whole character been received. Transmit routine used send character transmit request UART. This routine copies character transmitted transmit buffer with correct number stop start bits added. transmit routine then sets flag notify UART that character waiting transmitted. EE-89 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com Automatic Baud Rate Detection Routine software UART function properly, program must know baud rate setting serial device that trying communicate with. Instead setting baud manually, this autobaud feature UART will automatically detect match current serial device's baudrate. autobaud subroutine must called after system restart. user should transmit from serial terminal Lite board restart. character chosen because representation consecutive high bits with other bits low. Autobauding works follows: subroutine loads timer with maximum value (0xFFFF). subroutine waits start polling FLAG pin. When start detected, routine waits beginning three high bits `8''s ASCII representation arrive. timer counts down during receiving period high bits. number cycles taken receive those bits then compared number cycles known baud rate took receive bits. match found, autobaud sets timer constant operate UART same baud rate. number cycles needed process bits timer constant common baud rates found using following formula. following formula find number cycles needed processing bit: Number Cycles Needed process processor frequency baud rate BAUD Rate (bits/sec) 2400 4800 9600 EE-89 Cycles Needed Bits 41661 20826 10404 Cycles Needed 4629 2314 1156 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com 19200 5202 Table Timer constants number cycles common baud rates processor runs ADSP-2181 EZ-Kit Lite EE-89 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com Name: auto input: none output: none description: This function figures terminal's baud rate counting cycle time bits. This function waits char downloaded from terminal calculates time constant. This time constant compared known constant different baudrates. Once baudrate known, returns variable which then used UART clock transmit chars. note: Should called before initialize main program. ASCII char 00111000. first. #cycles/(1/3 bit) (freq/(3*Baudrate)) baudrate #cycles/3 bits #cycles/(1/3 bit) 2400 41668 4630 4800 20834 2315 9600 10417 1157 19200 5208 .module autobaud; .include <system.k>; .var baud_const; used uart.dsp .global baud_const; .entry auto; used main program auto: timer count from 0xFFFF timer; 0xffff; dm(TCOUNT) ax0; EE-89 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com dm(TPERIOD) ax0; dm(TSCALE) ax0; wait start wait_start: flag_in jump wait_start; looking high bits wait_high: flag_in jump got_high; jump wait_high; got_high: start counting down using timer timer; wait until high bits have been rxed wait_low: flag_in jump wait_low; wait stop counting down using timer timer; wait until char finished wait_stop: flag_in jump wait_stop; find many cycles needed dm(TCOUNT); 0xffff; ay0; compare #cycles known cycle diff baudrates 31251; 2400? ay0; jump baud2400; 15625; 4800? ay0; jump baud4800; EE-89 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com 7812; 9600? ay0; jump baud9600; buadrate found, setting timer constant baud19200: 579; dm(baud_const) ax0; jump baud_done; baud9600: 1157; dm(baud_const) ax0; jump baud_done; baud4800: 2315; dm(baud_const) ax0; jump baud_done; baud2400: 4630; dm(baud_const) ax0; baud_done: rts; .endmod; Listing Autobaud Program EE-89 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com Initialization Routine initialization routine called prepare UART transmit receive character. First, this routine gets timer constant sets timer issue interrupts times baud rate. This provides sufficient clock resolution handle asynchronous data stream. applications requiring greater resolution, interrupt rate changed higher multiples baud rate. initialization routine next configures Serial Port (SPORT1) FLAG FLAG pins. This routine then sets FLAG high indicate idle line. Finally, pending interrupts cleared, timer enabled, starts count down. Processing Timer Interrupt Service Routine interrupt service routine central routine UART program. This routine executed every time timer counter expires issues interrupt. Since timer running three times baud rate, will called three times every transmitted received. interrupt service routine divided into sections, transmit section receive section. routine begins switching secondary registers order preserve register content main program. Next, this routine checks transmit flag there transmit request. there character transmitted, transmit section executed; not, routine skips transmit section jumps directly receive section. Because timer runs three times baud rate, will sent once every three timer interrupts while transmit mode. transmit section must decide should sent during current interrupt. transmitted, routine shifts word transmit buffer out, first. This will determine whether FLAG high low. routine will then update necessary transmit flags then execute receive section. receive section first checks stop last word have been received. has, routine waits stop period pass returns main routine. stop been received, receiver either middle receiving word waiting receive word. EE-89 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com When receiver waiting word, samples FLAG check start bit. none found, routine returns main routine. start detected, routine sets receive counter more than normal count. This done UART sample near middle each data stream. When receiver middle receiving word, routine will sample FLAG shift once every three timer interrupts until there more bits left received. receiver will word ready flag update necessary flags indicate word been received. Transmit Routine This routine called main program transmit character using UART. copies word transmitted from register transmit buffer with stop start bits added. routine then sets transmit request flag notify UART that character waiting transmitted. UART busy, this routine will wait loop until UART transmitter becomes available. File: uart.dsp Contains: Initialize Trans_bit UART_ISR .module UART; .include <system.k>; .const CRYSTAL 16667; EZ-KIT LITE's crystal freq.} {-Defined main module-} .external num_tx_bits; .external num_rx_bits; {-Defined autobaud module-} .external baud_const; {-global functions-} .entry trans_char; .entry initialize; .entry uart_isr; EE-89 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com {-transmit variables-} .var uart_tx_buffer; bits from this buffer .var tx_bits_left; contains bits left .var main_tx_buffer; contains word txed .var tx_counter; uart when count=0 .var tx_flag; 1=transmit request, 0=no {-receive variables-} .var uart_rx_buffer; bits into this buffer .var main_rx_buffer; contains word .var rx_bits_left; contains bits left .var incomming; 1=uart middle .var rx_counter; uart clocks when .var rx_a_word; signals main prog word ready .var stop_bit; stop period reached .global main_rx_buffer; .global rx_a_word; Name: initialize input: none output: none description: This function sets timer generate interrupts three times baud rate. also configures Serial Port (SPORT1) FLAG FLAG pins. then sets flags that indicate UART ready Finally FLAG timer enabled. notes: This function should called beginning main routine. initialize: Initialize timer tick Baudrate dm(baud_const); autobaud dm(TCOUNT) ax0; dm(TPERIOD) ax0; EE-89 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com dm(TSCALE) ax0; Initialize UART status flags flag_out; high idle state dm(tx_flag) ax0; request dm(incomming) ax0; rxing word dm(rx_a_word) ax0; word ready dm(stop_bit) ax0; dm(tx_counter) ax0; load counter clear pending interrupts b#00000011111111; nop; take care latency Enable SPORT1 b#0000100000000000; System_Control_Reg; ay0; enable SPORT1 b#1111101111111111; ay0; SPORT1 FI/O Enable timer interrupt start timer count down imask; b#0000000001; ay0; imask enable timer timer; start timer count down rts; Name: uart_isr input: none output: none description: This called every time timer expires issues interrupt. This routine will xmit time using flag pin. there word EE-89 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com received, routine will shift bits reading flag pin. note: Since internal timer running baud rate, bits processed only once every timer interrupts. uart_isr: sec_reg; save content registers Something Transmit? dm(tx_flag); there request? none pass ax0; jump receive; goto receive, yes.} transmit: Decrement transmit counter dm(tx_counter); dm(tx_counter) Send char. during this interrupt? jump receive; goto receive, yes.} Shift buffer's into SR0. Test reset flag dm(uart_tx_buffer); lshift (hi); dm(uart_tx_buffer) sr1; pass sr0; reset flag_out; test sign SR0} flag_out; Reload transmit counter interrupts later transmit again dm(tx_counter) ax0; Decrement bits left transmit counter dm(tx_bits_left); EE-89 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com dm(tx_bits_left) jump receive; finished with current word? goto receive without clearing busy tmit request flag: tx_flag yes, finished with current word. setup status flags dm(tx_flag) ax0; receive: stop last word yet? dm(stop_bit); pass ax0; jump stop_rxed; busy, check start bit, none, exit dm(incomming); middle word? pass ax0; jump word_in; yes, goto routine flag_in jump done; then look start start found, clear buffer busy flag dm(uart_rx_buffer) ax0; dm(incomming) ax0; timer counter sample center adjust timeing dm(rx_counter) ax0; number bits word from main program dm(num_rx_bits); dm(rx_bits_left) ax0; rti; word_in: decrement timer counter, expired then take dm(rx_counter); EE-89 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com dm(rx_counter) jump done; exit expired timer expired, shift into buffer 0x0100; shifted from here dm(uart_rx_buffer); flag_in jump shift_zero; {flag high low?} ay0; high, shift shift_zero: low, shift zero lshift (lo); dm(uart_rx_buffer) sr0; Decrement bits left counter dm(rx_bits_left); dm(rx_bits_left) Reset timer counter dm(rx_counter) ax0; jump done; more bits current word? more, wait stop dm(stop_bit) ax0; stop_rxed: wait till stop passes dm(rx_counter); dm(rx_counter) jump done; stop period passed yet? more bits left current word, copy main buff dm(uart_rx_buffer); dm(main_rx_buffer) ax0; Reset status flags dm(incomming) ax0; dm(stop_bit) ax0; EE-89 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com signal main program there word ready dm(rx_a_word) ax0; done: rti; Name: trans_char Input: ASCII char transmitted output: none description: This function called main routine transmit char using UART. sets transmit flag notify UART that char waiting transmitted. then copies main transmit buffer UART tansmit buffer with stop start added trans_char: transmitter busy? Wait wait: dm(tx_flag); none pass ax0; jump wait; number bits will defined main routine dm(num_tx_bits); dm(tx_bits_left) ax0; copy char. internal transmit buffer dm(main_tx_buffer) ax1; ax0; init b#1111111000000000; adding stop dm(main_tx_buffer); lshift (lo); adding start dm(uart_tx_buffer) sr0; transmit flag dm(tx_flag) ax0; EE-89 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com rts; .endmod; Listing Software UART Program EE-89 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com EXAMPLE PROGRAM Introduction echo.dsp example program that uses software UART routine transmit receive. This example will show UART routine. program will read character from serial device echo back. this example will need ADSP-2181 Lite board connected comm. ports. Program Files following files needed create example program: uart.dsp autobaud.dsp echo.dsp uart.ach make.bat UART program subroutine. UART automatic baud detection subroutine. Main program that echoes characters back. UART system architecture file. batch file that assembles, links creates PROM file files listed above. make.bat batch file should used create executable PROM file example program. user should burn download PROM file Lite's EPROM after make.bat file successfully creates echo.exe echo.bnm files. Main Routine main echo routine uses software UART subroutine receive transmit character back serial device. main routine first uses autobaud routine automatically determine what current baud rate serial device Then main routine calls initialization routine match baud rate prepare software UART transmit receive characters. EE-89 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com When serial device's baud rate successfully detected autobaud routine, main routine will send string text terminal displaying detected baud rate. routine will then loop wait character available flag from UART. available, main routine will place character transmit register (AX1) call transmit routine send back out. Listings program files system files needed example program included this document. Information Lite board ADSP-2181 found ADSP-2100 Family EZ-Kit Lite Reference Manual. Name: echo Input: none Output: none Description: This program uses UART driver autobaud detection function echo back char receives. First, varifies functionality auto baud sending text string back terminal. After sending text string, program checks word ready from UART driver. trans_char function then used send char back terminal. calls: initialize auto trans_char .module echoing; .include <system.k>; .entry start; interrupt vector table .external initialize; .external trans_char; .external rx_a_word; EE-89 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com .external main_rx_buffer; .external auto; .external baud_const; .var num_tx_bits; .var num_rx_bits; .global num_tx_bits; .global num_rx_bits; {-sent terminal when autobaud successful-} .var text[20]; .var text1[20]; .var text2[20]; .var text3[20]; .init text: 'r','u','n','n','i','n','g',' ','a','t', ','1','9','2','0','0',0; .init text1: 'r','u','n','n','i','n','g',' ','a','t', ','9','6','0','0',0; .init text2: 'r','u','n','n','i','n','g',' ','a','t', ','4','8','0','0',0; .init text3: 'r','u','n','n','i','n','g',' ','a','t', ','2','4','0','0',0; start: imask b#0000000000; icntl b#00010; mstat b#1000000; b#0000000000000000; (System_Control_Reg) ax0; boot with blink toggle fl1; numbe data bits word dm(num_tx_bits) ax0; EE-89 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com bits including start stop bits data bits word dm(num_rx_bits) ax0; auto detect terminal baudrate call auto; user must this time initialize UART call initialize; display detected baud rate terminal dm(baud_const); 579; ay0; jump dis_19200; 1157; ay0; jump dis_9600; 2315; ay0; jump dis_4800; dis_2400: baud rate 2400 detected ^text3; jump text_done; dis_4800: baud rate 4800 detected ^text2; jump text_done; dis_9600: baud rate 9600 detected ^text1; jump text_done; dis_19200: baud rate 19200 detected ^text; EE-89 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com jump text_done; text_done: dm(i0, m0); pass ax1; jump line_feed; call trans_char; jump text_done; line_feed: call trans_char; call trans_char; again: wait until char received. dm(rx_a_word); pass ax0; jump again; received char., echo back dm(main_rx_buffer); clear word ready flag dm(rx_a_word) ax0; send char back call trans_char; wait until char received. jump again; .endmod; Listing Echo Example Program Name: Description: This interrupt vector table. will EE-89 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com placed 0x0000.0x002f, interrupt vectors area. .module/ram/abs=0 interrupt; .external start; .external uart_isr; jump start; rti; rti; rti; rti; rti; rti; rti; rti; rti; jump uart_isr; rti; .endmod; Listing Interrupt Vector Table rti; rti; rti; {00: reset rti; rti; rti; {04: IRQ2 rti; rti; rti; {08: IRQL1 rti; rti; rti; {0c: IRQL0 rti; rti; rti; {10: SPORT0 rti; rti; rti; {14: SPORT1 rti; rti; rti; {18: IRQE rti; rti; rti; {1c: BDMA rti; rti; rti; {20: SPORT1 IRQ1 rti; rti; rti; {24: SPORT1 IRQ0 rti; rti; rti; {28: timer rti; rti; rti; {2c: power down EE-89 Page Technical Notes using Analog Devices' components development tools Phone: (800) ANALOG-D, FAX: (781) 461-3010, FTP: ftp.analog.com, EMAIL: dsp.support@analog.com Other recent searchesSi4833ADY - Si4833ADY Si4833ADY Datasheet PK1801CA - PK1801CA PK1801CA Datasheet ISL54057 - ISL54057 ISL54057 Datasheet FMB150 - FMB150 FMB150 Datasheet 2SC4762 - 2SC4762 2SC4762 Datasheet
Privacy Policy | Disclaimer |