Submitted by:
Glenn Clark
VersaTech Electronics
Parallax's Basic STAMP II has proved to be a very capable processor for a wide variety of tasks. One shortfall of this device, however, is that it can not receive RS232 serial data in background. The ability is often required. An example of background processing might be a situation where the STAMP II is controlling a motor or gathering A/D data while connected to a PC. With no background serial, it is impossible to receive RS232 serial data while the STAMP is doing anything else. So, if the stamp is executing a PWM command or a SHIFTOUT command when the PC sends serial data, that serial data will be lost.
What is needed is a way to store the serial data while the STAMP is busy with other tasks, and then a way to receive the stored data when the STAMP is ready. Protean's RSB509 can do just that.
The RSB509B receives the serial data from the PC ( or whatever serial device ) and stores it (up to 32 bytes). The STAMP asks for serial data by temporarily outputting a high voltage level on the pin connected to the RSB509. When the STAMP executes a SERIN command, the line specified is configured for input which removes the high voltage from the I/O pin. The RSB509 sees this high pulse and understands the STAMP is ready for data. The RSB509 then sends data to the STAMP.
The circuit to accomplish this task using the RSB509 is shown below. Notice that pull down resistors are used on the interface and status pins. This is required to accomplish bi-directional use of the I/O pins on the RSB509. In this example, the serial input to the RSB509 is configured to be "true". This means that the serial from the PC will need to be buffered through a MAX232 or an MC1489 which are RS232 buffer/driver ICs.
The program that follows uses the circuit above to receive serial RS232 and to display it on the STAMP's PC console. In reality, you probably would not have two PCs. But the example illustrates how to receive RS232 using the RSB509. You can modify the program to do something else with the received data.
' sample program for RSB509 on STAMP II
inval VAR byte
'generate a 10 ms pulse to signal initialization HIGH 1 PAUSE 10 INPUT 1
' pin P1 is used for input. ' we are using open, inverted, 9600, 8n1 format ' no match byte is used but we must send a byte to ' hold our place during initialization SEROUT 1, 49236, [" "]
' pin P1 is used for input. ' we are using open, inverted, 9600, 8n1 format ' The input to the RSB509 is "true", 9600, 8N1 SEROUT 1, 49236, [%00000000]
' wait for RSB509 to reset PAUSE 100
around: ' generate a quick pulse for each byte ' to be read. HIGH creates the start of ' the pulse. SERIN creates the end of the ' pulse when it makes the pin an input ' ( because the interface pin is pulled low ) HIGH 1
' pin P1 is used for input. ' we are using open, inverted, 9600, 8n1 format ' if a byte is not received within 1 ms branch to ' "around" to poll again. ' data will only be displayed when a byte is received SERIN 1, 16468, 5, around [inval]
' show character received on debug window DEBUG inval
GOTO around END
The meaning of all of the config bytes is as follows:
Initially an RSB509 will sit idle after power up waiting for a the control bytes to be sent. To send a control message, pull the interface line to the RSB509 high for a time greater than 11 bit times ( at 9600 baud this is 1144 microseconds ). Then send the address match byte. Send a dummy byte if no address matching is to be done just to keep things consistent for the RSB509. Then send the control byte. Build up the byte with the defines that follow or use this bit map to generate the proper control byte.
B0 = must be low B1 = must be low B2 = high = RS232 input will be inverted and open drain ( pull down ) low = RS232 input is true and full totem ( for interface buffer ) B3 = baud rate is divided by 2 or 8 depending on B4 B4 = baud rate is divided by 4 or 8 depending on B3 B5 = Input stream requires a match to address byte before input is stored B6 = Input stream requires a break and an address match before input stored B7 = high = A single short pulse causes the RSB509 to send all stored low = A single short pulse causes the RSB509 to send only one byte
After these two bytes are sent, the RSB509 will store incoming serial as specified. The RSB509 will not echo that data to the host until the host generates a short high pulse. This pulse should be greater than one half bit time but less than 10 bit times (for 9600 baud interface, > 52us and ; < 1040us.
rsb509_invert CON %00000100 'serial input is inverted rsb509_baud1 CON %00000000 'serial input baud MAX/1, 9600@4.0MHz rsb509_baud2 CON %00001000 'serial input baud MAX/2, 4800@4.0MHz rsb509_baud4 CON %00010000 'serial input baud MAX/4, 2400@4.0MHz rsb509_baud8 CON %00011000 'serial input baud MAX/8, 1200@4.0MHz rsb509_addr CON %00100000 'serial input requires an address byte match rsb509_brek CON %01000000 'serial input requires a break followed by address rsb509_cont CON %10000000 ' serial output is continuous until empty
Protean Logic Inc. Copyright 05/06/04 Top of Page