DS18x20 Temperature-Sensors readout with AVR
发布: 2009-9-14 15:02 | 作者: 玲珑 | 查看: 68次
DS18X20 with AVR
Demo application to read DS1820, DS18S20 andDS18B20temperature-sensors with an Atmel AVR controller. 1Wire-Bus with several devices on the wire supported, parasite power-supply supported without external FET ("strong-pullup" sourced from AVR-Portpin). The source-code is for avr-gcc/avr-libc. The 1-Wire- and DS18x20- routines may be used as "library" for own developments. 1-Wire-Bus I/O-Pin can be changed during runtime.Credits: Peter Dannegger (some DS18x20- and most of the 1wire-code), Peter Fleury (uart-library), Colin O'Flynn (CRC-code)
P. Fleury's uart-library and P. Danneggers 1-Wire code have been slightly extended. There is not too much left from P. Dannegger's DS18x20-code but it has been the base for the presented "project". Used C. O'Flynns CRC8-Code only.
Changelog
- 20. Sept. 2004 - Version 0.5
- 30. Sept. 2004 - Version 0.6.1
- 03. Oct. 2004 - Version 0.6.3, Run-time-config of 1-wire-bus, improved timeing
- 24. Nov. 2004 - Version 0.6.4, Extended measurements for DS18(S)20 contributed by Carsten Foss (CFO)
- 02. Feb. 2005 - Version 0.6.5, added function to read single sensor on OW-Bus (no rom-search needed), added demo using this function
- 10. Mar. 2005 - Version 0.7, added functions to access the internal DS18x20 EEPROM
Hardware
- Atmel AVR-Controller (ATmega16 and ATmega32 @ 1MHz, 2MHz, 4MHz, 8MHz internal R/C and 1,8432 MHz, 3.6864MHz ext. XTAL used for testing)
- DS18X20 temperature-sensors (3 DS18B20 used during development)
- 4,7 kOhm pull-up resistor for 1-Wire data-line
- UART-connection to PC
Demo-Output
Version 0.6.x with two DS18B20
DS18X20 1-Wire-Reader Demo
--------------------------
Scanning Bus for DS18X20
2 DS18X20 Sensors available:
# in Bus :1 : FC:28 (18B)SN: 67 C6 6B 00 00 00 CRC:E2 CRC O.K.
# in Bus :2 : FC:28 (18B)SN: 44 D7 6B 00 00 00 CRC:BC CRC O.K.
Sensor# 1 is a DS18B20 which is parasite powered
Sensor# 2 is a DS18B20 which is externally powered
Convert_T and Read for every Sensor (reverse order)
Sensor# 2 = +20.9375°C [+20.9°C]
Sensor# 1 = +20.8750°C [+20.9°C]
Convert_T for all Sensors and Read for single Sensor
Sensor# 1 = +20.8750°C [+20.9°C]
Sensor# 2 = +20.9375°C [+20.9°C]
Verbose output
FC:28 (18B)SN: 67 C6 6B 00 00 00 CRC:E2 CRC O.K.
SP:4E 01 4B 46 7F FF 02 10 CRC:D9 CRC O.K.
T_raw=014E B20/12 +20.8750°C
FC:28 (18B)SN: 44 D7 6B 00 00 00 CRC:BC CRC O.K.
SP:4F 01 4B 46 7F FF 01 10 CRC:CF CRC O.K.
T_raw=014F B20/12 +20.9375°C
Version 0.7 with one DS18B20
DS18X20 1-Wire-Reader Demo by Martin Thomas
-------------------------------------------
Scanning Bus for DS18X20
1 DS18X20 Sensor(s) available:
# in Bus :1 : FC:28 (18B)SN: 44 D7 6B 00 00 00 CRC:BC CRC O.K.
Sensor# 1 is a DS18B20 which is externally powered
DS18x20 EEPROM support test for first sensor
TH/TL from EEPROM sensor 1 : 140 / 141
TH+1 and TL+1 written to scratchpad
scratchpad copied to DS18x20 EEPROM
DS18x20 EEPROM copied back to scratchpad
TH and TL verified
TH/TL from EEPROM sensor 1 now : 141 / 142
There is only one sensor -> Demo of "read_meas_single":
+21.8125°C [+21.8°C]
Convert_T and Read Sensor by Sensor (reverse order)
Sensor# 1 = +21.8125°C [+21.8°C]
Convert_T for all Sensors and Read Sensor by Sensor
Sensor# 1 = +21.8125°C [+21.8°C]
Verbose output
FC:28 (18B)SN: 44 D7 6B 00 00 00 CRC:BC CRC O.K.
SP:5D 01 8D 8E 7F FF 03 10 CRC:BD CRC O.K.
T_raw=015D B20/12 +21.8125°C
Software/Source-Code
- Download the Source-Archive of Version 0.7 (20050310)
- Download the Source-Archive of theoldVersion 0.6.5 (20050214)
(Hex-file for ATmega16@3,6864MHz included, 1-Wire data-pin PD6, remind the 1-wire pull-up between PD6 and VCC.)



