Serial Communications
Introduction
This lab is based on using the SCI Serial Communications module, and will show the basic steps needed to set up the HCS12 for asynchronous serial communications. We will write a simple program that continuously transmits a string of characters from a Dragon12 board, and then add some code so that we can receive and store the characters as well.
1-Pre-lab
For the pre-lab, draw the waveform you would see on a logic analyzer when sending the character 'A' out of the transmit SCI port. Show the whole frame including start, stop and data bits, and include a time axis (assume we are transmitting at 9600 baud). The tutorials noted below will give you the information needed to solve this problem.
2-Tutorials
3-Program
* Following the steps outlined in the stationery tutorial above, name your project "lab7" and make it from the ee3176 stationery. Name your absolute executable "lab7.abs" and your source code "lab7.asm".
* Make a program from scratch that is similar to that of the SCI demo, except your new program will transmit AND receive characters of the string 'Code Warrior'. Your program will have the specifications noted below.
* Your code for the transmit portion should be similar to that of the SCI demo program noted above; you will still send out the string 'Code Warrior' in an infinite loop out of the TX port. However, you will need to add code for the RX receive portion. Again, when your program is running, you will both transmit AND receive serial data.
* For the RX portion of code to add, the received data should be saved in RAM with the label "rx_string" that points to a region of memory large enough for the string 'Code Warrior' (hint: use a "ds.b" type command that reserves space for the characters of the string). As you read data into the RX register, you will store it in the rx_string memory location, advancing one byte as each character is read in. You should use an rx_ptr value to move along the rx_string much as you did with the tx_string. The RX portion should run as a subroutine that is called in loop 1 after the first delay, something like:
loop1:
jsr TX_CHAR ; output char via TX of SCI1
jsr DELAY ; wait 2 msec between TX
inc tx_ptr+1 ; update tx_ptr
jsr RX_CHAR ; input char via RX of SCI1
jsr DELAY ; wait 2 msec between RX
inc ??? ; update rx_ptr, you need to add code here
deca
bne loop1
bra loop2 ; infinite loop
* You will thus need to: (1) enable the RX register (and also the TX register of course) in the initialization part of the program at the beginning of your code; (2) set up and initialize the rx_ptr and add the code to increment it; and (3) create an RX_CHAR subroutine (much like the TX_CHAR subroutine) that reads the value from the RX register and saves it to the desired memory location. You may find it helpful to refer to the HCS12 hardware manual in the lab to get the register address for the RX enable, etc.
* Add the RX code and assemble the new program. Make sure the program/project names are lab7.asm, lab7.abs, lab7.mcp, etc.
* Verify that the RX portion of code works OK. To do this, first set the J23 jumper to position 1-2 (URDX1) - this will connect the PS2 header pin to the P91 pin of the HCS12 chip and thus enable you to receive data. Then, connect a short jumper cable from the TXD1 PS3 pin to the RXD1 PS2 pin so that you have looped the TX output to the RX input. !CALL THE TA OVER TO VERIFY THAT YOU HAVE SET THIS UP CORRECTLY BEFORE YOU DO ANYTHING!
* Load the TX/RX program into DBug12. Before you run the program, type "md xxxx" (where xxxx is the address you set for the rx_string) to see the starting values in RAM. They should all be zeroes. Now, run the program using the "g 1000" command at the DBug12 prompt. Hit the abort button, and check the data at the RAM address assigned to rx_string. You should see the string "Code Warrior" stored there.
* Build and run the program. Debug it as necessary until it runs correctly.
* For checkout, verify to the TA that the program works OK.
4-What to Hand In
At the next lab, hand in the commented code from your program from above. Remember to include your: (1) name; (2) date; (3) class (eg, UTEP EE3176);(4) the name of the program (eg, "lab7.asm"); and (5) what the program does. In addition, there should be comments throughout your program that describe what the main sections of code do.