I have posted a new device driver for the Maxim DS2482 device. The DS2482 is an I²C to 1-Wire bridge. The DS2482 allows any host with I²C communication to generate properly timed and slew-controlled 1-Wire waveforms. This new driver provides detailed communication sessions for common 1-Wire master operations. I have used the DS18B20 sensor in this example.
The is based on the Maxim application note 3684 and therefore supports all the 1-Wire functions, called primitives, which an application must have to perform any 1-Wire communication session.
The driver has all the primitives required for normal operation.
The function OWReset resets all the 1-Wire slaves on the network, readying them for a command from the 1-Wire master.
The function OWWriteBit writes a bit from the 1-Wire master to the slaves, and the function OWReadBit reads a bit from the 1-Wire slaves. Since the 1-Wire master must start all 1-Wire bit communication, a "read" is technically a "write" of a single bit with the result sampled. Almost all other 1-Wire operations can be constructed from these three operations. For example, a byte written to the 1-Wire network is just eight single bit writes.
A 1-Wire Search Algorithm can also be constructed using these same three primitives. However, the DS2482 incorporates a search helper function called the 1-Wire triplet, which greatly reduces the communication overhead required for a search. Similarly there is a byte 1-Wire communication command that is more efficient than doing eight single-bit commands.
'Sample Code a DS18B20 - requires #include <ds2482.h>
' Required to DS18B20 support
#define ConvertT 68 ' 0x44 (68). DS18B20 command set
#define ReadScratch 190 ' 0xBE (190). DS18B20 command set
Dim DSdata As Word ' required for negative numbers support
Dim TempC_100 as word ' variable to handle the temperature calculations
Locate 0,0
Print "DS2428 "
if ds2482_detect = true then
HSerPrint "DS2482 Device"
Else
if ds2482_reset = true then
HSerPrint "I2C Bus Error, or"
HSerPrintCRLF
HSerPrint "One Wire Device(s)Missing"
else
HSerPrint "DS2482 Missing"
end if
exit sub
end if
' read DS18B20 64-BIT LASERED ROM CODE
if ds2482_OWReset = true then
DSdata = 0
oneWire_writeByte ( READ_DEVICE_ROM ) ' Send 64-BIT LASERED ROM CODE read command
for cc = 0 to 7
oneWire_ReadByte ( DSdata ) ' Process and display the 64-BIT LASERED ROM CODE
HSerPrint hex(DSdata)
next
end if
Locate 1,0
' read DS18B20 device on the bus. Using the DS18B20 protocol. See the device Datasheet.
if ds2482_OWReset = true then
DSdata = 0
oneWire_writeByte ( SKIP_ROM )
oneWire_writeByte ( ConvertT )
ds2482_temp = ds2482_OWReset
oneWire_writeByte ( SKIP_ROM )
oneWire_writeByte ( ReadScratch )
' read temperature values
oneWire_ReadByte ( DSdata ) ' we now have one byte of the 12 bit number
oneWire_ReadByte ( DSdata_h ) ' we now have other byte of the 12 bit number
' do some simple maths to calculate the temp.
SignBit = DSdata / 256 / 128
If SignBit = 0 Then goto Positive
' its negative!
DSdata = ( DSdata # 0xffff ) + 1 ' take twos comp
Positive:
' Convert value * 0.0625. Mulitple value by 6 then add result to multiplication of the value with 25 then divide result by 100.
TempC_100 = DSdata * 6
DSdata = ( DSdata * 25 ) / 100
TempC_100 = TempC_100 + DSdata
Whole = TempC_100 / 100
Fract = TempC_100 % 100
If SignBit = 0 Then goto DisplayTemp
HSerPrint "-"
DisplayTemp:
HSerPrint str(Whole)
HSerPrint "."
' To ensure the decimal part is two digits
Dig = Fract / 10
HSerPrint Dig
Dig = Fract % 10
HSerPrint Dig:
HSerPrint "c"
else
HSerPrint "Error one One Wire Bus"
end if
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have posted a new device driver for the Maxim DS2482 device. The DS2482 is an I²C to 1-Wire bridge. The DS2482 allows any host with I²C communication to generate properly timed and slew-controlled 1-Wire waveforms. This new driver provides detailed communication sessions for common 1-Wire master operations. I have used the DS18B20 sensor in this example.
The is based on the Maxim application note 3684 and therefore supports all the 1-Wire functions, called primitives, which an application must have to perform any 1-Wire communication session.
The driver has all the primitives required for normal operation.
Anobium
See https://sourceforge.net/p/gcbasic/code/HEAD/tree/GCBASIC/trunk/include/ds2482.h