Shop OBEX P1 Docs P2 Docs Learn Events
8E1 Serial with Basic Stamps — Parallax Forums

8E1 Serial with Basic Stamps

max_mmax_m Posts: 3
edited 2009-12-19 00:28 in BASIC Stamp
I'm trying to communicate with an industrial Pressure/Level sensor with serial communication parameters of 8E1 (8 Bits, Even Parity, 1 Stop Bit). I'd like to use a basic stamp to poll and process the data from the sensor but it seems the serout/serin command can not handle 8 bits and even parity. Has anyone been able to make a stamp communicate with 8E1 settings? If so, can you share your solution?

Thanks

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-12-18 22:03
    Look at the chapter on the SEROUT and SERIN commands in the BASIC Stamp Syntax and Reference Manual or the help files for the Stamp Editor. There are tables for the Baud constants for various settings. One group is for 7 data bits, even parity, and a stop bit. This is what you should use. With very rare exceptions, when datasheets mention 8 bits with even parity, they're including the parity bit in the total of 8 bits. There are old devices that have 8 data bits and a parity bit (to make a total of 9 bits), but this is very non-standard now and most modern equipment cannot talk to this sort of device.
  • max_mmax_m Posts: 3
    edited 2009-12-18 22:45
    Right, I've actually already tried that but thanks. I can confirm the sensor expects 11-bit packages. Thats 1 start bit, 8 bits for data, parity bit, and stop bit. The sensor documentation specifies it as such. I can communicate with the sensor using hyperaccess set to 8E1 and a simple hyperaccess script.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-12-18 23:44
    The Stamps cannot do 8 bit data plus parity. You'd have to use either the SX or Propeller. They both could handle this easily. The Propeller's serial library routines assume 8 bits of data without parity, but one routine (Simple_Serial) just uses a constant of 8. It's a simple matter to change that to 9 and to supply/check the parity along with the data. The Propeller is fast enough to directly calculate the parity like:

    data |= ((data<<1)^(data<<2)^(data<<3)^(data<<4)^(data<<5)^(data<<6)^(data<<7)^(data<<8))&$100

    Post Edited (Mike Green) : 12/19/2009 12:31:28 AM GMT
  • max_mmax_m Posts: 3
    edited 2009-12-19 00:16
    Thanks. We actually have a Propeller eval board here but I just haven't delved into it. It may be the solution.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-12-19 00:28
    The following modifications to Simple_Serial should allow you to receive and transmit 9 bits of data rather than 8 with the 9th bit provided for parity. The transmit routine calculates the parity and includes it. The receive routine ignores it.
    PUB rx: rxByte | t
    {{ Receive a byte; blocks caller until byte received. }}
    
      if rxOkay
        dira[noparse][[/noparse]sin]~                                          ' make rx pin an input
        waitpeq(inverted & |< sin, |< sin, 0)               ' wait for start bit
        t := cnt + bitTime >> 1                             ' sync + 1/2 bit
        repeat 9                                                 ' *****
          waitcnt(t += bitTime)                             ' wait for middle of bit
          rxByte := ina[noparse][[/noparse]sin] << 8 | rxByte >> 1             ' sample bit *****
        waitcnt(t + bitTime)                                ' allow for stop bit 
        rxByte ^= inverted & $1FF                            ' adjust for mode *****
        rxByte &= $FF                                       ' strip off received parity *****
    
    
    PUB tx(txByte) | t
    {{ Transmit a byte with even parity; blocks caller until byte transmitted. }}
    
      txByte |= ((txByte<<1)^(txByte<<2)^(txByte<<3)^(txByte<<4)^(txByte<<5)^(txByte<<6)^(txByte<<7)^(txByte<<8))&$100
      if txOkay
        outa[noparse][[/noparse]sout] := !inverted                             ' set idle state
        dira[noparse][[/noparse]sout]~~                                        ' make tx pin an output        
        txByte := ((txByte | $200) << 2) ^ inverted         ' add stop bit, set mode *****
        t := cnt                                            ' sync
        repeat 11                                           ' start + eight data bits + even parity + stop *****
          waitcnt(t += bitTime)                             ' wait bit time
          outa[noparse][[/noparse]sout] := (txByte >>= 1) & 1                  ' output bit (true mode)  
        
        if sout == sin
          dira[noparse][[/noparse]sout]~                                       ' release to pull-up/pull-down
    


    This is actually off-topic for this BASIC Stamp forum. If you have any questions or comments further on this, please start a new thread in the Propeller forum. Thanks.

    Post Edited (Mike Green) : 12/19/2009 12:36:01 AM GMT
Sign In or Register to comment.