Searching for PICaxe SDI-12 implementation

Eclectica

Member
Hi,

I remember back into the distant past (wow that's over 3 decades!:rolleyes:) that my one of software lecturers at Brighton said "don't re-invent the wheel"!

So, I was just wondering if anyone has come across a SDI-12 PICaxe implementation? http://www.sdi-12.org/
(Would have to be for 28 or 40 I would have thought, so as to leave room for user program.)

Thanks in advance.:)

E.
 

Buzby

Senior Member
Hi Eclectica,

I couldn't find a PICAXE implementation, but here is a STAMP Basic version, which won't take much to convert.


Code:
Here is a simple BASIC Stamp command/response exchange to read a continuously recording stream stage instrument:

    SDIp    con 0       ' this pin for data
    baud    con  $32A + $4000 + $2000   ' 1200 baud, inverted (stop bit low), 7bit even parity
    SDI12:
      high SDIp          ' generate BREAK
      pause 12
      low SDIp           ' end BREAK
      pause 7            ' let it sink in
      serout SDIp,baud,["0R0!"]   ' command for device 0, Read, value 0, ! ends command
      input SDIp                  ' release the serial line to await response
      serin SDIp,baud,100,noResponse,[wait ("0"),SDEC result]
      debug SDEC result, " millimeters",cr
      nap 6
    goto SDI12
       
    noResponse:
      debug "something went wrong",cr
    goto SDI12

The Stamp first generates the break condition, followed by a low level, and then it sends a command, "0R0!". 
That addresses the device set up to answer to "0", then the "read", command, and finally the command terminator "!". 
The data line is turned to an input, so that it can await the response from the device. 
The serin command awaits the echo of the address byte, followed by the signed decimal result, which is terminated with <CR>.
I found the code on this site, but I've not explored it further.

http://www.pearltrees.com/#/N-play=1&N-p=12090988&N-u=1_155467&N-s=1_1710355&N-f=1_1710355&N-fa=1647658

Cheers,

Buzby
 

westaust55

Moderator
The SDI-12 protocol should be relatively easy to impliment.
when transmitting use SEROUT and immediately after change the pin to an input so as not to impact on the rest of the nextwork even if not receiving data.
The protocol has 1 start, 7 data, 1 parity, and 1 stop bit.

That fits the data and parity neat into a byte. take the data value shift left 1 bit (= *2 on not X1/X2 parts) and add/or the parity bit into the least significant bit.
The parity is even parity so count the number of bits in the data (NOB command on X2 parts) and if odd make the parity bit 1 for even.
 

Eclectica

Member
Thanks for the replies. I'll see what I can do - I can feel an all nighter coming on!:p

It would be nice to write a complete implementation for master and slave, but it might take too long!:rolleyes:

Regards
E.
 
Top