Shop OBEX P1 Docs P2 Docs Learn Events
Serial communication — Parallax Forums

Serial communication

RoomsterRoomster Posts: 2
edited 2007-11-07 15:40 in General Discussion
I want to use a BS2(p) to activate a pager system used for a emergency system by means of serial communication

Can anyone tell me wich baudmode to use for· 9600 8O(dd)1 ?

·

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-09-21 21:36
    What's 8O(dd)1 stand for?
  • FranklinFranklin Posts: 4,747
    edited 2007-09-21 21:41
    8 Odd 1 - but can you have 8 data bits with parity?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2007-09-21 21:56
    There is no 8-O-1 baudmode.· There isn't a 7-O-1 baudmode, either.

    With STAMPs, Parity is only possible with 7-bit, and then it's Even Parity only. (Odd Parity not supported.)

    Update -- I wrote an SX/B program to transmit 8-bit Even Parity.· To modity it for Odd parity transmission would be a snap.

    Post Edited (PJ Allen) : 9/21/2007 10:06:41 PM GMT
  • RoomsterRoomster Posts: 2
    edited 2007-09-22 22:25
    Thats·not so nice.

    Thanks for your reactions

    Jan

    From the Netherlands
  • Mike GreenMike Green Posts: 23,101
    edited 2007-09-22 23:31
    It's very rarely that anyone uses 8 data bits and a parity bit. What you're needing is probably 7 data bits and an odd parity bit in an 8 bit character frame. The built-in modes of the Stamps only handle 8 bits of data without parity and 7 bits of data with even parity. You can use 7 bits of data with odd parity, but you have to compute the odd parity yourself and transmit the whole thing as an 8 bit (no parity) character. It's not hard at all ... you can build a 128 byte table in the beginning of the EEPROM using the DATA statement to translate characters without parity into characters with odd parity. It will slow down things a bit, but it is doable.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-09-23 00:20
    If you can stand the lower speed and if the receiver uses only the seven least significant bits of each byte, you can send eight bits with odd parity by sending seven bits with even parity and setting the pace argument to one. The additional 1mS between characters adds a bunch of stop bits, effectively inserting a ninth "one" bit from the receiver's standpoint, converting the even parity to odd. This depends a lot on whether your receiver ignores the high-order bit of the byte (i.e. treats both $C1 and $41 as an ASCII "A").

    -Phil
  • TumbleweedTumbleweed Posts: 45
    edited 2007-11-06 17:22
    It's very rarely that anyone uses 8 data bits and a parity bit. What you're needing is probably 7 data bits and an odd parity bit in an 8 bit character frame. The built-in modes of the Stamps only handle 8 bits of data without parity and 7 bits of data with even parity. You can use 7 bits of data with odd parity, but you have to compute the odd parity yourself and transmit the whole thing as an 8 bit (no parity) character. It's not hard at all ... you can build a 128 byte table in the beginning of the EEPROM using the DATA statement to translate characters without parity into characters with odd parity. It will slow down things a bit, but it is doable. said...


    Hi Mike,
    I have a similar application using 7-O-1. I'm still learning how to use serial communications and am having trouble.
    Can you give me an example? For instance, if I need to send "aXR<CR>" to a device manually, what would it look like?

    Thanks,
    Lance
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-06 17:41
    An odd parity table might look like the following:
    oddParity  DATA  $80,$01,$02,$83,$04,$85,$86,$07,$08,$89,$8A,$0B,$8C,$0D,$0E,$8F
               DATA  $10,$91,$92,$13,$94,$15,$16,$97,$98,$19,$1A,$9B,$1C,$9D,$9E,$1F
    


    You'd need to fill in the rest, but you get the idea ... add $80 to the value if there's an even # bits.

    You would put your messages into EEPROM with a DATA statement, then use a subroutine to transmit them.
    You could hand translate the codes into odd parity as well and use them directly in SEROUT statements.
    message DATA "aXR",CR,0 ' zero byte marks the end
    
        address = message  ' pass the address of the message
        gosub   sendMessage
    
    sendMessage:
        read   address,character   ' get a character
        address = address + 1
        if character = 0 then return ' end of string
        read  table+character,character  ' translate the character
        serout <pin>,<Baud>,[noparse][[/noparse]character]
        goto sendMessage
    


    Note that you'd need a special subroutine to send numbers (like the DEC formatter).
  • TumbleweedTumbleweed Posts: 45
    edited 2007-11-06 19:34
    Thanks Mike. Really appreciate the help.

    Lance
  • TumbleweedTumbleweed Posts: 45
    edited 2007-11-06 20:30
    Hey all,
    I went ahead and completed the full table....or at least I think I did smile.gif
    Mike, can you check that I did it right and if not, let me know?

    Thanks,
    Lance

    oddParity DATA $80,$01,$02,$83,$04,$85,$86,$07,$08,$89,$8A,$0B,$8C,$0D,$0E,$8F
              DATA $10,$91,$92,$13,$94,$15,$16,$97,$98,$19,$1A,$9B,$1C,$9D,$9E,$1F
              DATA $20,$A1,$A2,$23,$A4,$25,$26,$A7,$A8,$29,$2A,$AB,$2C,$AD,$AE,$2F
              DATA $B0,$31,$32,$B3,$34,$B5,$B6,$37,$38,$B9,$BA,$3B,$BC,$3D,$3E,$BF
              DATA $40,$C1,$C2,$43,$C4,$45,$46,$C7,$C8,$49,$4A,$CB,$4C,$CD,$CE,$4F
              DATA $D0,$51,$52,$D3,$54,$D5,$D6,$57,$58,$D9,$DA,$5B,$DC,$5D,$5E,$DF
              DATA $E0,$61,$62,$E3,$64,$E5,$E6,$67,$68,$E9,$EA,$6B,$EC,$6D,$6E,$EF
              DATA $70,$F1,$F2,$73,$F4,$75,$76,$F7,$F8,$79,$7A,$FB,$7C,$FD,$FE,$7F
    
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-06 20:42
    It's pretty tedious to go through this by hand. Why don't you write a short Stamp Basic program to go through the table and count the number of one bits in each byte, check that the number of one bits is odd and use DEBUG to display any values that are wrong.
  • TumbleweedTumbleweed Posts: 45
    edited 2007-11-06 21:55
    I used excel to generate the table, so it should be good. But I will do as you suggest. Thanks again.

    I have a question. Now that I'm trying out the code sample I'm getting an error at this line:
    read  table+character,character  ' translate the character
    


    It's calling "table" an undefined symbol.

    I'm sorry if I'm asking stupid questions, but these are all aspects that are new to me and I have my manual sitting on my lap as I type.

    I think I understand the concept of your code, but must be missing something on the execution. Let me write it in plain english to see if I got it right, then maybe we can find out what I'm missing.

    Basically, we're reading in the parity table, then the message command. We're reading the first character ("a") of the message which translates to ASCII code 97 (hex code $61). We're then reading memory map position 97 ($61) to find out the actual command to send. In this case $61. $61 is 1100001 so it doesn't need to be converted before being sent.
    We're then sending that data to the SEROUT pin.

    Did I miss something?

    Thanks,
    Lance
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-06 22:05
    Sorry, I wrote table, I meant oddParity. It's whatever name you assign to the parity table.

    You've got the idea right.

    Read the chapters in the PBasic Manual on the DATA and READ statements. They explain how the DATA statement values get stored in EEPROM memory and how you use READ (and WRITE) to access these table areas.
  • TumbleweedTumbleweed Posts: 45
    edited 2007-11-07 14:46
    Hey Mike,
    Sorry, one more question then I'm going to take a break on this project.

    I'm using a BS2 and communication 9600 baud. If I'm understanding correctly I need to send the code in 8-bit, no-parity, true which would give a {baud} code of 84. Is that right?

    If so, I'm doing something wrong and its getting frustrating. I've gone so far as to manually send the 4 codes to initialize my device and it's not working. When I switch to a dedicated terminal it goes ok. I don't get it.

    Lance
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-07 15:24
    How are you connecting the pager system and the Stamp? A dedicated terminal usually has RS232 voltage levels. If you're directly connecting your Stamp to an RS232 connector (as described in the manual ... with protective resistors), the voltage that the Stamp puts out may not be enough. You may need a MAX232 to do the voltage conversion. In that case, the signal to the MAX232 has to be inverted (since the MAX232 inverts it).

    If you're using the programming/DEBUG port on the Board of Education, that has other considerations.
  • TumbleweedTumbleweed Posts: 45
    edited 2007-11-07 15:40
    Ahhh...that must be it. I'm connecting my pin2 directly to my syringe module (not a pager). I successfully sent the commands in a terminal using 8-N-1 so I know the codes work. But I must have brushed a live line when I was last switching between my computer serial cable and the Stamp's line because I fried my Stamp :-(
    I guess that's what I get for using my BOE instead of my Pro Dev Board. I've got a BS2pe which I will try using tomorrow. Thanks again for the help. I'll (hopefully) let you know how it goes.

    Lance
Sign In or Register to comment.