BS2 to BS2 communication using RS232
RoHerman00
Posts: 22
I have a question with the serin and serout commands. Everyone who does a tutorial on serial communication between a computer or another BS2 always uses pins 0-15 to communicate. For example "serout 15, 9600, [DEC 8832]" or something like that. I know that you use serin/serout 16, 9600 etc. when communicated with your computer because those use RS232 voltages rather than TTL. Could I use those pins (physical pins 1 and 2) to communicate with another Basic Stamp? So rather than using Serout 16, 9600, [DEC 8832] for the debug terminal on a computer I use that same command and same pins but connected to pins 1 and 2 of another basic stamp? Also, should this work could I write something like Serout 16\16, 9600, [DEC 8832] and use one of the pins as flow control?
Thanks a lot
Thanks a lot
Comments
I believe you'll need a pulldown resistor on the receive line on both Stamps. I don't have my Stamp Manual handy (to be able to look at the Stamp schematic), but I think that the transmit line uses this as a source of negative voltage when the line is idle. A pulldown resistor to Vss might work, but a source of -5V would be more like the use of a real RS232 line.
Whatever is sent to a Stamp's RS232 port is echoed back by the RS232 interface hardware. You'd have to account for this in your programming.
The flow control is not really needed I was just wondering if it was possible. Just to be sure I understand what you mean (I have to look at the wiring for serial pins) I could connect for example physical pins 1 on both stamps and have one stamp use only serin 16 commands and the other serout 16 and it might work using the points you made with connecting them?
For Stamp to Stamp communication, look in the Help file of the programming software under SERIN or SEROUT. Note that you can't use p16 in Stamp to Stamp without a negative voltage source. It will only cause tears and frustration when learning the basics. Thats why most examples are p0 - p15.
For Stamp to PC, use the programming port ( that is, pin16) and the DEBUG command in the STamp. The negative voltage is supplied by the PC's serial port.
Cheers,
Yes, you can connect SIN of one Stamp to SOUT of the other Stamp (and vice versa). This may not work reliably if the Stamps are far apart (more than a foot or two) or if there's a lot of electrical noise nearby (like motors or other high current devices switched on and off), but it should work otherwise. It would work better with a source of negative voltage as stamptrol mentioned.
Remember that one Stamp has to be "listening" to the other Stamp (by executing a SERIN) when the other Stamp sends its data with SEROUT. There's no buffering.
The db-9 connector is meant for connection to the PC or some other RS-232 device. Again, you will not be terribly successful in using the db-9 connection from Stamp to Stamp. The usual minimum connection between devices using a 9-pin connector is pin 2, pin 3 and pin 5. That is, Rx, Tx and Gnd.
The recommendation to start by communicating with the normal outputs ( p0 - p15) allows serial communication to take place with TTL voltage levels of 0 and 5 volts.
You will need 2 rs232 level shifting chips (MAX232 or MAX 233 or equiv.) Some have two sets of channels so one chip might suffice depending on how far apart the two Stamps are.
The level shifter gets connected to each Stamp's db-9 connector and provides the negative voltage thats been mentioned. Then, the TTL levels of the chips are connected forming the link between the Stamps. Obviously, Tx on one Stamp gets connected to RX on the other and vice versa. This will still not give you hand-shaking nor buffering so its best at speeds of 4800 and lower.
Cheers,
I don't know if you guys are talking about the actual physical pin, or the pin number as referenced in PBASIC.
When I look at Figure 1.4 in the PBASIC Syntax & Reference manual v2.2, it shows that physical pin 16 is for I/O P11 and there is no P16 shown.
From what I've read, pins 1 SOUT & 2 SIN are the dedicated RS-232 level pins.
Where am I going wrong here?
In the future, please start your own thread for any question not directly related to the subject of a thread. If you just add to an existing thread, you may not get a quick answer and it's confusing to others who may be looking for an answer to the same or similar question.
The programming port is separate from the above ports but apart from programming it can also be used for PC communication. In the PBasic language this port is called P16.
In the case of a DB9 serial connection the higher voltages from the PC's serial port are routed to a "line driver" on the Stamps circuit board, the line driver reduces these higher voltages from the PC to a safe level for the Stamp. Not only is the voltage level reduced but the signal is inverted, that is one of the reasons the manual lists baud values for True or Inverted.
One other thing to be aware of when using P16, characters transmitted from the PC to Stamp using P16 will be echoed back to the PC. This will give you some unexpected results if you don't make provision for it.
Jeff T.