Shop OBEX P1 Docs P2 Docs Learn Events
Complicated Serin-Serout — Parallax Forums

Complicated Serin-Serout

alnajjar1alnajjar1 Posts: 110
edited 2011-08-17 16:51 in BASIC Stamp
Serial communication is the hardest thing on the BS2!

I am communicating with a lighting controller and everything works through Hyper Terminal . With HT, I send the following with carriage return:
chan int:128 c1 (set the intensity of channel c1 to 128 or 50%)
The controller then responds with
chan c1 int:128

using 16468 as equivalent to the setting in HT of 9600, no parity, 1 stop bit (8 data bits is mandatory) (I also tried 84 without any luck), I send the following from the BS2:

p_lightsTX PIN 15
p_lightsRX PIN 11
c_lightsBaud CON 16468 ' Baud set at 9600
inText VAR Word

SEROUT p_lightsTX, c_lightsBaud, ["chan int:0 KP 5",CR]
SERIN p_lightsRX, c_lightsBaud, [inText]
DEBUG HOME, inText

I get nothing but garbage in the debug window and the commands have no effect on the controller. The system obviously works from HT. How can I make it work from BS2?

Please help,

Al

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-08-16 17:51
    If your sending chan int:128 c1 from HT works, then how does it go sending that same thing from the Stamp?
    (I ask because you give the one example from/for HT and another, chan int:0 KP 5, for the Stamp.)

    So far as the confirmation / reply back to the Stamp, from the controller, inText and SERIN must be configured as an array (of bytes). You could probably shorten that up with a WAIT
  • alnajjar1alnajjar1 Posts: 110
    edited 2011-08-17 04:34
    My mistake, I only use (chan int:0 KP 5) the c1 for just illustration when I was writing the question. the KP 5 works with HT but not with the BS2.
  • stamptrolstamptrol Posts: 1,731
    edited 2011-08-17 04:59
    There are a couple of possibilities:
    1. Are you sure the lighting controller can work with serial voltage levels of 0 volts and 5 volts as generated by the Stamp pin? If the controller is expecting 'real' rs-232 voltage levels, you may have to add a level shifting chip. Or, use the programming port (pin 16). The baudrate number will go to 84. I'd get the SEROUT part working before worrying about the SERIN part.

    2. Because the Stamp has no communication buffer, your SERIN has to be executing when the data arrives. Usually you can use the 'WAIT' modifier to get the program to wait for a specified character before executing.
  • alnajjar1alnajjar1 Posts: 110
    edited 2011-08-17 05:09
    I am not sure about the voltage level requirement but I guess you are correct especially that I am using a 50' serial cable which is at the very limit of serial specs. I will shorten the cable and test to see if this works. I am also planning on using a serial signal booster from B&B electronics (http://www.bb-elec.com/product_family.asp?familyid=13) which is supposed to increase the range to 100'.

    what is the best way of adding a "level shifting chip"? is that something off the shelf on a separate circuit board that I can plug into or do I have to redo my circuitry?

    thanks,
    Al
  • stamptrolstamptrol Posts: 1,731
    edited 2011-08-17 09:35
    Fifty feet won't cause you any problem at the speeds you're using. I don't think you'll need the booster.

    Several level shifter chips are available. I like the MAX233 as no external capacitors are required, but the MAX232 and ST232 work fine as well.

    Cheers,
  • alnajjar1alnajjar1 Posts: 110
    edited 2011-08-17 16:11
    Great! I took your advise and eliminated the Serin commands and that seems to cure the problem! it was probably waiting for a reply and freezing the process. The serout portion works great. It turns out that I need to double the cable length to 100' and not 50' as I mentioned earlier. What is the absolute length of cable RS232 the stamp can handle? I am putting in the booster just in case...

    many thanks again,
    Al
  • stamptrolstamptrol Posts: 1,731
    edited 2011-08-17 16:51
    There are no absolutes with rs-232! Driving from a Stamp, you don't have much margin because you're only going from 0 to 5 volts; I'd guess you'd be OK at 100' unless cable capacitance is high. Make sure the booster can accept ttl levels from the Stamp.

    It will depend on the type of cable (twisted, coax, parallel ,shielded or not) and the speed. I've run 300 feet at 9600 to drive a remote display at standard +/- 12 volt rs232 levels.

    Cheers,
Sign In or Register to comment.