BS2 comm port settings
PVJohn
Posts: 60
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
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
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.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
·· 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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
PVJohn
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
· 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.
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 Williams
Applications Engineer, Parallax
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
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.
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 -->
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
Sincerely,
PVJohn