Using the 1 WIRE protocol/de

(Difference between revisions)
Jump to: navigation, search
(Übersicht)
(Übersicht)
Line 20: Line 20:
 
<span style="font-family: 'Arial';  color: #000000">&nbsp;</span>
 
<span style="font-family: 'Arial';  color: #000000">&nbsp;</span>
  
Mit 2 Leitungen. Dann wird DQ und Ground benutzt. Die 5V-Versorgung erfolgt über die DQ-Leitung und lädt einen Kondensator im DS-Baustein. Dieser versorgt das Bauteil während der Kommunikation, wenn die Datenleitung für kurze Pulse auf Ground liegt.
+
Mit 2 Leitungen. Dann wird DQ und Ground benutzt. Die 5V-Versorgung erfolgt mit einem Pullup-Widerstand über die DQ-Leitung und lädt einen Kondensator im DS-Baustein. Der Kondensator versorgt das Bauteil während der Kommunikation, wenn die Datenleitung für kurze Pulse auf Ground liegt.
 
Dieser Bus wird 1-Wire genannt.
 
Dieser Bus wird 1-Wire genannt.
  
Line 27: Line 27:
 
<span style="font-family: 'Arial';  color: #000000">&nbsp;</span>
 
<span style="font-family: 'Arial';  color: #000000">&nbsp;</span>
  
With 3 wires, when +5V is supplied to the VDD line of the device, and DQ + ground as above. This bus is called the 2-wire bus.
+
Mit 3 Leitungen, wenn Vdd des Bauteils mit +5V versorgt wird und DQ und GND wie oben. Dieser Bus wird 2-Wire genannt.
  
 
<span style="font-family: 'Arial';  color: #000000">&nbsp;</span>
 
<span style="font-family: 'Arial';  color: #000000">&nbsp;</span>
  
So, the ground line is "not counted" by DS. But hereafter we use DS naming conventions.
+
Man sieht, daß die Ground-Leitung von DS nicht mitgezählt wird. Trotzdem benutzen wir die DS-Bezeichnungen weiterhin.
  
 
<span style="font-family: 'Arial';  color: #000000">&nbsp;</span>
 
<span style="font-family: 'Arial';  color: #000000">&nbsp;</span>

Revision as of 20:55, 20 February 2013

Contents

Übersicht

Das 1-Wire-Protokoll war eine Erfindung von Dallas Semiconductor (heute Maxim Integrated Products). Es braucht nur eine Leitung für eine 2-Wege-Kommunikation. Natürlich wird noch eine Versorgung und Ground benötigt.

 

Dieser Beitrag wurde von Göte Haluza geschrieben. Er testete die neuen 1-Wire-Suchroutinen beim Bau einer Wetterstation.

 

Dallas Semiconductor (DS) 1-wire. Dies ist eine Kurzbeschreibung des 1-Wire-Busses und dessen Umsetzung in Bascom. Für detailliertere Informationen über 1-Wire besuchen Sie bitte www.maxim-ic.com. Durch Bascom wird 1-wire einfach. Dieser Text beschreibt den Zugang zum Thema aus der Sicht des Bascom-Nutzers.

 

 

1-Wire-Net ist ein serielles Kommunikationsprotokoll, welches von DS-Geräten benutzt wird. Der Bus kann auf 2 Arten implementiert werden:

 

 

Mit 2 Leitungen. Dann wird DQ und Ground benutzt. Die 5V-Versorgung erfolgt mit einem Pullup-Widerstand über die DQ-Leitung und lädt einen Kondensator im DS-Baustein. Der Kondensator versorgt das Bauteil während der Kommunikation, wenn die Datenleitung für kurze Pulse auf Ground liegt. Dieser Bus wird 1-Wire genannt.

 

 

Mit 3 Leitungen, wenn Vdd des Bauteils mit +5V versorgt wird und DQ und GND wie oben. Dieser Bus wird 2-Wire genannt.

 

Man sieht, daß die Ground-Leitung von DS nicht mitgezählt wird. Trotzdem benutzen wir die DS-Bezeichnungen weiterhin.

 

How it works. (1-wire)

The normal state of the bus is DQ=high. Through DQ the device gets its power, and performs the tasks it is designed for.

 

When the host (your micro controller (uC)) wants something to happen with the 1-wire bus, it issues a reset-command. That is a very simple electric function that happens then; the DQ goes active low for a time (480uS on original DS 1-wire bus). This put the DS-devices in reset mode; then (they) send a presence pulse, and then (they) listen to the host.

 

The presence pulse is simply an active low, this time issued by the device(s).

 

Now, the host cannot know what is on the bus, it is only aware of that at least 1 DS device is attached on the bus.

 

All communication on the 1-wire bus is initialized by the host, and issued by time-slots of active-low on a normally high line (DQ), issued by the device, which is sending at the moment. The devices(s) internal capacitor supplies its power needs during the low-time.

 

 

How do you work with 1-wire-bus

Thereafter, you can read a device, and write to it. If you know you only have 1 sensor attached, or if you want to address all sensors, you can start with a "Skip Rom" - command. This means; take no notice about the IDs of the sensors - skip that part of the communication.

 

When you made a 1-wire-reset, all devices of the bus are listening. If you chose to address only one of them, the rest of them will not listen again before you have made a new 1-wire-reset on the bus.

 

I do not describe BASCOM commands in this text - they are pretty much self-explanatory. But the uC has to write the commands to the bus - and thereafter read the answer. What you have to write as a command depends on devices you are using - and what you want to do with it. Every DS chip has a data sheet, which you can find at http://www.dalsemi.com/datasheets/pdfindex.html. There you can find out all about the actual devices command structure.

 

There are some things to have in mind when deciding which of the bus-types to use.

 

