Sie sind auf Seite 1von 4

DS18X20 with AVR

Demo application to read DS1820, DS18S20 and DS18B20 temperature-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 DS18x20routines 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 OWBus (no rom-search needed), added demo using this function 10. Mar. 2005 - Version 0.7, added functions to access the internal DS18x20 EEPROM 01. Oct. 2009 - Version 0.8, Minor update (addtional delay ow_bit_io, using avrlibc delay, AVRStudio workspace) 25. June 2010 - Version 0.9, Major modifications, see comments in source. Thanks to Karol Zdunski and Sascha Schade from suggestions and patches. 17. July 2010 - Version 0.9.1, Improved recovery-time handling when parasite power is used. Thanks to Jrgen Liegner for the report and suggestions. 9. Feb. 2011 - Version 0.9.2, added fix in format-function. Thanks to Marian Kulesza.

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: # in Bus :2 : FC:28 (18B)SN: Sensor# 1 is a DS18B20 which Sensor# 2 is a DS18B20 which

67 44 is is

C6 6B 00 00 00 CRC:E2 D7 6B 00 00 00 CRC:BC parasite powered externally powered

CRC O.K. CRC O.K.

Convert_T and Read for every Sensor (reverse order) Sensor# 2 = +20.9375C [+20.9C] Sensor# 1 = +20.8750C [+20.9C] Convert_T for all Sensors and Read for single Sensor Sensor# 1 = +20.8750C [+20.9C] Sensor# 2 = +20.9375C [+20.9C] 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.8750C 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.9375C

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 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.8125C [+21.8C] Convert_T and Read Sensor by Sensor (reverse order) Sensor# 1 = +21.8125C [+21.8C] Convert_T for all Sensors and Read Sensor by Sensor Sensor# 1 = +21.8125C [+21.8C] 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.8125C

CRC O.K.

Version 0.9
DS18X20 1-Wire-Reader Demo by Martin Thomas -------------------------------------------

Scanning Bus for DS18X20 1 DS18X20 Sensor(s) available: # in Bus :1 : FC:28 (18B)SN: F9 E1 6B 00 00 00 CRC:E9 Sensor# 1 is a DS18B20 which is parasite powered DS18x20 EEPROM support test for fist sensor TH/TL from EEPROM sensor 1 : 155 / 150 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 : 156 / 151 There is only one sensor -> Demo of "DS18X20_read_decicelsius_single": 232 deciC, +23.2 C Convert_T and Read Sensor by Sensor (reverse order) Sensor# 1 = 232 deciC, +23.2 C Convert_T for all Sensors and Read Sensor by Sensor Sensor# 1 = 232 deciC, +23.2 C Sensor# 1 = 231875 Ce-4, +23.1875 C

CRC O.K.

Verbose output FC:28 (18B)SN: F9 E1 6B 00 00 00 CRC:E9 CRC O.K. SP:74 01 9C 97 7F FF 0C 10 CRC:87 CRC O.K. T_raw=0174 B20/12 +23.2500C conv: 233 deciC fmt: +23.3 C

DS18X20 1-Wire-Reader Demo by Martin Thomas ------------------------------------------Scanning Bus for DS18X20 2 DS18X20 Sensor(s) available: # in Bus :1 : FC:28 (18B)SN: F9 E1 6B 00 00 00 CRC:E9 CRC O.K. # in Bus :2 : FC:10 (18S)SN: 7E 26 88 00 08 00 CRC:A7 CRC O.K. Sensor# 1 is a DS18B20 which is parasite powered Sensor# 2 is a DS18S20/DS1820 which is parasite powered DS18x20 EEPROM support test for first sensor TH/TL in scratchpad of sensor 1 now : 41 / 41 TH+1 and TL+1 written to scratchpad TH/TL in scratchpad of sensor 1 now : 42 / 42 scratchpad copied to DS18x20 EEPROM TH and TL in scratchpad set to 0 TH/TL in scratchpad of sensor 1 now : 0 / 0 DS18x20 EEPROM copied back to scratchpad TH and TL verified TH/TL in scratchpad of sensor 1 now : 42 / 42 Convert_T and Read Sensor by Sensor (reverse order) Sensor# 2 = 244 deciC, +24.4 C Sensor# 1 = 243 deciC, +24.3 C Convert_T Sensor# 1 Sensor# 2 Sensor# 1 for all Sensors and Read Sensor by Sensor = 243 deciC, +24.3 C = 244 deciC, +24.4 C = 243125 Ce-4, +24.3125 C

Sensor# 2 = 244375 Ce-4, +24.4375 C Verbose output FC:28 (18B)SN: F9 E1 6B 00 00 00 CRC:E9 CRC O.K. SP:85 01 2A 2A 7F FF 0B 10 CRC:9B CRC O.K. T_raw=0185 B20/12 +24.3125C conv: 243 deciC fmt: +24.3 C FC:10 (18S)SN: 7E 26 88 00 08 00 CRC:A7 CRC O.K. SP:31 00 67 62 FF FF 05 10 CRC:30 CRC O.K. T_raw=0031 S20/09 +24.4375C conv: 244 deciC fmt: +24.4 C

Test with AVR internal pull-up resistor instead of external: DS18X20 1-Wire-Reader Demo by Martin Thomas ------------------------------------------Scanning Bus for DS18X20 2 DS18X20 Sensor(s) available: # in Bus :1 : FC:28 (18B)SN: F9 E1 6B 00 00 00 CRC:E9 CRC O.K. # in Bus :2 : FC:10 (18S)SN: 7E 26 88 00 08 00 CRC:A7 CRC O.K. Sensor# 1 is a DS18B20 which is parasite powered Sensor# 2 is a DS18S20/DS1820 which is parasite powered DS18x20 EEPROM support test for first sensor TH/TL in scratchpad of sensor 1 now : 50 / 50 TH+1 and TL+1 written to scratchpad TH/TL in scratchpad of sensor 1 now : 51 / 51 scratchpad copied to DS18x20 EEPROM TH and TL in scratchpad set to 0 TH/TL in scratchpad of sensor 1 now : 0 / 0 DS18x20 EEPROM copied back to scratchpad TH and TL verified TH/TL in scratchpad of sensor 1 now : 51 / 51 Convert_T and Read Sensor by Sensor (reverse order) Sensor# 2 = 247 deciC, +24.7 C Sensor# 1 = 242 deciC, +24.2 C Convert_T Sensor# 1 Sensor# 2 Sensor# 1 Sensor# 2 for all Sensors and Read Sensor by Sensor = 242 deciC, +24.2 C = 248 deciC, +24.8 C = 241875 Ce-4, +24.1875 C = 247500 Ce-4, +24.7500 C

Verbose output FC:28 (18B)SN: F9 E1 6B 00 00 00 CRC:E9 CRC O.K. SP:83 01 33 33 7F FF 0D 10 CRC:E0 CRC O.K. T_raw=0183 B20/12 +24.1875C conv: 242 deciC fmt: +24.2 C FC:10 (18S)SN: 7E 26 88 00 08 00 CRC:A7 CRC O.K. SP:32 00 6A 65 FF FF 10 10 CRC:FD CRC O.K. T_raw=0032 S20/09 +24.7500C conv: 248 deciC fmt: +24.8 C

Das könnte Ihnen auch gefallen