hw6_SCI_answers

advertisement

1

ECE371 Homework 6 -- Answers

1. What serial data (write 1’s and 0’s) would be sent by the SCI unit of the MC9S12DP256B microcontroller if a value of the data character to be sent is 49 hex. Use a format of 8 bits per character with odd parity.

{start bit }{01001001 starting with LSB}{parity bit}{stop bit}

01001001001 (9-bit mode)

0100100101 (8-bit mode)

(b) Repeat for no parity.

0100100101

2. Which are true of the parity error flag? (Circle all that are true.)

(a) If there is an error of exactly one bit in the serial data stream associated with transmitting and receiving a character, the parity error system will detect this condition.

(b) If there is an error in an even number of bits in the serial data stream associated with transmitting and receiving a character, the parity error flag will not be set. x(c) If the parity error flag is set, we know that there has been an error in exactly one bit of transmitted data.

3. If the bus clock that drives the SCI serial I/O system on the MC9S12DP256B microcontroller is a 2

MHz clock, what value should be initialized into the baud rate registers of the SCI unit if we want to achieve a serial data rate as close as possible to 1000 baud?

BAUD RATE DIVISOR = 2MHZ / (16 * (DESIRED BAUD RATE))

2MHz / (16*1000) = divisor = 125 or 0x7D

SCIOBDH= 0;

SCIOBDL=125;

(b) What actual serial data rate will result from using the values you selected for the baud rate registers in part a?

1000 bps

(c) At this rate, what is the minimum time it would take the SCI unit, with 8 bits per frame, no parity, and 1 stop bit, to transmit a total of 100 characters?

100 characters * 10 bits per character / 1000 bits per second = 1 second

4. On the MC9S12DP256B SCI module, what can cause an "overrun error" (OR), and how can this be prevented?

Not reading the received data register before the next incoming value is received

When the RDRF flag (SCI0SR1, bit 5) is set, the data register (SCI0) must be read immediately using an interrupt service routine or a loop

2

(b) On the MC9S12DP256B SCI module, what causes a "framing error" (FE), and how can this be prevented?

Cause 1: Errors in the transmission

Remedies: Reduce data rate, shield cable, use shorter cable, reroute cable, provide better power filtering

Cause 2: Configuration error

Remedy: Ensure that sender and receiver are using the same data size, parity configuration, and bit rate

5. Give the C statements to set up an ISR that executes when the SCI unit is ready to transmit data.

//assuming SCI0

SCI0CR2 |= 0x0C; //Enable SCI module transmitter and receiver

SCI0CR2 |= 0x80; //Set Transmitter Interrupt Enable Bit (generate interrupt when TDRE = 1)

SETVECT(0xFFD6,sci_isr);

ENABLE(); void sci_isr ( void ){ …}

(b) Give the C statements to set up an ISR that executes when the SCI unit has received incoming data.

//assuming SCI0

SCI0CR2 |= 0x0C; //Enable SCI module transmitter and receiver

SCI0CR2 |= 0x20; //Set Receiver Full Interrupt Enable Bit (generate interrupt when RDRF = 1)

SETVECT(0xFFD6,sci_isr);

ENABLE(); void sci_isr ( void ){ …}

6. The following data stream is received by a serial SCI device, what character value is represented, assuming that 8 data bits per character are being used. Assuming no errors in transmission, what is the binary value of the character sent?

____

|_|

___

|_|

__

|___|

__________

0 111 0 11 000 111111

{0 start bit }{8 data bits starting with MSB}[parity bit]{stop bit}

Data = 1110 1100 => 00110111 = 0x37

Parity bit = 0

(b) Assuming there are no errors in the transmission, is even parity, odd parity, or no parity being used?

Odd parity (since there are 5 1’s and the parity bit is zero)

(c) If the data value receiving is using the ASCII code for representing characters, what is the numerical value represented by the above data stream?

ASCII 0x37 = ‘7’

Download