The commands, from BASCOM, are the same in both cases. So this is not a problem.

 

The +5V power-supply on the VDD when using a 2-wire bus has to be from a separate power supply, according to DS. But it still works with taking the power from the same source as for the processor, directly on the stabilizing transistor. I have not got it to work taking power directly from the processor pin.

 

Some devices consume some more power during special operations. The DS1820 consumes a lot of power during the operation "Convert Temperature". Because the sensors knows how they are powered (it is also possible to get this information from the devices) some operations, as "Convert T" takes different amount of time for the sensor to execute. The command "Convert T" as example, takes ~200mS on 2-wire, but ~700mS on 1-wire. This has to be considered during programming.

 

And that power also has to be supplied somehow.

 

If you use 2-wire, you don't have to read further in this part. You can do simultaneously "Convert T" on all the devices you attach on the bus. And save time. This command is the most power-consuming command, possible to execute on several devices, I am aware of.

 

If you use 1-wire, there are things to think about. It is about not consuming more power than you feed. And how to feed power? That depends on the devices (their consumption) and what you are doing with them (their consumption in a specific operation).

 

Short, not-so-accurate description of power needs, not reflecting on cable lengths.

 

Only the processor pin as power supplier, will work < 5 sensors. (AVR, 1-wire-functions use an internal pull-up. 8051 not yet tested). Don't even think of simultaneous commands on multiple sensors.

 

 

With +5V through a 4K7 resistor, to the DQ-line, 70 sensors are tested. But, take care, cause issuing "Convert T" simultaneously, would cause that to give false readings. About ~15 sensors is the maximum amount of usable devices, which simultaneously performs some action. This approach DS refers to as "pull-up resistor".

 

With this in mind, a bus with up to 70 devices has been successfully powered this way.

 

The resistor mentioned, 4K7, could be of smaller value. DS says minimum 1K5, I have tested down to 500 ohm - below that the bus is not usable any more. (AVR). Lowering the resistor feeds more power - and makes the bus more noise resistant. But, the resistor minimum value is naturally also depending on the uC-pin electric capabilities. Stay at 4K7 - which is standard recommendation.

 

DS recommends yet another approach, called "strong pull-up" which (short) works via a MOS-FET transistor, feeding the DQ lines with enough power, still on 1-wire, during power-consuming tasks. This is not tested, but should naturally work. Because this functionality is really a limited one; BASCOM has no special support for that. But anyway, we tell you about it, just in case you wonder. Strong pull-up has to use one uC pin extra - to drive the MOS-FET.

 

Cable lengths

(this section is only for some limitation understanding)

For short runs up to 30 meters, cable selection for use on the 1-Wire bus is less critical. Even flat modular phone cable works with limited numbers of 1-Wire devices. However, the longer the 1-Wire bus, the more pronounced cable effects become, and therefore greater importance is placed on cable selection.

 

 

For longer distances, DS recommends twisted-pair-cable (CAT5).

 

DS standard examples show 100 meters cable lengths, so they say, that's no problem. They also show examples with 300m cabling, and I think I have seen something with 600-meter bus (but I cant find it again).

 

Noise and CRC

The longer cable and the noisier environment, the more false readings will be made. The devices are equipped with a CRC-generator - the LSByte of the sending is always a checksum. Look in program examples to learn how to re-calculate this checksum in your uC. AND, if you notice that there are false readings - do something about your cables. (Shield, lower resistor)

 

 

Transfer speed

On the original 1-wire bus, DS says the transfer speed is about 14Kbits /second. And, if that was not enough, some devices has an overdrive option. That multiplies the speed by 10. This is issued by making the communication-time-slots smaller (from 60 uS to 6uS ) which naturally will make the devices more sensitive, and CRC-error will probably occur more often. But, if that is not an issue, ~140Kbit is a reachable speed to the devices. So, whatever you thought before, it is FAST.

 

The BASCOM scanning of the bus is finds about 50 devices / second , and reading a specific sensors value to a uC should be about 13 devices / second.

 

 

Topology

Of the 1w-net - that is an issue we will not cover so much. Star-net, bus-net? It seems like you can mix that. It is a bus-net, but not so sensitive about that.

 

 

The benefit of the 1-wire bus

Each device is individual - and you can communicate with it over the media of 2 wires. Still, you can address one individual device, if you like. Get its value. There are 64 ^ 2 unique identifications-numbers.

 

Naturally, if lot of cables are unwanted, this is a big benefit. And you only occupy 1 processor pin.

 

DS supplies with different types of devices, which all are made for interfacing an uC - directly. No extra hardware. There are sensors, so you can get knowledge about the real world, and there are also potentiometers and relays, so you can do something about it. On the very same bus.

 

And the Ibutton approach from DS (ever heard of it?) is based on 1wire technology. Maybe something to pick up.

 

BASCOM let you use an uC with 1wire-devices so easy, that (since now) that also has to count as a benefit - maybe one of the largest. ;-)

 

 

Nachteile des 1-wire-Busses

Soweit bekannt, ist DS der einzige Hersteller von Sensoren für diesen Bus. Manche Leute meinen, deren Bauteile sind teuer. Bis jetzt war es wirklich schwierig, mit den Bauteilen zu kommunizieren. Insbesondere, wenn mehrere Slaves an einem Bus teilnehmen. Manche Leute sagen, der 1-wire-Bus wäre langsam, ich denke das ist nicht so.

 

 

Göte Haluza

System engineer


Languages   English Deutsch  
Retrieved from "http://wiki.mcselec.com/bavr/index.php?title=Using_the_1_WIRE_protocol/de&oldid=3574"
Personal tools
Namespaces
Variants
Actions
Navigation
In other languages
Language