PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : DS1721 mit Atmega8 auslesen



2A
21.02.2008, 16:11
Hallo Leute

Ich würde gerne einen DS1721 Temperaturfühler auslesen

Ich schließe ihn über die SCL und SDA schnittstelle an, aber wie bekomme ich die gesendete Temperatur in meinen Atmega8 um den wert an das Display weiterzugeben ?

Ich weiß nicht genau wo nach ich suchen soll, zumal mein Bascom wissen sehr mager ist.

Vielen dank
mfg. 2A

linux_80
21.02.2008, 17:19
Hallo,

Du könntest zB. im Wiki suchen, nach I2C, nach TWI, nach Bascom, nach DS1621 ...

2A
21.02.2008, 17:41
Hallo Linux

Im Forum hab ich schon den Thread über den 1621 gefunden, allerdings wusste ich nicht, ob ich das so übernehmen kann.

Ich werde mal im wiki nachschauen.

Vielen Dank

linux_80
21.02.2008, 18:08
Hallo,

die beiden sind ziemlich gleich, der DS1721 hat eine grössere Auflösung von bis zu 0,0625°C der 1621 nur 0,5°C.
Er braucht deshalb auch länger zum wandlen der Temperatur.

Näheres siehe Datenblatt.

2A
23.02.2008, 08:18
Moin
Ich habe in Bascom einen code für einen DS1624 gefunden.


$regfile = "m8def.dat" 'Define the chip you use

$baud = 19200 'Define UART BAUD rate


'Declare RAM for temperature storage
Dim I2ctemp As Byte 'Storage for the temperature


'Configure pins we want to use for the I²C bus
Config Scl = Portd.1 'Is serial clock SCL
Config Sda = Portd.3 'Is serial data SDA



'Declare constants - I2C chip addresses
Const Ds1721wr = &B10010000 'DS1624 Sensor write
Const Ds1721rd = &B10010001 'DS1624 Sensor read

'This section initializes the DS1624
I2cstart 'Sends start condition
I2cwbyte Ds1721wr 'Sends the address




'byte with r/w 0




'Access the CONFIG register (&HAC address byte)

I2cwbyte &HAC
'Set continuous conversion (&H00 command byte)

I2cwbyte &H00
I2cstop 'Sends stop condition
Waitms 25 'We have to wait some time after a stop

I2cstart
I2cwbyte Ds1721wr

'Start conversion (&HEE command byte)
I2cwbyte &HEE
I2cstop
Waitms 25
'End of initialization

Print 'Print empty line


Do

'Get the current temperature
I2cstart
I2cwbyte Ds1721wr
I2cwbyte &HAA 'Read temperature (&HAA command byte)
I2cstart
I2cwbyte Ds1721rd 'The chip will give register contents

'Temperature is stored as 12,5 but the ,5 first
I2crbyte I2ctemp

'So you'll have to read twice... first the ,5
I2crbyte I2ctemp , Nack

'And then the 12... we don't store the ,5
I2cstop
'That's why we read twice.

'We give NACK if the last byte is read

'Finally we print

Print "Temperature: " ; Str(i2ctemp) ; " degrees" ; Chr(13);

Waitms 25

Loop
End

wenn ich meinen Atmega8 damit beschrieben habe, dann bekomme ich im Terminal emulator so Zeichen:

xàø€€€€€x€xþ€xà€x€x€xþ€xxxøxøxx€xà€xüxxø xà€x€xàø€€€€€x€xþ€xà€x€x€x
þ€xxxøxøxx€xà€xüxxøxà€x€xàø€€€€€x€xþ€xà€x €x€xþ€xxxøxøxx€xà€xüxx
øxà€x€xàø€€€€€x€xþ€xà€x€x€xþ€xxxøxøxx€xà €xüxxøxà€x€xàø€€€€€x€xþ€xà
€x€x€xþ€xxxøxøxx€xà€xüxxøxà€x€xàø€€€€€x €xþ€xà€x€x€xþ€xxxøxøxx€
xà€xüxxøxà€x€xàø€€€€€x€xþ€xà€x€x€xþ€xxxøx øxx€xà€xüxxøxà€x€xàø€€€€€
x€xþ€xà€x€x€xþ€xxxøxøxx€xà€xüxxøxà€x€xà ø€€€€€x€xþ€xà€x€x€xþ€xxx
øxøxx€xà€xüxxøxà€x€xàø€€€€€x€xþ€xà€x€x€xþ€ xxxøxøxx€xà€xüxxøxà€x€
xàø€€€€€x€xþ€xà€x€x€xþ€xxxøxøxx€xà€xüxxø xà€x€xàø€€€€€x€xþ€xà€x€x€x
þ€xxxøxøxx€xà€xüxxøxà€x€xàø€€€€€x€xþ€xà€x €x€xþ€xxxøxøxx€xà€xüxx
øxà€x€xàø€€€€€x€xþ€xà€x€x€xþ€xxxøxøxx€xà €xüxxøxà€x€xàø€€€€€x€xþ€xà
€x€x€xþ€xxxøxøxx€xà€xüxxøxà€x€xàø€€€€€x €xþ€xà€x€x€xþ€xxxøxøxx€
xà€xüxxøxà€x€xàø€€€€€x€xþ€xà€x€x€xþ€xxxøx øxx€xà€xüxxøxà€x€xàø€€€€€
x€xþ€xà€x€x€xþ€xxxøxøxx€xà€xüxxøxà€x€xà ø€€€€€x€xþ€xà€x€x€xþ€xxx
øxøxx€xà€xüxxøxà€x€xàø€€€€€x€xþ€xà€x€x€xþ€ xxxøxøxx€xà€xüxxøxà€x€
xàø€€€€€x€xþ€xà€x€x€xþ€xxxøxøxx€xà€xüxxø xà€x€xàø€€€€€x€xþ€xà€x€x€x
þ€xxxøxøxx€xà€xüxxøxà€x€xàø€€€€€x€xþ€xà€x €x€xþ€xxxøxøxx€xà€xüxx
øxà€x€xàø€€€€€x€xþ€xà€x€x€xþ€xxxøxøxx€xà €xüxxøxà€x€xàø€€€€€x€xþ€xà
€x€x€xþ€xxxøxøxx€xà€xüxxøxà€x€xàø€€€€€x €xþ€xà€x€x€xþ€xxxøxøxx€
xà€xüxxøxà€x€xàø€€€€€x€xþ€xà€x€x€xþ€xxxøx øxx€xà€xüxxøxà€x€xàø€€€€€
x€xþ€xà€x€x€xþ€xxx

woran kann das liegen ? ich weiß echt nicht weiter.

Vielen Dank, Lg 2A

linux_80
23.02.2008, 12:29
Hallo,

das liegt vermutlich daran, dass die Baudrate nicht übereinstimmt.
Wahrscheinlich läuft der AVR nicht mit den angegebenen MHz die im Programm angegeben ist, bzw. steht da garnix davon !
Ich würde im Programm immer angeben wie schnell der AVR läuft ($crystal), hilft die Fehlerquelle schneller zu lokalisieren !

Vitis
23.02.2008, 12:35
$crystal = ?


*zeichenfüller*

stefan_Z
24.02.2008, 21:39
Ist eigentlich der DS1722 gleich in der Ansteuerung?
Beim DS1721 steht zum Interface:
"Data is transferred over 2-wire/SMBus interface"
Beim DS1722:
"Data is Read From/Written to Via a Motorola Serial Peripheral Interface (SPI) or Standard 3-Wire Serial Interface"
Ist SMBus gleich 2-Wire? Also zumindest elektrisch gesehen?