-
-
Bitte um "Hilfe" mit I2C-Bus am PC ,Temp. mit DS
Hallo Forum,
ich habe mir zum Experimentieren den I2C-Bus am Pc Bausatz bestellt. Der ist auch wie beschrieben schnell zusammengebaut.
Am I2C Bus möchte ich zum test einen DS18s20 Temperatursensor auslesen.
Der Sensor hat ein TO-92 Gehäuse mit 3 Anschlüssen 1- GND = Ground, 2-DQ = Data In/Out, und 3-Vdd = Power Supply Voltage
Wie muß ich den Sensor an den RN - Standard Bus anschließen? Nur 1 und 3 scheint nicht auszureichen.
Das Beispiel Programm startet nicht, aber ich glaube das hierzu ein I2C Device am Bus hängen muß ??
Auslesen möchte ich den Bus/Sensor mit VB.
Wer hat eine Idee wie das zu realisieren ist?
Gruß Tom_
-
Erfahrener Benutzer
Robotik Einstein
Hallo,
der DS18s20 wird nicht per I2C angeschlossen, sondern ist ein 1-wire Sensor,
deswegen klappts nicht.
-
Hallo zusammen, ich kann dir vieleicht weiter helfen!
probiers mit diesem Testbeispiel:
' DS18B20_two_thermo.bas for Atmel AVR vith Bascom - AVR and Dallas semiconductors DS18B20 temperature sensors - NO extra hardware
' Program "DUAL DS Thermo"
' Messures and displays temperature in 1/10 celcius on two DS sensors,
' stores and displays minimum and maximum readings.
' This program will NOT work on Bascom earlier than 1.11.6.2, cause of the CRC-function
' and (maybe ?) its not possible to declare functions in earlier environment.
' But the 1w-functions work from 1.11.4 , I think.
' The program code (BIN) will be ~3Kb so its NOT possible to run in DEMO-environment anyway
' Platform(s) : Atmel devkit ~1996, used "AVR ISP programmer"-setting
' Dev - uC : Atmel AT90s8515 (AVR) @ 4 Mhz
' BASCOM-AVR IDE Version : 1.11.6.2 Compiler: Version 1.11.6.2 (released)
' This is a TWO-sensor DS18b20 thermometer displayed on 2*16 LCD
' The sensors are on the same 1-w bus which is the intresting part
' The bus used is of 2-wire type, that means : Port-PIN to DQ, +5V to VDD and Gnd.
' See also HTML-help-file in Bascom regarding "Using the 1 WIRE protocol"
' Main goal is to show basics of using two DS-sensors on the same uC-pin.
' The code is written for easy understanding as goal, not optimized for anything else
' If you use it or test it, please report to the author. (Not when only browsing )
' mailto: gote@sys-op.com
' subject : DS18B20_two_thermo.bas test-report
' message : type of uC, Mhz, type of sensors used, type of cable and length
' platform (devkit / PCB ?), BASCOM-version, compiled code size, (BIN file size)
' That will be enough pay-back for non-commercial use.
' Changes in the code will be allowed, if copy of changed program is sent to author,
' with comments in English ( or German, Swedish ).
' For commercial use, contact author.
' (c) 2001 Göte Haluza, gote@sys-op.com, gote@hotmail.com (Sweden)
' version :1 , revision 2, Startdate : 18 apr 2001 Last update : 27 Apr 2001
'$sim
$regfile = "m8def.dat"
$crystal = 4000000
Declare Sub Init
Declare Sub Convallt ' Convert T on ALL sensors
Declare Function Decigrades(byval Sc(9) As Byte) As Integer
Config 1wire = Portb.0 '0,1,2 NOP 3,4,5,6,7 works good ON MY Equipment
Config Lcd = 20 * 4
Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7 , E = Portd.2 , Rs = Portd.0
'Temp variables
Dim B As Byte
Dim W As Word
'Program variables
'Implicit Err created by compiler
Dim Dg As Integer 'DECIgrades, I call it, cause I have no space for commas on the display....
Dim Min1 As Integer
Dim Min2 As Integer
Dim Max1 As Integer
Dim Max2 As Integer
Dim Dsid1( As Byte 'Dallas ID 64 bits incl CRC
Dim Dsid2( As Byte
'When Used Like This : Dsid(1) = 1wread(
'Dsid(1) = Family Code 'Ds1820 10h, DS18B20 28h, Ds18s20 10h
'Dsid(2) '48 Bits Serial, LSB
'Dsid(3)
'Dsid(4)
'Dsid(5)
'Dsid(6)
'Dsid(7) '48 Bits Serial, MSB
'Dsid( '8 CRC
Dim Sc(9) As Byte 'Scratchpad 0-8 72 bits incl CRC, explanations for DS18b20
'Sc(1) 'Temperature LSB
'Sc(2) 'Temperature MSB
'Sc(3) 'TH/user byte 1 also SRAM
'Sc(4) 'TL/user byte 2 also SRAM
'Sc(5) 'config also SRAM x R1 R0 1 1 1 1 1 - the r1 r0 are config for resolution - write FF to byte for 12 bit - others dont care
'Sc(6) 'res
'Sc(7) 'res
'Sc( 'res
'Sc(9) '8 CRC
'DALLAS DS18B20 ROM and scratchpad commands''''''''''''''''''''''''''1wwrite....
'&H 33 Read Rom - Single Sensor
'&H 55 Match Rom , Followed By 64 Bits
'&H Cc Skip Rom
'&H Ec Alarm Search - Ongoining Alarm > Th < Tl
'&H Be Read Scratchpad
'&H 44 Convert T
Cls
Lcd "This is a 2sensor DS18B20 thermometer"
Locate 2 , 1
Lcd " by gote@sys-op.com"
Wait 1
For B = 1 To 10
Shiftlcd Left
Waitms 500
Next
Wait 2
Cls
W = 1wirecount()
' Here I assume 2 sensors - no errorcontrol made, but would be easy to do with the "Err"-variable
' Getting the two sensors IDs.
Dsid1(1) = 1wsearchfirst()
Do
Dsid2(1) = 1wsearchnext()
Loop Until Err = 1
' If displayed, everything went well.
' First sensor identified and stored in variable
If Dsid1( = Crc8(dsid1(1) , 7) Then ' Control that the received CRC match the calculated
Locate 1 , 1
Lcd "CRC OK Sensor 1 ID"
Wait 1
Locate 1 , 1
For B = 1 To 8
Lcd Hex(dsid1(b))
Next
End If
' Second sensor
If Dsid2( = Crc8(dsid2(1) , 7) Then
Locate 2 , 1
Lcd "CRC OK Sensor 2 ID"
Wait 1
Locate 2 , 1
For B = 1 To 8
Lcd Hex(dsid2(b))
Next
End If
Wait 1
Cls
Init
' Main loop
Do
Convallt ' "Convert ALL T on the 1w-bus"
Waitus 200 : Waitus 200 : Waitus 200 : Waitus 200 'if you use 2-wire, could be reduced to 200us
1wverify Dsid1(1) 'Issues the "Match ROM "
Locate 1 , 1
If Err = 1 Then
Lcd "Err " 'Err = 1 if something is wrong
Elseif Err = 0 Then 'lcd " Sensor found"
1wwrite &HBE
Sc(1) = 1wread(9) 'read bytes into array
If Sc(9) = Crc8(sc(1) , Then
Dg = Decigrades(sc(9))
If Min1 > Dg Then Min1 = Dg
If Max1 < Dg Then Max1 = Dg
Lcd Dg : Locate 1 , 8 : Lcd Min1 : Locate 1 , 14 : Lcd Max1
End If
End If
1wverify Dsid2(1)
Locate 2 , 1
If Err = 1 Then
Lcd "DsId2 not on bus "
Elseif Err = 0 Then ' lcd " Sensor found "
1wwrite &HBE
Sc(1) = 1wread(9)
If Sc(9) = Crc8(sc(1) , Then
Dg = Decigrades(sc(9))
If Min2 > Dg Then Min2 = Dg
If Max2 < Dg Then Max2 = Dg
Lcd Dg : Locate 2 , 7 : Lcd Min2 : Locate 2 , 14 : Lcd Max2
End If
End If
Wait 1
Loop
End 'end program
'Sets variables and LCD for further use'''''''''''''''''''''''''''''''''''''''''
Sub Init
Cls
Lcd " Min Max"
Locate 2 , 1
Lcd " Min Max"
Min1 = 999 ' to get a real value from start
Min2 = 999
End Sub
'Makes the Dallas "Convert T" command on the 1w-bus configured in "Config 1wire = Portb. "
'WAIT 200-750 ms after issued, internal conversion time for the sensor''''''''''
'SKIPS ROM - so it makes the conversion on ALL sensors on the bus simultaniously
'When leaving this sub, NO sensor is selected, but ALL sensors has the actual
'temperature in their scratchpad ( within 750 ms )
Sub Convallt
1wreset ' reset the bus
1wwrite &HCC ' skip rom
1wwrite &H44 ' Convert T
1wwrite &HEC '&H Ec Alarm Search - Ongoining Alarm > Th < Tl
End Sub
'Makes a integer value of the first two bytes in scratchpad'''''''''''''
'Works on DS18 B 20 , observe "B". The R0 and R1 in Sc(5) tells you how many bits are accurate
'Function Decigrades(byval Sc(9) As Byte)
' Decigrades = 0
' Decigrades = Makeint(sc(1) , Sc(2))
' Decigrades = Decigrades * 10
' Decigrades = Decigrades / 16
'End Function
' If you have DS1820 or DS18 S 20 , you can use this algo instead:
' Observe that DsId1(1) contains the info value of which sensor is used.
Function Decigrades(byval Sc(9) As Byte)
Dim Tmp As Byte , T As Integer , T1 As Integer
Tmp = Sc(1) And 1 ' 0.1C precision
If Tmp = 1 Then Decr Sc(1)
T = Makeint(sc(1) , Sc(2))
'Print Hex(t)
'Print T
T = T * 50 'here we calculate the 1/10 precision like
T = T - 25 'DS18S20 data sheet
T1 = Sc( - Sc(7)
T1 = T1 * 100
T1 = T1 / Sc(
T = T + T1
Decigrades = T / 10
'As integer, this routine gives T*10, with 1/10 degree precision
End Function
Berechtigungen
- Neue Themen erstellen: Nein
- Themen beantworten: Nein
- Anhänge hochladen: Nein
- Beiträge bearbeiten: Nein
-
Foren-Regeln
Lesezeichen