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.

Buss pirat

DS1822

SDA

DQ

+5volts
Vdd

Bakke

GND.

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.

Kommando
Beskrivelse

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) Found gadgets at: 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 menu Macro 1-wire adresse <-Eumerated gadget adresser 1,0 × 22 0x50 0x28 0x22 0x00 0x00 0x00 0x0a * DS1822 ECON DIG THM 2,0 × 22 0xD0 0xc7 0x1a 0x00 0x00 0x00 0x01 * DS1822 ECON DIG THM 3,0 × 22 0x47 0x45 0x22 0x00 0x00 0x00 0x29 * DS1822 ECON DIG THM 1-wire rom kommandoen makroer: <- normale kommandoer 51.READ ROM (0x33) * for single gadget buss 85.Match ROM (0x55) * etterfulgt av 64bitadresse 204.Skip ROM (0xcc) * etterfulgt av kommando 236.Alarm Bla gjennom (0xec) 240.Search rom (0xf0) 1-wire>

Makromenyen (0) vil også inkludere gadgetadressene som holdes i ruteren. Nå kan vi bare adressere gadgets av makro, i stedet for å skrive hele 64bit adressen hver gang.

1-wire> (85) (1) 0x44 <-start konvertering xxx 1wire buss reset OK XXX 1Wire Compose ROM-kommando: Match (0x55) * Følg med 64bitadresse XXX 1Wire Adresse Makro 1: 0x22 0x50 0x28 0x22 0x00 0x00 0x00 0x0A XXX 1Wire Skriv: 0x44 1-wire> (85) (1) 0xbe r: 9 <-fetch lesing xxx 1wire buss reset OK XXX 1Wire Compose ROM-kommando: Match (0x55) * Følg med 64bitadresse XXX 1Wire Adresse Makro 1: 0x22 0x50 0x28 0x22 0x00 0x00 0x00 0x0A XXX 1Wire Skriv: 0xbe XXX 1Wire Bulk LES, 0X09 BYTES: 0x81 0x01 0x4b 0x46 0x7f 0xff 0x0f 0x10 0x71 1-wire>

(85) er en snarvei for en Bus Reset og Match ROM-kommando. (1) er gadgetadressen makro, og 0x44 er kommandoen for å starte en temperaturomregning. Hente lesingen inkluderer nøyaktig samme makroer, men erstatter kommandoen for å sjekke ut gadgeten (0xbe) og griper 9 byte (R: 9). The temperature is 0x0181, or 24C next to the PC fan.

Tar det videre

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

Leave a Reply

Your email address will not be published. Required fields are marked *