Submitted by:
Glenn Clark
VersaTech Electronics
The programs and drawings shown below are taken from the examples section of the manual.
Another very common use for TICkit type processors is to "glue" together various electronic instruments using RS232 format serial connections. Many such instruments are available as a result of Marine use of GPS, Compass and LORAN. NEMA standards for communications as well as serial interfaces for LCD displays and countless data acquisition instruments, make the RS232 format one of the most essential controller interfaces.
Even though RS232 is so wide spread, it is a standard which was not initially intended for many of the uses it now performs. This leads to a rather loose interpretation of the signal names and meanings. Generally, the only standard part of the RS232 standard is the bit timing of the serial data stream. The voltages, polarities, pin assignments, and connectors all vary by application. Therefore, when we refer to RS232 in respect to the TICkit, we are referring to the bit timing of the stream. The TICkit can produce TICkit output that is either intended for standard RS232 drivers like the MAX232 or 1489 driver ICs, or it can produce an open drain inverted output that can, in most cases, be connected directly to RS232 sockets via a resistor.
The following diagrams illustrate RS232 timing and how inverted or non-inverted signals appear on output pins.
There are 5 basic functions associated with serial communications on the TICkit. There are complex functions are available that build on these functions.
The first functions are the rs_param_set() and rs_param_get() function. These two functions are used to setup subsequent serial communications. These functions set the baud rate, pin number for data, and determine if the stream is inverted or not.
The third function is the rs_send() function. This function sends the specified byte out using the format and pin set by the rs_param_set() function. The function, rs_break() can be used to send a byte with a forced framing error, but this is seldom required. This is used for advanced serial protocols.
The fourth function is the rs_receive() function. This function receives a single byte of specified format from the specified pin. This function can have a timeout or wait indefinitely to receive a byte. It also returns error information when an error in format is detected in the input stream. A special control parameter allows a handshake pin to be used in addition to the data stream pin specified with the rs_param_set() function.
The fifth function, rs_recblock() is similar to the rs_receive() function except that it can receive more than one byte. This function also has the control parameter and can be instructed to ignore data until a matching byte or a break is detected in the input stream. These special conditions can be useful when creating a network of controllers that are linked by a shared serial line.
For this manual, we are only going to deal with serial transfer to and from a PC. We use a normal communications program like WINTERM or PROCOMM to send and receive serial data over a standard COM port. The cable we use is shown below. Also included are the standard pin assignments for 9 and 25 pin PC connectors.
Pin Function | DB9 | DB25 |
Frame Ground | 1 | |
Transmit data (TD) | 3 | 2 |
Receive data (RD) | 2 | 3 |
Request to Send (RTS) | 7 | 4 |
Clear to Send (CTS) | 8 | 5 |
Data Set Ready (DSR) | 6 | 6 |
Signal Ground (SG) | 5 | 7 |
Data Carrier Detect (DCD) | 1 | 8 |
Data Terminal Ready (DTR) | 4 | 20 |
Ring Indicator (RI) | 9 | 22 |
The demonstration program is as simple as the circuit. The program initializes the LCD display then displays 20 characters it receives with the rs_receive() function. The rs_send() function is used by the rs_string() function to send a message to the PC saying, "send a block beginning with 'A'". At this point, the program uses rs_recblock() to get a block of 10 characters which are prefaced with the letter 'A'. When all 10 characters are received, the string is displayed on the LCD. The process is repeated indefinitely
DEF tic62_c LIB fbasic.lib ; These defines used by the LCD libraries DEF xbuss_mask 0y00100001b ; These are the address lines used DEF lcd_data_reg 0y00100001b ; Address of data register DEF lcd_cont_reg 0y00100000b ; Address of control register LIB lcdinit4.lib LIB lcdsend.lib LIB lcdstrin.lib FUNC none rs_string PARAM word in_string PARAM word temp_ptr PARAM word temp_chr BEGIN =( temp_ptr, in_string ) =( temp_chr, ee_read( temp_ptr )) WHILE temp_chr rs_send( temp_chr ) ++( temp_ptr ) =( temp_chr, ee_read( temp_ptr )) LOOP ENDFUN
FUNC none main LOCAL byte in_count LOCAL byte temp_chr LOCAL byte in_array[ 10b ] BEGIN delay( 500 ) ; delay 1/2 second lcd_init() rs_param_set( rs_invert | rs_9600 | pin_a3 ) =( in_count, 0b ) REP lcd_data_wr( rs_receive( 0b, 0b, 0b )) ++( in_count ) UNTIL ==( in_count, 20b ) rs_param_set( rs_invert | rs_9600 | pin_a1 ) rs_string( "Send a block beginning with 'A'" ) rs_param_set( rs_invert | rs_9600 | pin_a3 ) =( temp_chr, rs_recblock( 0b, rs_cont_addr, 'A',~ ~ in_array[ 0b ], 10b ) rs_param_set( rs_invert | rs_9600 | pin_a1 ) rs_string( "Block was: " ) =( in_count, 0b ) REP rs_send( in_array[ in_count ] ) ++( in_count ) UNTIL ==( in_count, 10b ) reset() ENDFUN
The PC's communication program must be set to the following settings: 9600 baud, the com port number that the cable is plugged into, no handshake, 8 bits, no parity, 1 stop bit. Play with this program and circuit to get a feel for how things work. Some people may find that when the TICkit sends data nothing is received by the PC or possibly garbled data is received. This is because the voltages generated by the TICkit are in the range of 0 to 5 volts. True RS232C states that the voltages should range between +3 and +9 volts for a "space" (low) and -3 to -9 volts for a "mark" (high). The following circuit accomplishes an official interface to a PC. The only program change required for this circuit is to remove the "rs_invert" word from the rs_param_set function calls. The circuit for PC communication, with conforming drivers is shown here.
Protean Logic Inc. Copyright 05/06/04 Top of Page