<< Chapter < Page Chapter >> Page >
The core file provides two macros, READSER and WRITSER, for communicating with a PC via the serial port. One can create graphical user interfaces in MATLAB to control the DSP in real time.

Using the serial port

The core file supports the serial port installed on the TI TMS320C54x DSP. The serial port on the EVM is connected with acable to COM2 on the PC. Before jumping to your code, the core file initializes the EVM's serial port to 38,400 bits persecond (bps) with no parity, eight data bits, and one stop bit (but it may be necessary to restart the DSP completely if theserial port does not work.) It then accepts characters received from the PC by the UART ( Universal Asynchronous Receiver/Transmitter ) and buffers them in memory until your code retrieves them. It also can accept ablock of bytes to transmit and send them to the UART in sequence.

Two macros are used to control the serial port: READSER and WRITSER . Both accept one parameter. READSER n reads up to n characters from the serial input buffer (the data coming from the PC) and places them in memory starting at *AR3 . ( AR3 is left pointing one past the last memory location written.) The actual number ofcharacters read is left in AR1 . If AR1 is zero, then no characters were available in the input buffer.

WRITSER n adds n characters starting at *AR3 to the serial output buffer; in other words, it queues them to besent to the PC. AR3 is left pointing one location after the last memory location read.

Note that READSER and WRITSER modify registers AR0 , AR1 , AR2 , AR3 , and BK , as well as the flag TC . Be sure you restore these registers after calling READSER and WRITSER if you need them later in your code.

Note also that the core file allows up to 126 characters to be stored in the input and output buffers. Neither the DSPhardware nor the core file protect against serial-buffer overflows, so you must be careful not to allow the input andoutput buffers to overflow. (The length of the buffers can be changed by editing ser_rxlen and ser_txlen values in core.asm .) The buffers are 127 characters long; however, the code cannotdistinguish between a completely-full and completely-empty buffer. Therefore, only 126 characters can be stored in thebuffers.

It is easy to check if the input or output buffers in memory are empty. The input buffer can be checked by comparing thevalues stored in the memory locations srx_head and srx_tail ; if both memory locations hold the same value, the input buffer is empty. Likewise, the outputbuffer can be checked by comparing the values stored in memory locations stx_head and stx_tail . The number of characters in the buffer can be computed bysubtracting the head pointer from the tail pointer; add the length of the buffer (normally 127) if the resulting distanceis negative.

The following example shows the minimal amount of code necessary to echo received data back through the serialport. It is available as ser_echo.asm .

1 .copy "core.asm" 2 3 .sect ".data" 4 hold .word 0 5 6 .sect ".text" 7 main 8 stm #hold,AR3 ; Read to hold location 9 10 READSER 1 ; Read one byte from serial port 11 12 cmpm AR1,#1 ; Did we get a character? 13 bc main,NTC ; if not, branch back to start 14 15 stm #hold,AR3 ; Write from hold location 16 WRITSER 1 ; ... one byte 17 18 b main

Questions & Answers

what are components of cells
ofosola Reply
twugzfisfjxxkvdsifgfuy7 it
Sami
58214993
Sami
what is a salt
John
the difference between male and female reproduction
John
what is computed
IBRAHIM Reply
what is biology
IBRAHIM
what is the full meaning of biology
IBRAHIM
what is biology
Jeneba
what is cell
Kuot
425844168
Sami
what is biology
Inenevwo
what is cytoplasm
Emmanuel Reply
structure of an animal cell
Arrey Reply
what happens when the eustachian tube is blocked
Puseletso Reply
what's atoms
Achol Reply
discuss how the following factors such as predation risk, competition and habitat structure influence animal's foraging behavior in essay form
Burnet Reply
cell?
Kuot
location of cervical vertebra
KENNEDY Reply
What are acid
Sheriff Reply
define biology infour way
Happiness Reply
What are types of cell
Nansoh Reply
how can I get this book
Gatyin Reply
what is lump
Chineye Reply
what is cell
Maluak Reply
what is biology
Maluak
what is vertibrate
Jeneba
what's cornea?
Majak Reply
what are cell
Achol
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Dsp laboratory with ti tms320c54x. OpenStax CNX. Jan 22, 2004 Download for free at http://cnx.org/content/col10078/1.2
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Dsp laboratory with ti tms320c54x' conversation and receive update notifications?

Ask