philiph
17.09.2006, 13:28
Also obwohl ich alle möglichen Themen im Internet durchgearbeitet habe finde ich keine Lösung für mein Problem: Ich möchte die Temperatur aus meinem DS1631 Auslesen und bekomme immer nur 21.15 Grad.
Also ich habe folgende Pins des DS1631 Angeschlossen:
1 -->mit 1,7k nach 5V und an SDA
2 -->mit 1,7k nach 5V und an SCL
3 -->nichts
4 -->GND
5 -->GND
6 -->GND
7 -->GND
8 -->5V
und benutze diesen Code:
$regfile = "m16def.dat"
$crystal = 8000000
$baud = 9600
$hwstack = 32
$swstack = 10
$framesize = 40
Dim Addr As Byte
Dim Dat As Byte
Const Convert = &H51
Const Stop_convert = &H22
Const Read_temp = &HAA
Const Conf = &HAC
Const Reset = &H54
Dim Temp As Word
Dim Temphi As Byte
Dim Templo As Byte
Dim Temp1 As Byte
Dim Temp2 As Byte
Const Ds1631 = &H90
Declare Sub Ds1631reset
Declare Sub Ds1631convert
Declare Sub Ds1631get_status
Declare Sub Ds1631set_status
Declare Sub Ds1631wait_ready
Declare Sub Ds1631get_temp
Temp:
Ds1631reset
Ds1631set_status
I2cinit
Waitms 10
Ds1631convert
Ds1631wait_ready
Ds1631get_temp
Shift Temp , Right , 7
Temp1 = Temp / 2
Temp2 = Temp + 1
Temp2 = Temp2 * 5
Print "TEMP: " ; Temp ; Temp1 ; "." ; Temp2 ; " C " ;
Wait 2
Goto Main
'-----------------------------------------------------
'------------------ DS1631 RESET ------------------
'-----------------------------------------------------
Sub Ds1631reset(addr As Byte)
Addr = Ds1631
I2cstart
I2cwbyte Addr
I2cwbyte Reset
I2cstop
End Sub
'-----------------------------------------------------
'------------------ DS1631 CONVERT ----------------
'-----------------------------------------------------
Sub Ds1631convert(addr As Byte)
Addr = Ds1631
I2cstart
I2cwbyte Addr
I2cwbyte Convert
I2cstop
End Sub
'-----------------------------------------------------
'----------------- GET DS1631 STATUS -----------------
'-----------------------------------------------------
Sub Ds1631get_status(addr As Byte)
Dim Data As Byte
Addr = Ds1631
I2cstart
I2cwbyte Addr
I2cwbyte Conf
I2cstop
I2cstart
Addr = Addr + 1
I2cwbyte Addr
I2crbyte Dat
Print "dat1 " ; Dat
I2cstop
End Sub
'-------------------------------------------------------
'----------------- SET DS1631 STATUS -----------------
'-------------------------------------------------------
Sub Ds1631set_status(addr As Byte , Dat As Byte)
Addr = Ds1631
I2cstart
I2cwbyte Addr
I2cwbyte Conf
I2cwbyte &HA1
I2cstop
End Sub
Sub Ds1631wait_ready(addr As Byte)
Waitms 20
Ds1631get_status
End Sub
'-----------------------------------------------------
'----------------- GET DS1631 TEMP -----------------
'-----------------------------------------------------
Sub Ds1631get_temp(addr As Byte , Temp As Word , Dat As Byte )
Addr = Ds1631
I2cstart
I2cwbyte Addr
I2cwbyte Read_temp
I2cstop
Addr = Addr + 1
I2cstart
I2cwbyte Addr
I2crbyte Dat , Ack
Temp = Dat * 256
I2crbyte Dat , Nack
Temp = Temp + Dat
I2cstop
End Sub
Also ich habe folgende Pins des DS1631 Angeschlossen:
1 -->mit 1,7k nach 5V und an SDA
2 -->mit 1,7k nach 5V und an SCL
3 -->nichts
4 -->GND
5 -->GND
6 -->GND
7 -->GND
8 -->5V
und benutze diesen Code:
$regfile = "m16def.dat"
$crystal = 8000000
$baud = 9600
$hwstack = 32
$swstack = 10
$framesize = 40
Dim Addr As Byte
Dim Dat As Byte
Const Convert = &H51
Const Stop_convert = &H22
Const Read_temp = &HAA
Const Conf = &HAC
Const Reset = &H54
Dim Temp As Word
Dim Temphi As Byte
Dim Templo As Byte
Dim Temp1 As Byte
Dim Temp2 As Byte
Const Ds1631 = &H90
Declare Sub Ds1631reset
Declare Sub Ds1631convert
Declare Sub Ds1631get_status
Declare Sub Ds1631set_status
Declare Sub Ds1631wait_ready
Declare Sub Ds1631get_temp
Temp:
Ds1631reset
Ds1631set_status
I2cinit
Waitms 10
Ds1631convert
Ds1631wait_ready
Ds1631get_temp
Shift Temp , Right , 7
Temp1 = Temp / 2
Temp2 = Temp + 1
Temp2 = Temp2 * 5
Print "TEMP: " ; Temp ; Temp1 ; "." ; Temp2 ; " C " ;
Wait 2
Goto Main
'-----------------------------------------------------
'------------------ DS1631 RESET ------------------
'-----------------------------------------------------
Sub Ds1631reset(addr As Byte)
Addr = Ds1631
I2cstart
I2cwbyte Addr
I2cwbyte Reset
I2cstop
End Sub
'-----------------------------------------------------
'------------------ DS1631 CONVERT ----------------
'-----------------------------------------------------
Sub Ds1631convert(addr As Byte)
Addr = Ds1631
I2cstart
I2cwbyte Addr
I2cwbyte Convert
I2cstop
End Sub
'-----------------------------------------------------
'----------------- GET DS1631 STATUS -----------------
'-----------------------------------------------------
Sub Ds1631get_status(addr As Byte)
Dim Data As Byte
Addr = Ds1631
I2cstart
I2cwbyte Addr
I2cwbyte Conf
I2cstop
I2cstart
Addr = Addr + 1
I2cwbyte Addr
I2crbyte Dat
Print "dat1 " ; Dat
I2cstop
End Sub
'-------------------------------------------------------
'----------------- SET DS1631 STATUS -----------------
'-------------------------------------------------------
Sub Ds1631set_status(addr As Byte , Dat As Byte)
Addr = Ds1631
I2cstart
I2cwbyte Addr
I2cwbyte Conf
I2cwbyte &HA1
I2cstop
End Sub
Sub Ds1631wait_ready(addr As Byte)
Waitms 20
Ds1631get_status
End Sub
'-----------------------------------------------------
'----------------- GET DS1631 TEMP -----------------
'-----------------------------------------------------
Sub Ds1631get_temp(addr As Byte , Temp As Word , Dat As Byte )
Addr = Ds1631
I2cstart
I2cwbyte Addr
I2cwbyte Read_temp
I2cstop
Addr = Addr + 1
I2cstart
I2cwbyte Addr
I2crbyte Dat , Ack
Temp = Dat * 256
I2crbyte Dat , Nack
Temp = Temp + Dat
I2cstop
End Sub