<< Chapter < Page Chapter >> Page >
Explains how to send and receive data with the DSP through the serial port. Example code is shown in both assembly and C (for the DSP) as well as MATLAB for interfacing on the PC. Some example code for creating a MATLAB GUI is also shown.

Introduction

The serial port on the back of the DSP box can be used to transmit data between the DSP and the PC during real-time operation. Eight bits ofdata can be transmitted at one time (signed or unsigned). This can then be used as feedback from the DSP for a variety of applications. The serial port isconnected to a data buffer which holds values coming from the DSP until they are read. This allows for sending larger amounts of data (more than 1-byte) at a time from the DSP to the PC.The same is true in the opposite direction.

    Our serial port specifications

  • Port: com2
  • DataRate: 38400
  • Parity: None
  • StopBits : 1 Stop Bit
  • DataBits : 8 Data Bits
  • Handshaking : none
These parameters can be used when accessing the serial port through third-party utilities such as HyperTerminal (included with windows).

Using the dsp to access the serial port

The serial port data buffer can be written to with either C or assembly code. These functionalities are supplied through the core file, so it must be includedwith any of this code.

Using assembly to send/receive

Accessing the serial port in assembly comes in the form of macros (READSER and WRITSER). These macros allow for multiple bytes of data to be written to the serial portbuffer at a time.

  • READSER : READSER accepts one parameter, an integer number(n). The macro will read n bytes into memory and place them starting at the address *AR3 . The macro modifies AR3 and it is left pointing to one byte past the last memory location written. The actual number of data bytes read isput into AR1 . If AR1 is zero, there were no available data byte sin the buffer. The calling format is: READSER n
  • WRITSER : Similar to the previous macro, WRITSER takes a single integer parameter n. This macro will add n bytes starting at *AR3 to the serial port buffer. *AR3 is left pointing one location after the last memory read. This data is queued in the buffer and will remain there until the PC retrieves the data. The calling format is: WRITSER n
READSER and WRITSER modify registers AR0, AR1, AR2, AR3, and BK as well as the flag TC.

The core file allows up to 126 characters to be stored in the input and output buffers. No checks to protect against buffer overflows are made, so do not allow the input and outputbuffers to overflow. (The length of the buffers can be changed by changing ser_rxlen and ser_txlen values in the core.asm file.) The buffers are 127 characters long; however, the code cannot distinguish between a completely-full and completely-empty buffer.Therefore, only 126 characters can be stored in the buffers.

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

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Digital signal processing laboratory (ece 420). OpenStax CNX. Sep 27, 2006 Download for free at http://cnx.org/content/col10236/1.14
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Digital signal processing laboratory (ece 420)' conversation and receive update notifications?

Ask