Shop OBEX P1 Docs P2 Docs Learn Events
SDI-12 communication — Parallax Forums

SDI-12 communication

danielreisdanielreis Posts: 16
edited 2010-08-27 04:03 in Propeller 1
Hi guys,

I need to communicate with a sensor that communicates using SDI-12 protocol:
. 1200 baud
. 1 start bit
. 7 data bits, least significant bit first
. 1 parity bit, even parity
. 1 stop bit

How can I configure to send and receive commands with that configuration in propeller?

With the BS2pe, I use the value $432a for SDI-12 communication in "serin" and "serout" commands, but I don't know how to make that configuration using the propeller.

Can somebody help me?

Thanks,

Daniel Reis

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-19 10:23
    All of the serial I/O drivers accept a Baud value given literally (1200 or 2400 or 9600, etc.), so the 1200 Baud is not a problem. All of the serial I/O drivers handle 8 bit bytes. You can do your own parity bit calculation so 7 bits of data plus parity is not a problem. There's always one start bit and one stop bit.

    This is used to process the 7 bit values for transmission (adding even parity):
    pri Do7to8even(value) | parity
    parity := ((value>>6)^(value>>5)^(value>>4)^(value>>3)^(value>>2)^(value>>1)^value)&1
    return (parity<<7) | (value&$7F)
    

    This is used to check even parity:
    pri Do7evenOK(value) | parity
    parity := ((value>>6)^(value>>5)^(value>>4)^(value>>3)^(value>>2)^(value>>1)^value)&1
    return parity == (value>>7)
    
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-08-19 10:42
    1200 is very slow and you can generate custom rx and tx methods to do that. I *borrowed* some code from the simple_serial object and converted them to even parity (I think).

    I haven't tested this, but feel like it should work. Hope this helps.
  • danielreisdanielreis Posts: 16
    edited 2010-08-26 05:49
    Thank you guys for the quick reply.

    Jonny, I tried to use your code but it didn't work, and I couldn't find what's the error

    Mike, I'm having trouble to implement your code. I think that my problem is to understand better how the communication happens. How can I send all my "packet" of bits through the pin? The parity bit is the LSB?
  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-26 06:00
    The parity bit is always the most significant bit and asynchronous serial I/O is always done least significant bit first.

    There are several asynchronous serial I/O drivers available. The easiest to understand is either "Simple Serial" or the serial I/O routines in "BS2 Functions", both downloadable from the Propeller Object Exchange.

    If you need buffered I/O, you can use "FullDuplexSerial" which comes with the Propeller Tool and also is downloadable from the Object Exchange.

    These drivers act as a UART and take care of shifting out (and shifting in) the data as well as the timing of the bits.

    The routines I posted are used for pre-processing your data to generate the parity bit for transmission (and make a 7-bit value into an 8-bit value including the parity bit) or to check the parity bit on reception.
  • danielreisdanielreis Posts: 16
    edited 2010-08-27 04:03
    Mike, thank you very much for the explanation. It was very enlightening.

    I will try to use your code and post here the results.

    Thank you!
Sign In or Register to comment.