DOC PREVIEW
U of U ECE 3720 - Lecture 16 - Serial I O Devices cont
Pages 11

This preview shows page 1-2-3-4 out of 11 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Slide 1'&$%ECE/CS 3720: Embedded System Design(ECE 6960/2 and CS 6968)Chris J. MyersLecture 16: Serial I/O Devices (cont)Slide 2'&$%SCI Hardware Interface1Slide 3'&$%Baud Rate Selection for MC68HC11SCP1 SCP0 Prescaler,P0 0 10 1 31 0 41 1 13SCR2 SCR1 SCR0 Divider,BR0 0 0 10 0 1 20 1 0 40 1 1 81 0 0 161 0 1 321 1 0 641 1 1 128Slide 4'&$%SCI Data Register (SCDR)SCI Control Register 1 (SCCR1)• R8 - Receive data bit 8 (used if M=1)• T8 - Transmit data bit 8 (used if M=1)• M - Mode, 1 creates 11-bit frame (else 10-bit frame)• WAKE - Wake up by address mark (1) or idle (0)2Slide 5'&$%SCI Control Register 2 (SCCR2)• TIE - Transmit interrupt enable• TCIE - Transmit complete interrupt enable• RIE - Receive interrupt enable• ILIE - Idle line interrupt enable• TE - Transmitter enable• RE - Receiver enable• RWU - Receiver wake-up control• SBK - Send breakSlide 6'&$%SCI Status Register (SCSR)• TDRE - Transmit data register empty flag• TC - Transmit complete flag• RDRF - Receive data register full flag• IDLE - Idle line detected flag• OR - Overrun error flag• NF - Noise error flag• FE - Framing error flag3Slide 7'&$%Output a Character Using the SCI PortOutChar ldab SCSR ;statusbitb #$80 ;tdre?$beq OutCharstaa SCDR ;outputrtsOutChar staa SCDR ;outputwait2 ldab SCSR ;statusbitb #$80 ;tdre?beq wait2rtsOutChar staa SCDR ;outputwait3 ldab SCSR ;statusbitb #$40 ;TC?beq wait3rtsSlide 8'&$%Output a Character Using the SCI Port in Cvoid init(void){ BAUD=0x33; // 1200 baudSCCR1=0x00; // 8data, 1stopSCCR2=0x0C;}// enable gadfly#define RDRF 0x20#define TDRE 0x80#define TC 0x40unsigned char insci(void){while ((SCSR & RDRF) == 0);return(SCDR); }void OutChar(unsigned char letter){while ((SCSR & TDRE) == 0); /* Wait for TDRE */SCDR=letter; } /* then output */void outsci2(unsigned char letter){SCDR=letter; /* Output then */while ((SCSR & TDRE) == 0);} /* wait for TDRE */void outsci3(unsigned char letter){SCDR=letter; /* Output then */while ((SCSR & TC) == 0); } /* wait for TC */4Slide 9'&$%SCI Receive Only Interrupt InterfaceBit SCCR27 0 TIE=06 0 TCIE=05 1 RIE=14 0 ILIE=03 1 TE enable TxD2 1 RE enable RxD1 0 RWU no wake up0 0 SBK no breakSlide 10'&$%Ritual to Initialize to Accept Receive InterruptsRITSCI sei ;make atomicldaa #$31 ;4800 baudstaa BAUDldaa #00 ;M=0, 8 bit datastaa SCCR1 ;1 stopldaa #$2Cstaa SCCR2bsr CLRQ ;Initialize FIFOcli ;Enablerts5Slide 11'&$%ISR for Receiver InterruptsSCIHAN ldaa SCSRanda #$20 RDRF set?bne INSCIINSCI ldaa SCSR ;statusanda #$0E ;OR, NF, FEbne ERRORldaa SCDR ;data, ackbsr PutFifo ;Communicatebcs ERROR ;FIFO full?rtiSlide 12'&$%SCI Receive Interrupt Interface in C#pragma interrupt_handler SCIHAN()#define RDRF 0x20// Executed on RDRF (not TDRE)void SCIhandler(void){if((SCSR&0x21)!= RDRF) error();if(SCSR&0x0E) error();if(PutFifo(SCDR)) error(); }void RitualSCI(void){asm(" sei");BAUD=0x31; // 4800 bits/secSCCR1=0; // 8 bit 1 stopSCCR2=0x2C; // Receiver intrptCLRQ(); // Clear FIFOasm(" cli");}6Slide 13'&$%SCI Transmit Only Interrupt Interface (simple)Slide 14'&$%SCI Transmit Only Interrupt Interface (improved)7Slide 15'&$%Input and Output Interrupts on the SCI• Simultaneous input and output requires two FIFOs.• RxFifo passes data from InSCI handler to main thread.• TxFifo passes data from main thread to OutSCI handler.• Since TxFifo initially empty, transmit interrupts initiallydisarmed.• When main thread calls OutChar, transmit interruptsarmed.• Interrupt handler disarms transmit interrupts whenTxFifo becomes empty.Slide 16'&$%Ritual to Initialize the SCI PortInit ldaa #$30 ;9600 baud$staa BAUDldaa #$00 ;modestaa SCCR1jsr RxInitFifo ;emptyjsr TxInitFifo ;emptyldaa #$2c ;just RDRFstaa SCCR2 ;enable SCIclirts8Slide 17'&$%Routines to Perform Serial I/OInChar jsr RxGetFifobeq InCharrtsOutChar jsr TxPutFifo ;savebeq OutChar ;full?ldab #$AC ;arm bothstab SCCR2 ;TDRE, RDRFrtsSlide 18'&$%ISR for Receiver and Transmitter InterruptsSCIhdlr ldaa SCSRanda #$20 ;check RDRFbeq ChkTDRE ;Not RDRFInSCI ldaa SCDR ;ASCII codebsr RxPutFifoChkTDRE ldaa SCSRanda #$80 ;check TDREbeq SCIdone ;Not TDREOutSCI bsr TxGetFifobeq nomorestaa SCDR ;start nextbra SCIdonenomore ldaa #$2Cstaa SCCR2 ;disarm TDRESCIdone rti9Slide 19'&$%Serial Port Printer Interfaces• Printer bandwidth may be less than the maximumbandwidth supported by the serial channel.1. Special characters may require more time to print.2. Most printers have internal FIFOs that could get full.3. The printer may be disconnected.4. The printer may be deselected.5. The printer power may be off.• Flow control is needed to synchronize computer withvariable rate output device (ex. DTR or XON/XOFF).Slide 20'&$%Use of DTR to Interface a Printer10Slide 21'&$%Serial Output Using DTR Synchronization;PA0/IC3 is DTROutChar ldab PORTA ;wait forbitb #$01 ; DTR=0bne OutChar ;ldab SCSR ;statusbitb #$80 ;tdre?beq OutCharstaa SCDR ;outputrtsSlide 22'&$%Serial Output Using DTR Synchronization in C// PA0/IC3 is DTRvoid OutChar(unsigned char data) {while((PORTA&0x01)||((SCSR&0x80)==0));SCDR= data; }11Slide 23'&$%Initialization Using DTR Synchronization// PA0/IC3 is DTRvoid Ritual(void){asm(" sei");InitFifo();BAUD=0x33; // 1200 bits/secSCCR1=0x00; // 8 bit, 1 stopSCCR2=0x0C;/* SCI disarmed because FIFO is empty */TCTL2=0x03; // both rise or fallTMSK1=0x01; // Arm IC3TFLG1=0x01; // clear IC3F */asm(" cli");}Slide 24'&$%Output Function Using DTR Synchronizationint OutChar(unsigned char data) {unsigned char flag;/* Bit7=1 is the first stop bit */flag=PutFifo(data^0x80);checkIC3(); /* Arm SCI if DTR=+12 */return(flag);} /* error if FIFO is full */12Slide 25'&$%Helper Functions for DTR Synchronization// PA0/IC3 is DTRvoid checkIC3(void) {if(PORTA&0x01) // PA0=1 if DTR=-12SCCR2=0x0C; // SCI TxD disarmedelseSCCR2=0x8C;} // SCI TxD armedSlide 26'&$%ISR Using DTR Synchronization// PA0/IC3 is DTR#pragma interrupt_handler IC3Han()void IC3Han(void) {TFLG1=0x01; // Ack clear IC3FcheckIC3();} // Arm SCI if DTR=+12#pragma interrupt_handler SCIHAN()void SCIHan(void) { unsigned char data;if(!GetFifo(&data);)SCCR2=0x0C; // disarmed, emptyelseSCDR=data;} // output, ack interrupt13Slide 27'&$%Use of XON/XOFF to Interface a PrinterSlide 28'&$%Synchronous Communication Using the SPI• Two devices communicating with SCI operate at samefrequency but have 2 separate (not synchronized) clocks.• Two devices communicating with SPI operate using thesame (synchronized) clock.• Master device creates the clock while slave device(s) usethe


View Full Document

U of U ECE 3720 - Lecture 16 - Serial I O Devices cont

Course: Ece 3720-
Pages: 11
Download Lecture 16 - Serial I O Devices cont
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 16 - Serial I O Devices cont and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 16 - Serial I O Devices cont 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?