Shop OBEX P1 Docs P2 Docs Learn Events
Asynchronous RS-232 Help Question — Parallax Forums

Asynchronous RS-232 Help Question

CarStaCarSta Posts: 16
edited 2005-05-27 21:18 in BASIC Stamp
Hi All,

I am using a BS2p24 to send and receive RS-232 signals to a scientific device.· The device echos the
commands back.· I use a serout at 9600 baud inverted, no parity, 8 bits, 1 stop and expect to receive
the same.· The problem is when I send the command, the echo is returned before I am in the serin routine
which is the next line of code.· I am getting some of the echo plus the data sometimes and other times
I appear to be bit shifted across the entire transmission and the data appears garbled.· confused.gif
Here is an example:

'SEROUT Tpin {\Fpin}, Baudmode, {Pace,} {Timeout, Tlabel,} [noparse][[/noparse]OutputData]
cmdlen = 10
SEROUT 0, baud, 10,[noparse][[/noparse]"v"]
SERIN 1, baud, Bad_Data, 1500, No_Data, [noparse][[/noparse]STR serstr\cmdlen]
Sometimes I end up in the No_Data (Timeout) routine and sometimes I get part of the
response.

I am sure I am not the first to run into this.· How have you solved this problem.· Is a UART the answer?? Many thanks for your kind assistance. tongue.gif
Sincerely,

Carey (CarSta)


·

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2005-05-27 16:36
    The usual solution to this is to have the 'answering' device wait for a millisecond or two before sending back its response. Another alternative is to use the 'hand-shake' lines on your SERIN -- this will send out to the 'answering' device an enabling signal, which only goes active (high?) when the BS2 is ready for data.

    There does exist a small, 8-pin device (the sMT, I think it's called) which implements a recieve-only UART. This UART can run independently of your BS2, so it will get the return message and hold it until your BS2 has time to get it from the sMT.

    You're right, this is an on-going issue for any BS2 design.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-27 16:39
    The key is to know when a *real* response is coming. As Allan suggested, you could delay your SERIN a bit to let the echoed characters get transmitted without being received by SERIN. Or, if the the *real* response has an known header, you could use the WAIT modifier to ignore echoed characters until the header arrives.

    I don't think an external UART will solve this problem -- you'll have to flush the unwanted data out of it as well.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • CarStaCarSta Posts: 16
    edited 2005-05-27 16:39
    Additional Information:

    The scientific device does NOT support handshaking, either hardware or software, and

    responds at a time of its choosing.· I do not have the ability to cause it to delay responding.

    I would love more information on the sMT chip or whatever if that will cure the problem.



    Again thanks for your assistance,



    Carey (CarSta)
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-27 17:05
    Carey,

    ·· What data does the device return?· Does it preceed it's data with a known header or byte?· If so, Jon has given you a possible way to do this.· Let us know what type of data the device sends back.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-27 17:08
    Carey,

    While you can't delay the device's response, you can delay when you start listening for it by inserting a PAUSE before your SERIN. To do this, though, you'll need to be sure that the timing is consistent.

    Some users have employed the MAX3110 UART in projects. Here's one: http://devices.sapp.org/micro/stamp2sx/max3110/

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • CarStaCarSta Posts: 16
    edited 2005-05-27 18:19
    Hi Chris,

    ·Q>· What data does the device return?· Does it preceed it's data with a known header or byte?· If so, Jon has given you a possible way to do this.· Let us know what type of data the device sends back.

    The data does not have a consistent header or byte.· It responds differently to the command sent to it.· It is a ultraviolet spectrometer and is sending 2048 bytes of 12-bit resolution data (0-4094) in full scan mode.· If I ask it for something simple, such as the integration time, it only responds with a single word (which I miss) or in some cases just a single byte (which I almost never get).· If it doesn't understand the command or I have a syntax error in the command (hopefully all weeded out by now) it only returns a NAK (ascii 21) which again I miss as well.


    Hi Jon,

    Q> While you can't delay the device's response, you can delay when you start listening for it by inserting a PAUSE before your SERIN. To do this, though, you'll need to be sure that the timing is consistent.

    Some users have employed the MAX3110 UART in projects. Here's one: http://devices.sapp.org/micro/stamp2sx/max3110/


    I have tried using the pause before a serin just after the serout, but that seems to make matters worse in that then I always get a no_data timeout error and I receive nothing back.· I assume since I wasn't reading the port the data has just been dumped into the big bit bucket in the sky.

    I will definitely look into the MAX3110 UART and goto the reference you gave.

    Thanks again guys for all your help.

    If you have any other ideas please leave a message.

    Sincerely,

    Carey (CarSta)
  • David BDavid B Posts: 591
    edited 2005-05-27 18:39
    This is just like a project I worked on in the late 1980's, except that my spectrometer measured visible light. Once it was triggered, it just spat out a couple of K of RS232 data with no handshaking whatsoever.

    I solved the problem by buying a standard "printer buffer" from the Black Box company, as I remember, and it worked perfectly. The buffer absorbed the burst of RS232 from the spectrometer and fed it back to my PC with handshaking.
  • Don LeuenbergerDon Leuenberger Posts: 9
    edited 2005-05-27 19:03
    Another possibility is to use a MAX232 along with an RSB509C http://www.proteanlogic.com/product_periph_rs232.shtml. The RSB509C will buffer up to 32 bytes of data and is very straightforward to use with the stamp. The Protean Logic web site has sample code and schematics for its use.

    Don Leuenberger
  • steve_bsteve_b Posts: 1,563
    edited 2005-05-27 19:39
    anyway to just slow down the data stream? Will the spectrometer output 1200 or 2400 baud?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve
    http://ca.geocities.com/steve.brady@rogers.com/index.html
    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
  • NateNate Posts: 154
    edited 2005-05-27 21:18
    "Thanks again guys for all your help.

    If you have any other ideas please leave a message"

    Use·the SX microcontroller - it can handle this task with minimal effort.



    Nate
Sign In or Register to comment.