View previous topic :: View next topic |
Author |
Message |
dk_akj
Joined: 14 Sep 2004 Posts: 94
|
Posted: Fri Apr 01, 2005 8:52 pm Post subject: DS1621 - I2C temperature |
|
|
Hi,
Has some of you a link or some code and maybe schematics for connecting a DS1621 temperature transmitter to a AVR ??
I've tried to use/modify the sample file for 1620 but the temperature returned from the DS1621 is either 225 or 127.
This is my first test with I2C so I'm really lost...
Kind regards
Anders |
|
Back to top |
|
|
Luciano
Joined: 29 Nov 2004 Posts: 3149 Location: Italy
|
|
Back to top |
|
|
dk_akj
Joined: 14 Sep 2004 Posts: 94
|
Posted: Sat Apr 02, 2005 4:30 pm Post subject: |
|
|
Hi Luciano
Thank you very much
I did try google, what words did you search ??
Thanks again
Anders |
|
Back to top |
|
|
Luciano
Joined: 29 Nov 2004 Posts: 3149 Location: Italy
|
Posted: Sun Apr 03, 2005 9:23 am Post subject: |
|
|
Google search:
DS1621 bascom avr
Luciano |
|
Back to top |
|
|
dk_akj
Joined: 14 Sep 2004 Posts: 94
|
Posted: Sun Apr 03, 2005 8:15 pm Post subject: |
|
|
Hmm, I think i used the same words..
Thanks again
Anders |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Fri Apr 08, 2005 3:48 pm Post subject: |
|
|
hi,
I use it, and it works fine: dont forget the R 2,2k of pull-up line SDA and SCL
I finalyse the project, actually it is in french, and mixed inside a very very big program.
if you still don't work in 1 or 2 weeks, send me a message, I will extract it for you
JP _________________ pleasure to learn, to teach, to create |
|
Back to top |
|
|
dk_akj
Joined: 14 Sep 2004 Posts: 94
|
Posted: Sat May 07, 2005 10:11 pm Post subject: |
|
|
Hi,
I'm now playing with the DS1621 again.
I've connected 2 ds1621 to my labboard and i'm polling them with a Mega32.
Im using adr H90 and H92.
My problem is that 4 out of 5 times the reply from the DS1621 is 255 and only 1 of 5 times it's the correct temperature.
The problem also exists if im using only one transmitter.
My wires from the AVR to the DS1621 is app 25 cm (10 inch)
I have pull up resistors on both SDA and SCL
I have a 100mF cap on the supply to the 1621.
Any ideas to solve the problem ??
Kind regards
Anders |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Fri May 13, 2005 2:46 pm Post subject: |
|
|
Hi,
sorry it is a little bit complex and long, but when you understand it is very simple:
we have a function "XA" to drive all kind of I2C modules we use, more we use it to check if we have'nt any error
sorry but the name of variable are in french, I will translate in some..weeks, months, years...??
good luck
JP
---------------------------------------------------------
I work in decimal
at the end see the sub and function XA...
'----[Thermostat]---------------------
Sub Thermostat(btemper As Byte , Byval Etat As Byte )
' we want a thermostat working with + or - 1 degree C
'btemper is the high level
'low level = btemper-1
'etat 1= output active =1 heating if t° < btemper
'etat 0 =sortie passive =0 no heating if t°>Btemper
Adresse_fonction = Ds1621 'here 144, a constant
'---(configuration)----------------------
Commande = 172 'configuration of DS1621
Arg1 = Etat : Arg2 = 0 : Arg3 = 0 : Arg4 = 0 : Arg5 = 0
Statusmodule = Xa(commande , Adresse_fonction , Longueur , Arg1 , Arg2 , Arg3 , Arg4 , Arg5)
'---set thermostat high-----------------
Commande = 161
Arg1 = Btemper : Arg2 = 0 : Arg3 = 0 : Arg4 = 0 : Arg5 = 0
Statusmodule = Xa(commande , Adresse_fonction , Longueur , Arg1 , Arg2 , Arg3 , Arg4 , Arg5)
'---set thermostat low------------------
Commande = 162
Btemper = Btemper - 1
Arg1 = Btemper : Arg2 = 0 : Arg3 = 0 : Arg4 = 0 : Arg5 = 0
Statusmodule = Xa(commande , Adresse_fonction , Longueur , Arg1 , Arg2 , Arg3 , Arg4 , Arg5)
'---- start conversion------------------
Commande = 238
Arg1 = 0 : Arg2 = 0 : Arg3 = 0 : Arg4 = 0 : Arg5 = 0
Statusmodule = Xa(commande , Adresse_fonction , Longueur , Arg1 , Arg2 , Arg3 , Arg4 , Arg5)
End Sub
'------['reading temperature]-------------------------------------------------
Function Lecture_temp(byval Adresse_fonction As Byte)as String * 4
'Dim Val_temp As String * 4
For Dummy = 1 To 6 clearing of the array
Byterecu(dummy) = 0 'an array of byte reception of I2C line, see function reading...
Next
Commande = 170 'reading
Arg1 = 0 : Arg2 = 0 : Arg3 = 0 : Arg4 = 0 : Arg5 = 0
Statusmodule = Xa(commande , Adresse_fonction , Longueur , Arg1 , Arg2 , Arg3 , Arg4 , Arg5)
Val_temp = Str(byterecu(1)) 'the whole value
If Byterecu(2) = 128 Then
Val_temp = Val_temp + ",5" 'adding of the decimal value
Else
Val_temp = Val_temp + ",0" 'adding of the decimal value
End If
Lecture_temp = Val_temp
End Function
'-----[Xa function]-------also use to drive motors--------------------
Function Xa(byval Commande As Byte , Byval Adresse As Byte , Byval Longueur As Byte , Byval Arg1 As Long , Byval Arg2 As Long , Byval Arg3 As Long , Byval Arg4 As Long , Byval Arg5 As Byte ) As Byte
Gosub Compose_ecrit
Gosub I2c_ecrit
Statusmodule = Lit()
If Statusmodule > 5 Then
Locate 3 , 1 : Lcd "XA=" ; Statusmodule
End If
End Function
'------writing ---------------------------------------------------
Compose_ecrit:
For Lbyte = 1 To 6
Message_tableau(lbyte) = "" 'cleaning of the array
Next
'-----------debut------------------------------
Adresse = Adresse_fonction
Longueur_ecrit = 1
Message_tableau(longueur_ecrit ) = Chr(adresse)
'-----commande---------------------------
Longueur_ecrit = Longueur_ecrit + 1
Message_tableau(longueur_ecrit ) = Chr(commande)
'-------arguments--------------------------
Gosub Argument
Return
'--------------------------------
Argument:
Select Case Commande
Case 1 To 12
Return
Case 20 To 22
Jbyte = Arg1
Longueur_ecrit = Longueur_ecrit + 1
Message_tableau(longueur_ecrit ) = Chr(jbyte)
Case 30
Valeur = Arg1
Ecrit_word Valeur
Case 40
Valeur = Arg1
Ecrit_long Valeur
Case 101 'lecture
Longueur = 3
Case 103 'lecture
Longueur = 5
Case 161 To 162 ' réglage haut et bas du thermostat DS1621
Jbyte = Arg1
Longueur_ecrit = Longueur_ecrit + 1
Message_tableau(longueur_ecrit ) = Chr(jbyte)
Jbyte = Arg2
Longueur_ecrit = Longueur_ecrit + 1
Message_tableau(longueur_ecrit ) = Chr(jbyte)
Case 170 'lecture température thermostat DS1621
Longueur = 3
Case 172 'initialisation du thermostat DS1621
Jbyte = Arg1
Longueur_ecrit = Longueur_ecrit + 1
Message_tableau(longueur_ecrit ) = Chr(jbyte)
Case 204 To 205
Return
Case 238 'pour le thermostat DS1621
Return
End Select
Return
'------Ecriture I2C---------------------------------------------------
I2c_ecrit:
I2cstart ' Envoi I2C Start.
For Jbyte = 1 To Longueur_ecrit
I2cwbyte Message_tableau(jbyte)
Next
If Err <> 0 Then ' controle le status de l'operation.
Locate 1 , 9 : Lcd "Err.ec" ; Asc(message_tableau(1))
End If
I2cstop ' Fin de la sub d'écriture
Waitms 10 ' Atente pour la fin de l'écriture
Return
'-----lecture I2C ------------------------------------------------------
Function Lit() As Byte
Local Badresse As Byte , Blongueur As Byte
Badresse = Adresse_fonction * 2 : Badresse = Badresse + 1
I2cstart
I2cwbyte Badresse
For Blongueur = 1 To Longueur
I2crbyte Byterecu(blongueur) , Ack ' lecture...
Next
I2crbyte Byterecu(20) , Nack
If Err <> 0 Then ' controle le status de l'operation.
Locate 2 , 10 : Lcd "Err.Lect" ; ' Report failure.0
End If
I2cstop ' Fin de la sub de lecture
Lit = Byterecu(20)
End Function _________________ pleasure to learn, to teach, to create |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|