| The Datasheet Archive - 100 Million Datasheets from 7500 Manufacturers. |
AN1818 Freescale Semiconductor, Inc. Software Routines with
Top Searches for this datasheetOrder this document AN1818/D AN1818 Freescale Semiconductor, Inc. Software Routines with 16-Bit Timer Module Brad Bierschenk Applications Engineering Austin, Texas Introduction Many applications that communicate off-board devices require asynchronous serial link. Motorola microcontroller unit (MCU) with serial communications interface (SCI) module provide this communications functionality. However, many applications, that does have module must used. asynchronous communications capability needed, must provided through software control existing modules. "bit-banged" approach, documented HC05 Software-Driven Asynchronous Serial Communication Techniques Using MC68HC705J1A, Motorola document order number AN1240, convenient, requires dedicated software overhead while transmitting receiving data. Through 16-bit free-running counter, HC05 other families provide interrupt-driven software with minimal software overhead. Motorola, Inc., 1999 AN1818 More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note General Information solution discussed here works half-duplex mode. This means transmit receive serial data, cannot simultaneously transmit receive. This enough most applications much easier implement than full-duplex solution. timing Figure shows standard non-return-to-zero (NRZ) asynchronous transmission protocol RS-232 serial transfer. Freescale Semiconductor, Inc. BYTE TX/RX IDLE LINE START STOP Figure Serial RS-232 Timing complete byte transfer takes times, start stop bits. first falling edge indicates beginning start bit, thus beginning byte transmission. After start bit, data sent eight bits. logic high stop signals byte transmission. 16-bit free-running timer counter with input capture (IC), output compare (OC), associated interrupts, allows software emulation module with only small amount processor overhead. addition timer module, digital input that sampled using BRSET BRCLR instructions needed. some MCUs, including 68HC705P6A, input capture read directly digital input. other MCUs, input capture also should connected digital input allow digital polling. AN1818 More Information This Product, www.freescale.com MOTOROLA Application Note Receiving Serial Data byte variable used simulate flags status control register. Likewise, variable function data register where transmitted received bytes stored. RDRF TDRE Figure Simulated Status Register Variable Receive In-Progress Flag here signifies that receive progress. Transmit In-Progress Flag here indicates transmit progress. RDRF Receive Data Register Full here indicates that byte been received. TDRE Transmit Data Register Empty here indicates that byte been transmitted. Freescale Semiconductor, Inc. Figure Simulated Data Register Variable Receiving Serial Data this application, data being transmitted, input capture (IC) function timer enabled. this way, user wait start incoming transmission without software overhead. When start received, interrupt triggered. This provides both wakeup start receiving start timing reference value registers. AN1818 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note FIRST OUTPUT COMPARE IDLE LINE Freescale Semiconductor, Inc. INPUT CAPTURE SECOND OUTPUT COMPARE Figure Receiving with Timer Functions contents registers show time falling edge start bit. resulting timer interrupt routine determine which event triggered interrupt. first entry. half times added content capture register. result stored registers interrupts switched from delay half times will cause output compare event approximately middle first data bit's reception. Next, data register cleared, data register set. This most significant (MSB) data variable acts counter. next output compare, data (either TCAP port pin) sampled using BRSET instruction. This brings value data received into carry condition code register (CCR). "rotate right through carry" (ROR) instruction rotates data into data register. rotated into data register time added register. Because data register cleared prior reception, set, always rotated into carry until eighth data received. setting carry after rotate indicates that eighth been received. When this happens, receive data full flag interrupt capability switched back input capture. AN1818 More Information This Product, www.freescale.com MOTOROLA Application Note Transmitting Transmitting transmit byte, mechanism needed that trigger given rate allow changing level output. function 16-bit timer module allows this. SECOND COMPARE Freescale Semiconductor, Inc. IDLE LINE FIRST COMPARE THIRD COMPARE Figure Transmitting with Output Compare Function routine SCISend software listing provides transmit function. Before calling SCISend, user places byte transmitted into SCIData location. Transmission starts setting condition code register (CCR) ensure proper timing read contents free-running counter. offset then added that value, result stored into output compare registers. This defines time transmission will begin. OLVL produce required falling edge start time next compare. interrupt enabled, user wait predefined event drive TCMP start transmission. When running through timer interrupt service routine, distinguishing between event (they both same interrupt) must. this way, user arbitrate between beginning byte reception reception/transmission progress. AN1818 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note Just with receiving code, transmission byte uses propagation logic from carry provide counter. When bits have been transmitted, logic will rotated into carry bit, transmit logic high stop bit. Baud Rates change baud rate, adjust values BITHI BITLO represent time frequency timer module. Likewise, BIT1HI BIT1LO should changed represent half times frequency timer module. internal frequency operation latency timer interrupt define maximum baud rate that achieved. rate timer interrupts should programmed faster than latency interrupt service routine. this happened, might miss events. frequency 16-bit timer counter four times slower than internal operating frequency. formula determine what number timer value cause specific delay fBus [(baud rate) example: Internal Frequency Timer Frequency 9600 Baud $0034 4800 Baud $0068 2400 Baud $00D0 1200 Baud $01A0 Freescale Semiconductor, Inc. AN1818 More Information This Product, www.freescale.com MOTOROLA Freescale Semiconductor, Inc. AN1818 MOTOROLA Timer Interrupt T_Int Flowchart Timer Interrupt Service Routine "T_Int" Clear Flags ICIE interrupts enabled) Clear transmission BRCLR TX,SCIFlag Sets transmission rotates next data into value goes into MSb, transmission (for counter) byte reception received value into BRSET instruction Carry Clear OLVL define next output value Rotate into data register with instruction Check times registers, store into registers Clear OLVL define next output value SCIData Empty? time store into More Information This Product, www.freescale.com Carry Set? time offset registers store back registers time store into "RX_End" Clear flags Disable interrupts Enable interrupts RDRF flag Clear flag flag Disable interrupts Enable interrupts Clear data register data register counter time store into Disbale interrupts Enable interrupts TDRE flags Application Note Baud Rates Figure Flowchart Timer Interrupt Service Freescale Semiconductor, Inc. Application Note Software Example code listing that follows illustrates reading writing serial data through timer interface. This simple software loop waits data received echoes value back sending device. Code Listing Freescale Semiconductor, Inc. SWSCI.ASM software-driven simulation 705P6A MCU, using timer's input capture output compare functions. Brad Bierschenk, Applications Engineering Hill, Austin, Texas 08/06/99 NOTES: "SCI" subroutine sets transmit routine send byte, have load into data variable, "simulated" status data register held RAM, "simulated" interrupt really timer interrupt. Limitation half-duplex only. transmit, routine. will able receive until transmission complete. This requires part that digitally read TCAP (P6A). Otherwise, separate input should tied TCAP polling. REQUIRES pullup TCAP this application. Needed bits bytes -RAMSPACE $0050 ROMSPACE $0100 PORTB PORTC PORTD DDRB AN1818 More Information This Product, www.freescale.com MOTOROLA Application Note Code Listing Freescale Semiconductor, Inc. DDRC DDRD IC1HI IC1LO OC1HI OC1LO TCNTHI TCNTLO OLVL IEDG OCIE ICIE Software TDRE RDRF equates variable SCIFlag ;BIT1HI+BIT1LO define timer delay times given ;baud rate. baud BITHI BITLO BIT1HI BIT1LO ;4800 ;BITHI ;BITLO ;BIT1HI ;BIT1LO ;2400 ;BITHI ;BITLO ;BIT1HI ;BIT1LO ;1200 ;BITHI ;BITLO ;BIT1HI ;BIT1LO baud baud baud AN1818 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note Variables -ORG RAMSPACE SCIFlag ;Simulated Status register SCIData ;Simulated Data register Start program code -ORG ROMSPACE Begin #$10 PORTB ;Set high idle line #$F7 DDRB SCIFlag SCIData IC1LO OC1LO ;Clear status register ;Clear data register ;Clear possibly flags Freescale Semiconductor, Inc. ;Initialize timer system OCLevel High (idle) falling edge (detect start bit), disable ;enable (SCI ready receive) #$81 BSET Main BRCLR TX,SCIFlag ;Clear first-entry-to-transmit ;flag ;Globally enable interrupts RDRF,SCIFlag,* ;Wait byte received ;Allow times rest last stop ;~210 cycles #$09 DelayLoop DECA DelayLoop ;Echo back received byte. RDRF,SCIFlag SCISend ;Wait next received byte Main BCLR AN1818 More Information This Product, www.freescale.com MOTOROLA Application Note Code Listing Freescale Semiconductor, Inc. SCISend sets timer module transmit byte. Uses function transmit data. Can't receive while transmitting (limitation half-duplex) -SCISend ;Disable interrupts ensure ;timing TCNTHI ;Read current timer value TCNTLO #$15 ;Add offset OC1LO ;Store value #$00 ;Accommodate carry needed OC1HI OC1LO OC1LO #%01000000 ;Generate start setting OLVL ;bit falling edge, disable ICI, ;enable ;Globally enable interrupts again T_Int timer interrupt service routine. Must arbitrate whether caused interrupt, determine whether receiving transmitting byte. (Timer interrupt Interrupt) event either byte transmitting sampling byte being received. event start received byte -T_Int ;Clear flags interrupts enabled, receive mode ;and have received start TCAP BRSET ICIE,TCR,Receive interrupts enabled, either ;transmitting byte, sampling byte coming BRSET RX,SCIFlag,RX1 receiving? this byte transmitalready-in-progress? ;The BRCLR instruction sets carry value being tested. BRCLR TX,SCIFlag,TX1 AN1818 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note ;New transmission ;Carry gets set, clear flag indicate ;transmit-in-progress. will rotated into data register ;for counter. BCLR TX,SCIFlag ;Transmitting SCIData ;Shift next data into carry low, BSET OLVL,TCR high, next level high Data register zero, Carry set, have ;just rotated last bit, need send ;stop bit. TX_End stop bit, TX_End OC1LO ;Otherwise, time #BITLO ;for next OC1HI #BITHI OC1HI OC1LO BCLR OLVL,TCR ;Carry means next data ;low next level ;Add time Freescale Semiconductor, Inc. TX_End #BITLO OC1LO #BITLO OC1HI #BITHI OC1HI OC1LO OC1LO ;Add last time ;stop OC1HI #BITHI OC1HI OC1LO IC1LO #$81 ;Disable OCI, enable AN1818 More Information This Product, www.freescale.com MOTOROLA Application Note Code Listing ;Clear first entry flag again, ;and TDRE bit. NOTE that even though ;the TDRE set, data byte complete, with rest last ;and stop transmitted #$50 SCIFlag Receive BSET IC1LO #BIT1LO IC1HI #BIT1HI OC1HI OC1LO RX,SCIFlag #$41 #$80 SCIData ;Start been received ;add 1+1/2 times first sampling Freescale Semiconductor, Inc. ;Set receive-in-progress flag ;disable ICI, enable ;Clear data register, counter BRSET 7,PORTD,RX2 SCIData RX_End OC1LO #BITLO OC1HI #BITHI OC1HI OC1LO ;get level from TCAP ;put into data variable ;End last time ;for next sample RX_End ;Byte received, clear possibly flag IC1LO #$81 ;Disable OCI, enable ;Set receive register full flag ;NOTE that even byte complete ;the rest data stop ;still their way. BSET RDRF,SCIFlag BCLR RX,SCIFlag ;Clear receive-in-progress flag AN1818 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note Vector definitions -ORG $1FF8 ;Timer vector T_Int $1FFE Begin ;Reset vector Freescale Semiconductor, Inc. AN1818 More Information This Product, www.freescale.com MOTOROLA Application Note Code Listing Freescale Semiconductor, Inc. AN1818 MOTOROLA More Information This Product, www.freescale.com Freescale Semiconductor, Inc. Application Note Freescale Semiconductor, Inc. Motorola reserves right make changes without further notice products herein. Motorola makes warranty, representation guarantee regarding suitability products particular purpose, does Motorola assume liability arising application product circuit, specifically disclaims liability, including without limitation consequential incidental damages. "Typical" parameters which provided Motorola data sheets and/or specifications vary different applications actual performance vary over time. operating parameters, including "Typicals" must validated each customer application customer's technical experts. Motorola does convey license under patent rights rights others. Motorola products designed, intended, authorized components systems intended surgical implant into body, other applications intended support sustain life, other application which failure Motorola product could create situation where personal injury death occur. Should Buyer purchase Motorola products such unintended unauthorized application, Buyer shall indemnify hold Motorola officers, employees, subsidiaries, affiliates, distributors harmless against claims, costs, damages, expenses, reasonable attorney fees arising directly indirectly, claim personal injury death associated with such unintended unauthorized use, even such claim alleges that Motorola negligent regarding design manufacture part. Motorola registered trademarks Motorola, Inc. Motorola, Inc. Equal Opportunity/Affirmative Action Employer. reach USA/EUROPE/Locations Listed: Motorola Literature Distribution, P.O. 5405, Denver, Colorado 80217. 1-303-675-2140 1-800-441-2447. Customer Focus Center, 1-800-521-6274 JAPAN: Motorola Japan Ltd.; SPS, Technical Information Center, 3-20-1, Minami-Azabu, Minato-ku, Tokyo 106-8573 Japan. 81-3-3440-8573 ASIA/PACIFIC: Motorola Semiconductors H.K. Ltd.; Silicon Harbour Centre, King Street, Industrial Estate, N.T., Hong Kong. 852-26668334 MfaxTM, Motorola Back System: RMFAX0@email.sps.mot.com; http://sps.motorola.com/mfax/; TOUCHTONE, 1-602-244-6609; Canada ONLY, 1-800-774-1848 HOME PAGE: http://motorola.com/sps/ Mfax trademark Motorola, Inc. Motorola, Inc., 1999 AN1818/D More Information This Product, www.freescale.com Other recent searchesMMBD1401 - MMBD1401 MMBD1401 Datasheet MC74F1245 - MC74F1245 MC74F1245 Datasheet HY5DU283222F - HY5DU283222F HY5DU283222F Datasheet HC4020 - HC4020 HC4020 Datasheet HC4040 - HC4040 HC4040 Datasheet CM600HU-12F - CM600HU-12F CM600HU-12F Datasheet
Privacy Policy | Disclaimer |