BS2 simple serial out works with any pin but not Pin1 - Sout

I need all digital pins P0-P15 for my project. I also need to send a data stream (one direction) to a PIC device. I am using the following basic code to send a test stream. The PIC expects True polarity not inverted:

' {$STAMP BS2}
' {$PBASIC 2.5}
' {$PORT COM12}

SEROUT 16, 396, ["Hello!", CR] ' send the greeting
PAUSE 100 ' wait 0.1 seconds
LOOP ' repeat forever

It doesn't work on Pin 1 however it works fine if I change SEROUT to any other pin.

Just to be sure I looked at the Pin output on my scope which has a UART logic decoder and its all gibberish regardless of settings I try. With the BS2 set for any pin 0-15, the code works perfectly and my scope easily decodes.

Would the line driver on Pin Sout be affecting this? The only wires I have from BS2 to PIC (or scope) are the Sout and Ground.

Any advice appreciated.

Jerry NY2KW


  • 4 Comments sorted by Date Added Votes
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 21,409
    edited February 4 Vote Up0Vote Down
    You realize that the RS232 driver on PIN 1 inverts the signal, right? Try 16780 instead of 396 to re-invert it.

    “Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. -Antoine de Saint-Exupery
  • Yes, thanks. I dont seem to be able to change the signal polarity. The signal pattern looks identical on my scope with either

    SEROUT 16, 396, [string]


    SEROUT 16, 16780, [string].

    My scope to decode does not automatically find the right polarity - i have to set it and I leave it unchanged with both 396 or 16780 and the signal burst is identical.

    Any suggestions?

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 21,409
    edited February 5 Vote Up0Vote Down
    Just checked, and you're right: the signal does not get inverted with 16780 like you might expect on P16. Soooo ... it looks like you'll have to add an external inverter.

    “Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. -Antoine de Saint-Exupery
  • The serout inverter on the BS2 is a single PNP prebiased transistor you can find on top of the BS2 module. You could tap/hack into the base of that transistor to find the non-inverted signal.

    Another peculiarity of the Stamp wiring is that the collector of that PNP transistor is connected both to pin 1 of the module, SOUT, and to a 4.7kohm resistor that goes to the SIN pin. The idea is that SOUT will "steal" negative or zero voltage from the SIN pin. If SIN is floating, there is still a path to ground via a pair of 10k resistors and the base of the NPN transistor that inverts the SIN signal. You can see the schematics in the appendix of the Stamp manual.
Sign In or Register to comment.