Our Serial Port Specifications
- Port: com2
- DataRate: 38400
- Parity: None
- StopBits : 1 Stop Bit
- DataBits : 8 Data Bits
- Handshaking : none
Using the DSP to Access the Serial Port
Using Assembly to Send/Receive
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
AR3and it is left pointing to one byte past the last memory location written. The actual number of data bytes read is put into
AR1is zero, there were no available data byte sin the buffer. The calling format is:
WRITSER: Similar to the previous macro, WRITSER takes a single integer parameter n. This macro will add n bytes starting at
*AR3to the serial port buffer.
*AR3is 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:
ser_txlenvalues 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.
srx_tail; if both memory locations hold the same value, the input buffer is empty. Likewise, the output buffer can be checked by comparing the values stored in memory locations
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.
Alternative Method in Assembly
WRITSERmacros. Performance of these macros is often "flaky" if they even work at all. Two ECE 320 students I-Ju Liao and Jung-Gyu Lee from the Fall 2002 semester created this alternative method which provides much better assembly support for serial port access. The following is a skeleton for reading data from the serial port onto the DSP:
Using C to Send/Receive
SerialRX()takes no arguments and returns an integer, which is the next byte waiting in the serial input buffer. If there is no byte waiting, the function returns -1.
SerialTX()takes one argument, an integer to place in the serial output buffer. It returns nothing.
SerialRXBufCheck()takes no arguments and returns the number of bytes waiting in the serial input buffer.
SerialRXm()takes two arguments: the first is the number of bytes to read from the serial input buffer, and the second is a pointer, which is usually the name of an array into which the bytes will be copied. If you attempt to read more bytes than are waiting, the function will only copy those bytes that are waiting and then return. It always returns the number of characters read.
SerialTXm()takes two arguments: the first is the number of characters to write into the serial output buffer, and the second is a pointer, which is usually the name of an array containing the bytes to copy. It returns nothing.
Using MATLAB to Access the Serial Port (PC)
% Set serial port mode !mode com2:38400,n,8,1
% open com port for data transfer fid = fopen('com2:','w');
help serial. Since the DSP is blind to the different types and we can only use 8 bits at a time, int8 should work.
% send reset pulse fwrite(fid,255,'int8'); % close com port connection fclose(fid);
fid = serial('com2');command. This does not seem to work for reading either. See the MATLAB help for more details and methods.
Setting Up GetSerialData.cpp
Using GetSerialData with the DSP
y = GetSerialData('port', baud, size);
- 'port' is the serial port to which the DSP is connected. For our use it will be 'com2'. The port name must be entered in quotes.
- baud is the speed at which we transfer data. For the DSPs in lab we use 38400.
- size is the length of the row vector you want to acquire.
- y is the output vector.
Using MATLAB GUI Features
Creating a User Interface with Sliders
units: Normal tells Matlab to use positioning relative to the window boundaries.
pos: Tells Matlab where to place the control.
style: Tells Matlab what type of control to place. slider creates a slider control.
value: Tells Matlab the default value for the control.
max: Tells Matlab the maximum value for the control.
min: Tells Matlab the maximum value for the control.
callback: Tells Matlab what script to call when the control is manipulated. wrt_slid is a Matlab file that writes the values of the controls to the serial port.