Shop OBEX P1 Docs P2 Docs Learn Events
Serin at 19200baud — Parallax Forums

Serin at 19200baud

CMcGCMcG Posts: 17
edited 2007-12-14 10:12 in BASIC Stamp
Hello,

I am trying to·extract·a few data values from an RS232 string of about 50 ASCII characters. The string is sent into my stamp every 10 seconds, but the baud rate·being fixed at 19200bps., is just too fast for the BS2IC it seems. I have also tried a BSCpx24 but that too is foxed by the 19200 speed.

The 19200baud is fixed. Has anyone any idea of how an external serial buffer might be used to capture the data and for the stamp to then read the buffer at say 1200baud?

Thank you for any suggestions.
Carl

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-12-05 14:34
    You may have to use either an SX or a Propeller processor either of which could handle the speeds involved. You could either just write the data extraction portion on the other processor and still use the Stamp or move your whole application to the other processor.

    The external buffers I know of either can't work at 19.2KBps or don't provide a host speed that's lower than the input speed.
  • CMcGCMcG Posts: 17
    edited 2007-12-05 14:59
    Hello Mike,

    Thanks for taking the time to respond to my question.
    I did buy a BS2PX24-IC but that just could not handle the data reliably.

    If for example, I asked for a capture of (STR datain\20) only aout 90% of the displayed characters were valid, with gibbereish being displayed alongside good characters.

    I have spotted a previous post of yours advocating the RSB6505 chip, but from what you are saying, I guess it does not have the baud rate conversion facility that I am after?

    Not sure if mentioning it will get me struck off, but I am looking at trying a Basic atom which I see is advertised as having a UART on-board.

    All the best
    Carl
  • Mike GreenMike Green Posts: 23,101
    edited 2007-12-05 15:54
    Carl,
    The RSB6505 is the one that, from its datasheet, ought to work, but isn't for sale yet according to Protean Logic's website.

    If you're going to move to some other processor, I would seriously suggest you look at either using SX/B (SX Basic) on an SX
    or use Spin for programming on a Propeller. Both use software UARTs that work "in the background" so characters won't be
    dropped.
  • CMcGCMcG Posts: 17
    edited 2007-12-05 16:16
    Thank you Mike. I will do some background reading on SX Basic and the new Propellor modules.
  • CMcGCMcG Posts: 17
    edited 2007-12-05 16:26
    Mike,
    Can I just clarify. Do you think that a BS2sx might work for me at 19200baud? I see that it has a 50MHz crystal and can execute ~10000 instructions per second.

    I bought the BSCpx24 because I read it could achieve ~19000 instructions per second. It has a 32MHz crystal on-board. This BSCpx24 did not work well enough for me.

    Cheers
    Carl
  • Mike GreenMike Green Posts: 23,101
    edited 2007-12-05 16:31
    All of the Stamps have the same basic problem for your type of application. They are single threaded. They can do only one thing at a time. If they're processing information, they're not looking at the serial input line. For many applications and at lower speeds, this may not be a problem, but at 19.2KBps, any Stamp will probably drop characters where there's no flow control.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-12-05 17:09
    Carl-

    There may be another alternative such that you may still be able to use a PBASIC Stamp. Maxim makes the MAX3100 (MAX31xx series) external UARTS designed for use with microprocessors.

    On the input/output side to and from the Stamp the SHIFTIN/SHIFTOUT commands (synchronous serial) are used in lieu of SERIN/SEROUT. They also have an 8 byte buffer if I remember correctly.

    There is application information available for use of the MAX31xx series with the Stamp, if you need it.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-12-05 17:22
    Carl,

    With your BS2p24 have you tried using the SPSTR modifier to store the incoming data into the Scratch Pad RAM? I would recommend trying that instead of STR.
    SERIN  Pin, Baud, [noparse][[/noparse]SPSTR 50]
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • CMcGCMcG Posts: 17
    edited 2007-12-05 19:24
    Thank you Mike and thank you Chris. I did not know about the SPSTR modifier. I will definitely give that a go and report back in a day or two when I am next at my bench.

    Regards

    Carl
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-12-06 16:07
    Carl,

    Not only should the SPSTR modifier be a little more efficient, but it will provide you with 126 bytes of space instead of the <26 you had available before. In your example you were capturing 20 bytes, but I can’t help but wonder if any of those bytes were being over-written by other variables. You only have 26 bytes of variable space, so if you were using more than 6 bytes for general system variables you may very well have been over-writing some data. Let us know. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • CMcGCMcG Posts: 17
    edited 2007-12-09 12:36
    Hello Chris,
    I have tried the SPSTR modifier with my BS2p24 and all I can say is WOW!!!!
    I cannot believe how well it works. I can happily read in serial strings even at 115200baud. I never thought this possible with stamps.

    Thank you very much for your very useful advice.

    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}
    Datain Pin 1
    i VAR Byte
    serdata VAR Byte

    Start:
    'SERIN datain,16494,[noparse][[/noparse]SPSTR 52 ] '19200
    'SERIN datain,16429,[noparse][[/noparse]SPSTR 52 ] '38400
    'SERIN datain,16407,[noparse][[/noparse]SPSTR 52 ] '57600
    SERIN datain,16385,[noparse][[/noparse]SPSTR 52 ] '152000

    FOR i = 0 TO 51
    GET i,serdata
    DEBUG serdata
    NEXT
    DEBUG CR
    GOTO start:

    This is the my test string and the stamp reads it 100% at all baud rates.
    "The quick brown fox jumps over the lazy dog 0123456789"

    Best wishes
    Carl
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-12-10 19:55
    Carl,

    I’m glad you got it working…Besides faster speed you gain the ability to buffer larger incoming strings. For me this helps with such devices as GPS, Vinculum (Datalogger) and the PINK Module...all devices which can return large strings to have to deal with. When translating data between serial devices it not only cuts down on variable space but allows you to use a single byte variable for translation/transfer. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • CMcGCMcG Posts: 17
    edited 2007-12-12 20:07
    Hello Chris,

    A·further·question about the SPSTR modifier...

    I would love to be able to read in a long string, but be able to handle different string lengths. The strings all end with a $0D (carriage return).

    I am looking for something like SERIN,pin,baudrate,·[noparse][[/noparse]SPSTR 127 \CR]· that would read in up to 127 bytes OR until a CR is seen.

    The \CR modifier does not work. Is there any other way to handle variable length strings with SPSTR?

    Cheers

    Carl
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-12-12 22:10
    Carl,

    The only thing I can suggest in this case is to specify the maximum number of bytes you’re expecting and then use the timeout feature to break input. This is how the code for the PINK Module is written. When a variable is read it reads in up to 64 characters unless it times out. Very small values shouldn’t be noticeable but don’t get too small or you may timeout before getting a response. I don’t know if this will work in your situation. It works on the PINK because you send a command and expect return data immediately. I hope this helps. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • CMcGCMcG Posts: 17
    edited 2007-12-12 22:24
    Hi Chris,

    Sorry, I have no idea what a PINK module is. Is there a link to some info that you could send me?

    I thought of using a timeout as you suggest. I am just afraid that I might miss some of the first bytes of an incoming string, if the stamp just happens to be diverted off to a timeout branch at the instant that the string starts. Anyhow, I will continue to experiment.

    Thanks for all your help.
    Carl
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-12-13 15:43
    Hi Carl, a WAIT instruction combined with a timeout may work for you, it works at 9600 I have never tried at anything higher.

    SERIN RX,baud,[noparse][[/noparse]WAIT("!")]
    SERIN RX,baud,200,time_out,[noparse][[/noparse]SPSTR 127]

    in the GET loop I look for a CR to exit the loop (end of string)

    IF serdata=13 THEN EXIT

    Jeff T.
  • CMcGCMcG Posts: 17
    edited 2007-12-13 17:09
    Thanks for the message Jeff.

    I was thinking along those lines but had not thought of using two instructions like you suggest. Like it!

    My mind was stuck with trying to do it all with a single SERIN with WAITs and timeouts.

    I have a ";" semi colon that I can trigger on, i.e. WAIT for.



    SERIN pin,baudrate,[noparse][[/noparse]WAIT ";"]

    SERIN pin,baudrate,200,processdata,[noparse][[/noparse]SPSTR 127]

    processdata:·

    ' loop using GET until CR is found



    Thanks for the idea. I am confidentthat it will work.

    Aren't these Stamps amazing? There always seems to be a way to achieve what you need to.

    Rgds

    Carl
  • CMcGCMcG Posts: 17
    edited 2007-12-14 10:12
    Hello again Jeff,
    Unfotunately 19200 is just too fast for the two SERIN commands.
    I have however come up with a suitable solution using a timeout that I am happy with.
    Thanks for your help.
    Happy Christmas
    Carl
Sign In or Register to comment.