How to implement 8E2 serial protocol?


Closed Thread
Results 1 to 5 of 5
  1. #1
    imt_67's Avatar
    imt_67 Guest

    Default How to implement 8E2 serial protocol?

    Hello,
    I'm a totally newbie abut PIC and PICBASIC programming.
    I would build a PIC reader for my weather station, using its built-in RS232 interface. Before starting, I found a big problem to solve: the weather station uses a *not so common* serial protocol: 1 start bit, 8 data bits, EVEN parity and 2 bits stop (1+8+1+2=12 bits!) with a speed of 19200 bps. I haven't found a way to obtain it, neither with SERIN/SEROUT commands, nor with hardware USART commands, so I think I must create it from scratch....

    Anyone has suggestions, examples, code pieces to help me?

    Thanks in advance.

    PS: I think to use a 16F876 device for this project.

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166

    Default

    imt_67, Just use 8 data bits, 1 parity bit, and 1 stop bit for your received data. Ignor the last bit received......

    Dave Purola,
    N8NTA

  3. #3
    Join Date
    Aug 2005
    Posts
    42

    Default

    Like Dave says, ignore the last stop bit and when sending/receiving data by adding a pause after the serin command, especially if in a loop receiving byte after byte.

    Or write a Bit Bang routine.

    Lasy example below, but I am sure you can create a couple of loops to cut it down, have used pauseus of 104 that gives you 9600 baud, simply cut down the pause time to suit required baud rate:


    To send a byte:

    'Send Start Bit
    portb.7=0
    pauseus 104

    'Send Byte out
    portb.7=Byteout.bit0
    pauseus 104
    portb.7=Byteout.bit1
    pauseus 104
    portb.7=Byteout.bit2
    pauseus 104
    portb.7=Byteout.bit3
    pauseus 104
    portb.7=Byteout.bit4
    pauseus 104
    portb.7=Byteout.bit5
    pauseus 104
    portb.7=Byteout.bit6
    pauseus 104
    portb.7=Byteout.bit7
    pauseus 104

    'Send Parity bit
    portb.7=Parity
    pauseus 104

    'Send 2 Stop Bits
    portb.7=1
    pauseus 104
    portb.7=1
    pauseus 104

    *****

    To receive a byte:

    'Check for start bit by sampling the port twice within 104us.
    check1:
    if portb.6=0 then
    else
    goto check1
    endif
    pauseus 52
    if portb.6=0 then
    else
    goto check1
    endif
    pauseus 104

    'Receive Byte in
    ByteIn.bit0=portb.6
    pauseus 104
    ByteIn.bit1=portb.6
    pauseus 104
    ByteIn.bit2=portb.6
    pauseus 104
    ByteIn.bit3=portb.6
    pauseus 104
    ByteIn.bit4=portb.6
    pauseus 104
    ByteIn.bit5=portb.6
    pauseus 104
    ByteIn.bit6=portb.6
    pauseus 104
    ByteIn.bit7=portb.6
    pauseus 104

    'Receive Parity bit
    Parity=portb.6
    pauseus 104

    'Receive 2 Stop bits
    pauseus 104
    pauseus 104

    Regards

    Sean.

  4. #4
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237

    Lightbulb

    When recieving, do what Dave said, just use 8E1. PBP will see the extra stopbit as a little pause between the characters, no problems atall and nothing you need to worry about.

    When sending, you need to add that extra stopbit. You do that by adding a short pause(1/19200=52us) after each character. You can also use character pacing(which does exactly that). The biggest problem with that is that SEROUT2 paces with milliseconds. If you specify 1ms it may take too much time to send the entire message, but it will work. If your messages are short it may not be a problem.

    /Ingvar

  5. #5
    imt_67's Avatar
    imt_67 Guest

    Default Thanks a lot!

    As all of you wrote, I tried using 19200-8-E-1 protocol to connect my weather station (now writing a little program for PC using freepascal...fast and lazy way ;-) ) and it seems to be tolerant to 1 or 2 stop bits, both for tx and rx.
    So I'll try with SERIN and SERUOT as soon I'll have some time to spend (this weekend...I hope!). Fortunately I have to send only very small commands to ws ( four bytes or so... with fixed values), so also the "bit bang" idea (very nice!) may be useful...

    Again, thanks a lot!

    Marco.

Similar Threads

  1. Replies: 17
    Last Post: - 12th April 2014, 02:17
  2. How to define serial protocol ?
    By chrischristian in forum mel PIC BASIC
    Replies: 1
    Last Post: - 24th October 2009, 03:42
  3. Dynamic USB Serial Number (PIC18F4550)
    By awmt102 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th July 2009, 17:03
  4. Serial protocol not supported?
    By paxmowa in forum Serial
    Replies: 3
    Last Post: - 11th September 2007, 13:11
  5. UPS serial protocol
    By sougata in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 5th November 2006, 02:49

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts