Shop OBEX P1 Docs P2 Docs Learn Events
BS2 comm port settings — Parallax Forums

BS2 comm port settings

PVJohnPVJohn Posts: 60
edited 2006-02-13 17:10 in BASIC Stamp
Hi, I need to detect comm settings of the unit that I want to connect to, and it can have
3·different parity settings. I followed the instructions from the manual to calculate values for EVEN parity, but I couldn't find information about ODD parity settings for BS2. I have a code to detect and communicate·with NO parity settinings, but it took a lot of RAM. I'm sure that it can be "looped", but I don't know how to do it with arrays. When·the correct settings are detected I need to save that value (for ex. "T19K2")·in variable. It would be appriciated if somebody can help.

PVJohn

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2006-02-06 15:03
    Unfortunately, the BS2 only implements two settings.

    1. 8N1 -- 8-databits, No Parity, One stop bit

    2. 7E1 -- 7-databits, Even parity, One stop bit.

    No other RS-232 settings are supported in the 'native' BS2. So this would be a very poor platform for doing what you want.

    Now, the SX-28 (and -48, and -54) would be pretty good for this purpose, but you'll have to program them in assembly. The SX/Basic language provided by Parallax can give you a start, as it generates assembly code from Basic.

    Perhaps the Javelin also has a more flexible UART settings? I'm not so sure of that one.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-02-06 15:08
    Can an SX-28 do 1200 8-E-2?·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-06 15:22
    One could certainly write a custom subroutine to do that.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-02-06 15:34
    Is·the "SX Tech Tool Kit LITE" provision enough for the task (i.e. 1200 8-E-2)?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-02-06 16:15
    PJ,

    ·· Yes it is enough if you're communicating at TTL levels.· If you're trying to talk to an RS-232 level device you would need to add a driver chip such as a MAX232 to your kit.· Other than that you should be set.· Al William's book does a great job explaining serial communication on the SX.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-02-06 18:40
    Jon wrote that I'd have to write·a custom sub-routine.· I was looking around at the SX/B Docs and all, but I didn't see details about Baudmode values for SERIN/OUT on SX/B (I really didn't want to D/L & install the Help files.)· Is 1200 8-E-1 a supported Baudmode for SX/B?
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-06 19:15
    No, the built-in routines are 8N1 for any baud the FREQ directive will support. As has been pointed out, SX/B reveals the compiled code (annotated with your original source) so one could use that as a starting point for a custom routine.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-02-06 20:34
    PJ Allen said...
    Jon wrote that I'd have to write·a custom sub-routine.· I was looking around at the SX/B Docs and all, but I didn't see details about Baudmode values for SERIN/OUT on SX/B (I really didn't want to D/L & install the Help files.)· Is 1200 8-E-1 a supported Baudmode for SX/B?
    The reason there are no baud mode values is as was said, they are not supported by SX/B, however if you looked into the Al Williams book I mentioned you'll see you can easily implement in assmbly any format you want.· He even shows an example of talking to three serial ports at different speeds/formats.· So yes, you will have to customize the code.· You could always use SX/B to generate code for a standard baud mode and tweak it to your needs.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-06 21:20
    Here's an example of what Chris is suggesting -- I looked at the code generated by SX/B's SEROUT and SERIN instructions and duplicated it in high-level code (this is 8N1), and I verified that it works by connecting to a terminal program.· You could start with this and customize to your liking.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • PVJohnPVJohn Posts: 60
    edited 2006-02-07 00:18
    Can anyone help me with my code? Thanks.
    PVJohn
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-02-07 00:42
    Thanks Jon, that is what I getting at.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-02-07 01:51
    PVJohn,

    · Have you considered writing the Baudmode CONstants to EEPROM as DATA?· Then you could run/loop through it all·using a FOR...NEXT or ON...GOTO/GOSUB fashion by READing the Baudmode DATA.· When you hit the right one then you could WRITE that to a specific address.
  • PVJohnPVJohn Posts: 60
    edited 2006-02-08 03:49
    PJ Allen, I would like to try that, but I don't know how. Do you have any code to share?

    Thanks, PVJohn

    I should be something like this, but I don't know how.



    '{$STAMP BS2px}
    '{$PBASIC 2.5}

    replayfromPT······ VAR··· Byte(16)

    PTbaud··· VAR· Byte
    BS2baud·· VAR· Word

    'PT baud rates
    'N12 (1200), N24 (2400), N48 (4800), N96 (9600), N14 (14K4), N19 (19K2), N28 (28K8)
    PTbaudrates· DATA··· 12,24,48,96,14,18,28

    BS2baudratesN DATA··· 3313, 1646,813,396,258,188,119

    FindComSettings:

    FOR· BS2baud = 0 TO 6······ '3313, 1646,813,396,258,188,119
    ···· FOR· PTbaud = 0 TO 6·· '12,24,48,96,14,18,28
    ········· 'Now I need to read from· PTbaudrates to get first "PTbaud" parameter
    ········· SEROUT 1, BS2baud,[noparse][[/noparse]"*PTBR=N",PTbaud,13]· 'try first "PTbaud" parameter
    ········· SERIN 2, BS2baud,2500,TryNext, [noparse][[/noparse]WAIT("#"), STR replayfromPT\16 ]
    ···· NEXT

    NEXT


    TryNext:
    'Try next "PTbaud" settings from EEPROM
    'GOTO FindComSettings

    Now what?
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-08 06:35
    You cannot index from EE table as you're doing -- you actually need to use the READ instruction. You'll also need to use the Word modifier with both the DATA statement and with the READ instruction, because the default mode for both is byte-oriented.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • PVJohnPVJohn Posts: 60
    edited 2006-02-08 12:06
    That's where my trouble is. I don't know how to·READ parameters from "PTbaudrates" and "BS2baudratesN".···· I was looking at example from "help" about DATA, but I couldn't understand how to pull the 2nd, 3rd... parameter from locations 1, 2, 3...· It's easy to read the 1st parameter, (from location 0), but the others... Do I have to do this:

    PTbaud1 VAR Byte
    PTbaud2 VAR Byte
    ....
    PTbaud7 VAR Byte

    ·then..
    PTbaud1··· DATA·· 12
    PTbaud2··· DATA·· 24
    PTbaud3··· DATA·· 48
    PTbaud4··· DATA·· 96
    PTbaud5··· DATA·· 14
    PTbaud6··· DATA·· 19
    PTbaud7··· DATA·· 28

    or, I can do something like this: PTbaudrates· DATA··· 12,24,48,96,14,18,28.
    My question is: How can I·READ a value "96" from location·3 ?
    Thanks,
    PVJohn
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-02-08 12:55

    PVJohn saith...
    My question is: How can I·READ a value "96" from location·3 ?
    baudrate var byte
    DATA··· 12,24,48,96,14,18,28
    READ 3, baudrate

    Give DATA, READ, WRITE in PBASIC Help a read-over.· These commands are straight-forward.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-02-08 15:27
    PVJohn -

    I suspect I see what you're missing now, which isn't innately obvious I suppose. READ and DATA work hand-in-hand or DATA and READ work hand-in-hand which is probably a better way of expressing it.

    The DATA statement (in its most simplistic form) permits·the programmer·to store what amounts to be user constants in EEPROM. Each element of the DATA statement (element 1 through element n) represents one item in this internal EEPROM data array.

    /code

    Element Number· 1······2···· 3

    Element Address· 0·····1······2

    ············ DATA··· "A",··"B",·· "C"···················'has three elements

    Element Number······ 1···········2············· 3

    Element Address····· ·0·········· 2············· 4

    ··········· DATA·· WORD 1,·WORD 123,··WORD 32767· 'also has three elements

    code/

    In the second case,·each of the elements is "wider" than those in the·first ·example. In the first case they are one byte (BYTE type by default) or 8 bits wide. In the second case they are two bytes (WORD type specified) or 16 bits wide.

    To fetch each of the three elements of the first DATA statement, one by one, you need to·issue three successive READ commands:

    One VAR BYTE

    Two VAR BYTE

    Three VAR BYTE

    READ 0, One

    READ 1, Two

    READ 2. Three

    After the executions of the·READ statements, the listed variables have the following values assigned to them:

    One = 1
    Two = 2
    Three = 3

    To fetch each of the three elements of the·second DATA statement, one by one, you need to·issue three successive READ commands also:

    W_One·· VAR WORD
    W_Two·· VAR WORD
    W_Three VAR WORD

    READ 0, WORD W_One

    READ 2, WORD W_Two

    READ 4. WORD W_Three

    After the executions of those·READ statements, the listed variables have the following values assigned to them:

    W_One = 1
    W_Two = 2
    W_Three = 3

    Since BAUDMODEs may exceed 255 in value, and BAUDMODE must be a WORD sized field, the second examples above are more appropriate to your present application. Each of the BAUDMODEs with which you're concerned could be an element in a DATA statement. There are also other methods.

    I hope that gets you started.

    Regards,

    Bruce Bates



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-08 16:17
    If you're going to use BASIC Stamp baudmode values, I would do this:

    BaudTable······ DATA··· Word T1200, Word T2400, Word T4800
    ··············· DATA··· Word T9600, Word T19K2, Word T38K4

    The table values are defined in the template I use.· To read from the table, you would do it like this:

    · READ BaudTable + (idx * 2), Word baudMode

    Then the variable baudMode could be used in your SERIN and SEROUT statements·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • PVJohnPVJohn Posts: 60
    edited 2006-02-11 07:11
    Thanks you all for your help. I got this problem solved, but here's a "new" one. I remember seeing the answer to this (or very similar) question, but I can't find it again. I know that there's no 100 % reliable way to scan two serial inputs at the same time, but can you suggest something from your experience that will work good enough? I want to scan one port for incoming data from my pressure transducer and keybord input through PAK VI a. Thanks again for your help.

    Sincerely,
    PVJohn
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-02-13 17:10
    Start a new thread. New topic, new thread. Otherwise, people are going to ignore this.
Sign In or Register to comment.