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.
Bus Pirate
DS1822
SDA
DQ
+ 5VOLTS
Vdd
Grond
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.
Opdracht
Beschrijving
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-draads adres <-enumereerde gadgetadressen 1,0 × 22 0x50 0x28 0x22 0x00 0x00 0x00 0x0A * DS1822 ECON DIG DERM 2.0 × 22 0xD0 0xC7 0x1A 0x00 0x00 0x00 0x01 * DS1822 ECON DIG DERM 3.0 × 22 0x47 0x45 0x22 0x00 0x00 0x00 0x29 * DS1822 ECON DIG DERM 1-draads ROM-opdracht Macro's: <- Normale opdrachten 51.Read ROM (0x33) * voor een enkele gadgetbus 85.Pch ROM (0x55) * gevolgd door 64bit-adres 204.SKIP ROM (0XCC) * Gevolgd door commando 236.Alarm bladeren (0xec) 240.Zoeken ROM (0xF0) 1-draads>
Het Macro-menu (0) omvat ook de gadgetadressen die in de selectie worden bewaard. Nu kunnen we gewoon gadgets door macro aanpakken in plaats van elke keer het hele 64bit-adres te typen.
1-draads> (85) (1) 0x44 <-start conversie XXX 1WIRE BUS RESET OK XXX 1Wire Compose ROM-opdracht: match (0x55) * Volg met 64bit adres XXX 1Wire-adres Macro 1: 0x22 0x50 0x28 0x22 0x00 0x00 0x00 0x0A XXX 1Wire Schrijf: 0x44 1-Draad> (85) (1) 0xbe R: 9 <-Krijg lezen XXX 1WIRE BUS RESET OK XXX 1Wire Compose ROM-opdracht: match (0x55) * Volg met 64bit adres XXX 1Wire-adres Macro 1: 0x22 0x50 0x28 0x22 0x00 0x00 0x00 0x0A XXX 1Wire Schrijf: 0xbe XXX 1Wire Bulk lezen, 0x09 bytes: 0x81 0x01 0x4b 0x46 0x7f 0xFF 0x0f 0x10 0x71 1-draads>
(85) is een snelkoppeling voor een busreset en match-opdracht. (1) is de macro van het gadgetadres en 0x44 is de opdracht om een temperatuurconversie te starten. Het ophalen van de lezing omvat de exact dezelfde macro’s, maar vervangt echter de opdracht om de gadget (0xbe) uit te cheque en grijpt 9 bytes (R: 9). De temperatuur is 0x0181 of 24C naast de pc-ventilator.
Het verder brengen
We gebruikten de buspiraat om een visuele presentatie van het 1-draadse protocol te verschaffen, maar de oprechte moeilijkheid integreert het in uw eigen ontwerp. Maxim biedt voorbeeldcode, Microchip heeft een app-notitie (PDF) en u kunt inspecteren in de gebruikte voorbeeldcode die we hebben gebruikt.
Firmware Download: buspirate.vod.zip