External Links

Creative Science Centre

 

1-Wire

// #include "http://www.byvac.com/mBlib/flb/Library/2016/lib_ow.bas"

Resources:

  • Data sheet for the DS18S20
  • Data sheet for the DS18B20
  • Source code for the plug-in (only needed if you intend to modify the basic functions)

THIS LIBRARY WILL NOT WORK FROM RAM, IT MUST BE SAVED TO FLASH - this will occur normally if it is used as an include file ** Also don't forget that a 1-wire device has a pull up resistor.

How to use

The library is initiated with a timer and port pin:

constant OWBUS {PORTC(PORT),7) // bus is RC7

  • owInit(*TIMER3(),*OWBUS())

Above is the initialisation of 1-wire using timer 3 and port c pin 7

  • owFillRoms(*roms(),max_devices)

Gets the ROM codes for all connected devices in a supplied two dimensional array(number of devices>,<rom code>). The rom code will always be two bytes as it is 64 bits. This will return the actual number of devices on the bus.

Example

owInit(*TIMER3(),*OWBUS())
dim roms(5,2) // max 5 devices
print owFillRoms(*roms(),5)

Above returns with the actual number of devices so the first devise will be:

roms(0,0)
roms(0,1)

For a good practical example of how to use see below.

There are a few 1-wire devices available including some EEPROMS that also have on board PIO, DS2406 and the like. However all of the 1-wire devices are much more expensive than their SPI or I2C counterparts so I guess that is why they are not so popular. There is one exception to this and that is the DS18S20 temperature sensor that is a bit cheaper than the I2C equivalent and at the moment you can get them built into a temperature probe.

Example DS18_20

Use this as an example of how to use the 1-wire library

This is for both the DS18S20 and SD18B20 which interpret the two received bytes differently. The B version works to 4 decimal places whilst the S version is either 0.5 or 0

http://www.byvac.com/mBlib/flb/Library/2016/ds1820.bas

The code is above and is commented, it can be used as a library or stand alone.