Ok, ive gotten a little bit further found some code over at:
http://code.tinyclr....7/ds1620-driver
that does what i wanted, and after some tweaking seems to work perfectly, yet when ive converted it over to VB it seems the temp is off by a few degrees,
here are both classes, hopefully i have just made a mistake in my conversion now and its not another works in C# but not in VB thing
the C# Class:
public class DS1620_2 {
private TristatePort _data ;
private OutputPort _clock;
private OutputPort _reset;
public DS1620_2( Cpu.Pin dq,Cpu.Pin clk, Cpu.Pin rst)
{
_clock = new OutputPort(clk, false);
_reset = new OutputPort(rst, false);
_data = new TristatePort(dq, false, false, Port.ResistorMode.Disabled);
_data.Active = true;
}
void write_command(int command)
/* sends 8 bit command on DQ output, least sig bit first */
{
int n, bit;
for (n = 0; n < 8; n++)
{
bit = ((command >> n) & (0x01));
_data.Write((bit == 1));
_clock.Write(false);
_clock.Write(true);
}
}
int read_raw_data()
{
int bit, n;
int raw_data = 0; // go into input mode
if (_data.Active == true)
_data.Active = false;
for (n = 0; n < 9; n++)
{
_clock.Write(false);
if (_data.Read() == true)
bit = 1;
else
bit = 0;
_clock.Write(true);
raw_data = raw_data | (bit << n);
}
// make it a output again
if (_data.Active == false)
_data.Active = true;
return (raw_data);
}
public double readTemp()
{
_reset.Write(false);
_clock.Write(true);
_reset.Write(true);
write_command(0x0c); // write config command
write_command(0x02); // cpu mode
_reset.Write(false);
Thread.Sleep(200); //wait until the configuration register is written
_clock.Write(true);
_reset.Write(true);
write_command(0xEE); //start conversion
_reset.Write(false);
Thread.Sleep(200);
_clock.Write(true);
_reset.Write(true);
write_command(0xAA);
int raw_data = read_raw_data();
_reset.Write(false);
return ((double)raw_data / 2.0);
}
}
the vb class:
Public Class DS1620
Private _data As TristatePort
Private _clock As OutputPort
Private _reset As OutputPort
Private _high As Int32 = 125
Private _low As Int32 = -55
Sub New(ByVal data As Cpu.Pin, ByVal clock As Cpu.Pin, ByVal reset As Cpu.Pin)
_data = New TristatePort(data, False, False, Port.ResistorMode.Disabled)
_clock = New OutputPort(clock, False)
_reset = New OutputPort(reset, False)
_data.Active = True
End Sub
Public Function ReadTemp() As Double
_reset.Write(False)
_clock.Write(True)
_reset.Write(True)
write_command(&HC)
write_command(&H2)
_reset.Write(False)
Thread.Sleep(200)
_clock.Write(True)
_reset.Write(True)
write_command(&HEE)
_reset.Write(False)
Thread.Sleep(200)
_clock.Write(True)
_reset.Write(True)
write_command(&HAA)
Dim temp As Integer = read_raw_data()
_reset.Write(False)
Return (CDbl(temp) / 2.0)
End Function
Private Sub write_command(command As Integer)
Dim bit As Int32
For n = 0 To 8 Step 1
bit = ((command >> n) And (&H1))
If bit = 1 Then
_data.Write(True)
Else
_data.Write(False)
End If
_clock.Write(False)
_clock.Write(True)
Next
End Sub
Private Function read_raw_data() As Int32
Dim bit, n As Int32
Dim raw_data As Int32 = 0
If _data.Active Then
_data.Active = False
End If
For n = 0 To 9 Step 1
_clock.Write(False)
If _data.Read = True Then
bit = 1
Else
bit = 0
End If
_clock.Write(True)
raw_data = raw_data Or (bit << n)
Next
If Not _data.Active Then
_data.Active = True
End If
Return raw_data
End Function
End Class