120 likes | 227 Views
ECE 353 Introduction to Microprocessor Systems. Discussion 13. Topics. Serial I/O Q&A. Problem.
E N D
ECE 353Introduction to Microprocessor Systems Discussion 13
Topics • Serial I/O • Q&A
Problem • Write a serial receive procedure, receive, that receives a 10-bit frame with even parity. The procedure returns the ASCII character in R0, and parity error status in R1 (0 = no error, 1 = parity error). Assume that two delay procedures are available, half_bit_time and one_bit_time. Also, assume that there is a 1 bit data port defined as INPUT, where you read the incoming data on D0.
Answer • We will assume Asynchronous Serial Protocol • A 10-bit frame will include: • A one-bit start bit: 0 • A 7-bit pattern – sent LSB first • A parity bit – optional, used in this problem (The problem itself states the parity will be fixed, thus we will need the parity bit!) • A one-bit stop bit : 1. • Things to keep in mind: • Is there a way to distinguish noise from an actual start bit? • When is the best time to read the input to avoid errors due to noise or signal fluctuations or timing variations between receiver and transmitter?
Solution code “skeleton” receive PUSH {R2-R5, LR} ;context save LDR R2, =INPUT MOV R0, #0 MOV R1, #0 MOV R4, #0 ;keep track of parity MOV R5, #8 ;loop count - read bits poll_for_start get_bits parity_error frame_error done POP {R2-R5, PC} ;context restore/return END
Answer • First, we will check for an actual start bit poll_for_start LDR R3, [R2] ;read data port ANDS R3, R3, #1 ;test D0 BNE poll_for_start ;still a 1 - check again BL half_bit_time ;delay 1/2 bit time and ;check again LDR R3, [R2] ;read data port ANDS R3, R3, #1 ;test D0 BNE poll_for_start ;not still 0, keep polling
Answer • Then, we de-serialize the pattern set get_bits BL one_bit_time ;delay 1 bit time and get ;bit LSR R0, #1 ;prep for next bit LDR R3, [R2] ;read data port ANDS R3, R3, #1 ;test D0 ORRNE R0, R0, #0x80 ;put bit in result ADDNE R4, R4, #1 ;count 1 bits for parity calc. SUBS R5, R5, #1 ;decrement loop count BNE get_bits ;loop til count = 0
Answer • Check for frame error, check parity, return result, handle error in frame ;check for frame error BL one_bit_time ;delay 1 bit time and get bit LDR R3, [R2] ;read data port ANDS R3, R3, #1 ;test D0 BEQ frame_error ;framing error parity_error ANDS R4, R4, #1 ;if D0 in R4=1, error, odd # bits MOVNE R1, #1 ;set parity error for return BIC R0, R0, #0x80 ;clear bit7 – just want data bits B done frame_error BL frame_err_proc ;frame error - go to error handler done
RS-485 • Differential transmission • Transceivers usually have separate enables for transmit and receive – allows creation of a multi-drop bus • Longer distances possible than with RS-232 (roughly 4000 feet at 64K)
RS-485 • Need a protocol to prevent bus contention – only one transmitter on at a time • Master/Slave • Token passing • Bus turnaround speed is an issue – after completing a transmission, must disable the transmitter before another device enables its transmitter to send a reply or initiate a different transaction • Overhead associated with a bus – must deal with traffic not meant for you – takes cpu time