PDA

View Full Version : Asynchronous RS-232 Help Question



CarSta
05-28-2005, 12:22 AM
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.· http://forums.parallax.com/images/smilies/confused.gif
Here is an example:

'SEROUT Tpin {\Fpin}, Baudmode, {Pace,} {Timeout, Tlabel,} [OutputData]
cmdlen = 10
SEROUT 0, baud, 10,["v"]
SERIN 1, baud, Bad_Data, 1500, No_Data, [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. http://forums.parallax.com/images/smilies/tongue.gif
Sincerely,

Carey (CarSta)


·

allanlane5
05-28-2005, 12:36 AM
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 Williams
05-28-2005, 12:39 AM
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

CarSta
05-28-2005, 12:39 AM
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 Savage
05-28-2005, 01:05 AM
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 (mailto:csavage@parallax.com)

Jon Williams
05-28-2005, 01:08 AM
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

CarSta
05-28-2005, 02:19 AM
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 B
05-28-2005, 02:39 AM
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 Leuenberger
05-28-2005, 03:03 AM
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_b
05-28-2005, 03:39 AM
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."

Nate
05-28-2005, 05:18 AM
"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