Category

PARTS: 1-WIRE temperature SENSOR (DS1822)

Download: buspirate.v0d.zip

Dallas/Maxim’s 1-Wire protocol is the most requested addition to the Bus Pirate.  We lastly got some 1-Wire parts, and today we’ll demonstrate the DS1822 1-Wire digital thermometer. grab the datasheet (PDF) and comply with along.

This publish is gone along with by release v.0d of the Bus Pirate firmware for hardware version 0. This includes the new 1-Wire protocol library, more configuration options, and other improvements.

DS1822 economic climate digital Thermometer (Digikey #DS1822+-ND, $3.87) We discovered a footprint in the 1-wire library for Eagle on the Cadsoft download page.

The 1-Wire protocol utilizes a single cable for data transfer, and sometimes power. data is transferred in time-sensitive ‘slots’ since there isn’t a separate clock to delineate bit periods.

Πειρατής λεωφορείων

DS1822

Sda

DQ

+ 5volts
Vdd

Εδαφος

ΓΕ

The DS1822 connections are shown in the table. We utilized the Bus Pirate’s 5volt supply to power the DS1822, however it also works at 3.3volts. A resistor (R1, ~5K) holds the bus high.

All 1-Wire commands begin with a reset procedure, complied with by one of five ROM commands.

Εντολή
Περιγραφή

0x33
READ ROM. checked out single gadget address.

0x55
MATCH ROM. match gadget address, complied with by 64bit address.

0xCC
SKIP ROM. Address all gadgets together.

0xEC
ALARM SEARCH. browse for alarm condition.

0xF0
SEARCH ROM. part of address enumeration procedure.

ROM commands are explained on page 10 of the datasheet. All ROM commands are offered as macros in the Bus Pirate 1-Wire library, see (0) for a menu. ROM command macros include the 1-Wire bus reset procedure.

Single device

All 1-Wire gadgets have a unique 64bit (8 byte) address, and some 1-Wire gadgets are utilized solely to provide electronics a unique tracking number. When a single gadget is linked to a 1-Wire bus, the checked out ROM command will extract its address.

1-WIRE>{ 0x33 r:8 <–command xxx 1WIRE BUS RESET OK xxx 1WIRE WRITE: 0x33 <–READ ROM xxx 1WIRE bulk READ, 0x08 BYTES: 0x22 0x47 0x45 0x22 0x00 0x00 0x00 0x29 <–ID# 1-WIRE>

The command sends a bus reset ({), the checked out ROM command (0x33), and reads the 64bit address (r:8, 8 bytes *8bits/byte=64bits).

The very first byte (0x22) determines this as a DS1822 thermometer. The next 6 bytes are unique to this device, and the final byte is a CRC of the previous 7 bytes.

Now we can address the gadget with the match ROM command and send it further instructions.

1-WIRE>{ 0x55 0x22 0x47 0x45 0x22 0x00 0x00 0x00 0x29 0x44
xxx 1WIRE BUS RESET OK
xxx 1WIRE WRITE: 0x55<–MATCH ROM command xxx 1WIRE WRITE: 0x22<–start address xxx 1WIRE WRITE: 0x47 xxx 1WIRE WRITE: 0x45 xxx 1WIRE WRITE: 0x22 xxx 1WIRE WRITE: 0x00 xxx 1WIRE WRITE: 0x00 xxx 1WIRE WRITE: 0x00 xxx 1WIRE WRITE: 0x29 xxx 1WIRE WRITE: 0x44 <–start conversion 1-WIRE>

First, we send the match ROM command (0x55) and the gadget address (8 bytes).  next is the convert T command (0x44, datasheet page 11) that starts the temperature conversion.

A second command sequence retrieves the temperature reading from the DS1822.

1-WIRE>{ 0x55 0x22 0x47 0x45 0x22 0x00 0x00 0x00 0x29 0xbe r:9
xxx 1WIRE BUS RESET OK
xxx 1WIRE WRITE: 0x55
xxx 1WIRE WRITE: 0x22
…long 1-Wire address…
xxx 1WIRE WRITE: 0x29
xxx 1WIRE WRITE: 0xBE <–read scratchpad command xxx 1WIRE bulk READ, 0x09 BYTES: 0x71 0x01 0xFF 0x00 0x7F 0xFF 0x0F 0x10 0xF8 1-WIRE>

The checked out SCRATCHPAD command (0xBE, datasheet page 11) returns 9 bytes. We only care about the very first two bytes, the rest can be decoded according the the table on page 7 of the datasheet. temperature is calculated according to page 4 of the datasheet: 0x0171 HEX=369 DEC, 369*0.0625=23C  (74F).

Multiple devices

When several 1-Wire gadgets share a bus it’s more difficult to determine all the addresses. The fastest method to discover connected gadgets is with the browse ROM command (0xF0) and a binary branching procedure. The Bus Pirate automates this with macro (240).

1-WIRE>(240) <–macro 240 xxx 1WIRE ROM COMMAND: browse (0xF0) Βρέθηκαν gadgets σε: Macro     1-WIRE address 1.0×22 0x50 0x28 0x22 0x00 0x00 0x00 0x0A <–address *DS1822 Econ Dig Therm <–type according to household code 2.0×22 0xD0 0xC7 0x1A 0x00 0x00 0x00 0x01 *DS1822 Econ Dig Therm 3.0×22 0x47 0x45 0x22 0x00 0x00 0x00 0x29 *DS1822 Econ Dig Therm Found 0x03 devices. The very first 10 gadget IDs are offered by MACRO, see (0). 1-WIRE>

The browse ROM command shows the gadgets it found, and the type according to the household code.

We believe typing 8 byte 1-Wire addresses is truly tedious, so the very first 10 gadget addresses are kept in memory and can be accessed with the macros (1)…(10). A buffer for as much as 50 gadget addresses can be defined in the 1-Wire library at compile time. Ideally, this data will be kept in a worldwide scratch buffer shared by all modules in a future firmware update.

1-WIRE>(0) <–show macro list 0.macro μενού Macro     1-WIRE address <–enumerated gadget addresses 1.0×22 0x50 0x28 0x22 0x00 0x00 0x00 0x0A *DS1822 Econ Dig Therm 2.0×22 0xD0 0xC7 0x1A 0x00 0x00 0x00 0x01 *DS1822 Econ Dig Therm 3.0×22 0x47 0x45 0x22 0x00 0x00 0x00 0x29 *DS1822 Econ Dig Therm 1-WIRE ROM COMMAND MACROs:<–normal commands 51.READ ROM (0x33) *for single gadget bus 85.MATCH ROM (0x55) *followed by 64bit address 204.SKIP ROM (0xCC) *followed by command 236.ALARM browse (0xEC) 240.SEARCH ROM (0xF0) 1-WIRE>

The macro menu (0) will also include the gadget addresses kept in the roster. now we can just address gadgets by macro, rather than typing the whole 64bit address every time.

1-WIRE>(85) (1) 0x44 <–start conversion xxx 1WIRE BUS RESET OK xxx 1WIRE compose ROM COMMAND: match (0x55) *follow with 64bit address xxx 1WIRE ADDRESS MACRO 1: 0x22 0x50 0x28 0x22 0x00 0x00 0x00 0x0A xxx 1WIRE WRITE: 0x44 1-WIRE>(85) (1) 0xbe r:9 <–fetch reading xxx 1WIRE BUS RESET OK xxx 1WIRE compose ROM COMMAND: match (0x55) *follow with 64bit address xxx 1WIRE ADDRESS MACRO 1: 0x22 0x50 0x28 0x22 0x00 0x00 0x00 0x0A xxx 1WIRE WRITE: 0xBE xxx 1WIRE bulk READ, 0x09 BYTES: 0x81 0x01 0x4B 0x46 0x7F 0xFF 0x0F 0x10 0x71 1-WIRE>

(85) is a shortcut for a bus reset and match ROM command. (1) is the gadget address macro, and 0x44 is the command to begin a temperature conversion. Retrieving the reading includes the exact same macros, however substitutes the command to checked out the gadget (0xBE) and grabs 9 bytes (r:9). The temperature is 0x0181, or 24C next to the PC fan.

Το παίρνω περαιτέρω

We utilized the Bus Pirate to provide a visual presentation of the 1-Wire protocol, however the genuine difficulty is integrating it into your own design. Maxim provides example code, Microchip has an app note (PDF), and you can inspect out the example code we used.

Firmware download: buspirate.vod.zip