Shop OBEX P1 Docs P2 Docs Learn Events
Serial In buadrate properties — Parallax Forums

Serial In buadrate properties

TimNTimN Posts: 32
edited 2007-02-17 18:47 in BASIC Stamp
When i use a baudrate of 188 in PBASIC coding for the SERIN command, i am able to seperate a serial string into individual variables of set digit lengths using the DEC formatter. for example, to seperate 10 digits of serial data into smaller variables, i would use the code SERIN 0, 188, [noparse][[/noparse]DEC1 var1, DEC1 var2, DEC2 var3, DEC1 var4, DEC2 var5, DEC3 var6]. this working fine when i am using 4800 baud. but when i try to do the same with 9600 baud with the PBASIC code of 84, instead of var1 getting digit 1, var2 getting digit 2, var3 getting digits 3 and 4, etc... (which is what i want to happen), var1 gets digit 1, var2 gets digit 1, var3 gets digits 1 and 2, var4 gets digit 1, var5 gets digits 1 and 2, and var6 gets digits 1, 2, and 3. any ideas of why this happens only at 9600 baud and any ideas on how to fix it so that the results i want that happen at 4800 also happen at 9600? i ask because i have a device that send data out via serial line to the basic stamp, but it's minimum baud rate is 9600.

thanks for the advice

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-16 20:33
    The problem is that it takes a little time to set up the next input formatter and, at 9600 Baud, it may take just long enough so the input formatter misses the next character. You could read the 10 characters as a string into a 10 byte array, then do the conversion to binary yourself like:
    serin 0, 84, [noparse][[/noparse]str char\10]
    char[noparse][[/noparse] 0] = char[noparse][[/noparse] 0] - 48   ' subtracts the code for "0"
    char[noparse][[/noparse] 1] = char[noparse][[/noparse] 1] - 48
    char[noparse][[/noparse] 2] = (char[noparse][[/noparse] 2] - 48) * 10 + (char[noparse][[/noparse] 3] - 48)
    char[noparse][[/noparse] 3] = char[noparse][[/noparse] 4] - 48
    char[noparse][[/noparse] 4] = (char[noparse][[/noparse] 5] - 48) * 10 + (char[noparse][[/noparse] 6] - 48)
    char[noparse][[/noparse] 5] = (char[noparse][[/noparse] 7] - 48) * 100 + (char[noparse][[/noparse] 8] - 48) * 10 + (char[noparse][[/noparse] 9] - 48)
    
    
  • TimNTimN Posts: 32
    edited 2007-02-17 03:31
    how do you convert from character strings to binary or decimal format?
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-02-17 03:33
    Q: How do you convert from character strings to binary or decimal format?
    A: SERIN pin,baud,[noparse][[/noparse]DEC variable]

    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    StampPlot - GUI and Plotting, and XBee Wireless Adapters
    Southern Illinois University Carbondale, Electronic Systems Technologies
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-17 03:43
    Tim,
    The code fragment I posted does the conversion. I wrote it specifically for the format you showed for the 10 characters (1,1,2,1,2,3). Go through it step by step on a piece of paper and you'll see.
    Mike
  • TimNTimN Posts: 32
    edited 2007-02-17 04:59
    i tried copying and pasting that code in, but PBASIC syntax checker said that where the open bracket was in the "char[noparse][[/noparse] " line is, it should be an "=" instead of a "[noparse][[/noparse]" any ideas why this happens?
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-17 05:16
    My mistake. I'm sorry. Use regular parentheses instead of the square brackets. I'm going back and forth among 3 programming languages and PBasic uses parentheses for subscripts while Pascal and Spin use square brackets. It gets a little confusing.
  • TimNTimN Posts: 32
    edited 2007-02-17 05:45
    Actually, nevermind that... i was able to figure out how to get it to work, thank you very much for your help!!
  • TechnoRobboTechnoRobbo Posts: 323
    edited 2007-02-17 18:47
    If your device permits you increase the number of stop bits - that's what they're for. The part that's confusing me is how you got a device that's 9600 baud (minimum) to work at 4800?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Have Fun


    TR

    Post Edited (TechnoRobbo) : 2/17/2007 6:51:43 PM GMT
Sign In or Register to comment.