A Free Template From Joomlashack

A Free Template From Joomlashack

Sign in with a social network::

Powered by OneAll Social Login

Who is online

We have 15 guests online

Chat with us

Demystification of 1-Wire® commands PDF Print E-mail
Written by Jurij Mikeln   

Bascom-AVR has a couple of 1-Wire statements available. Many times readers call me about 1-Wire statements. Also, many times during my Bascom seminar lectures, similar questions about 1-Wire statements, like 1wiresearch, 1wirecount, 1wirenext come up. Because I have never studied these statements, I have always replied that “I have never used these statements”. One recent hot summer allowed me to rectify the situation. So, here we go: in this chapter you will read all about 1-Wire statements.

Let us briefly see how 1-Wire components perform. In Figure 1 you can see a typical connection of a 1-Wire component. Although 1-Wire elements can work normally with only 2 pins – one pin is connected to GND and the other communicates with microcontroller, I recommend using the 3-pin configuration as seen in Figure 1. The reason is that addressing a 1-Wire element using only one wire (besides ground) will take more of the processor’s time. In the case of long wires, I recommend schematic diagram shown in Figure 2, where you see the protection elements like capacitors and protective diodes.

The most well-known and commonly used 1-Wire element is certainly the DS18S20 thermometer. It’s popular because one can connect it to a microcontroller easily, it’s reliable and cheap. In addition, the DS18S20 has a digital output and many sensors can be connected in parallel on same wire. Most of you already know the basic 1-Wire commands for reading temperature from one sensor:

1wreset
 1wwrite &HCC                 ‘ignore ROM
1wwrite &H44                 ‘convert temp.
Wait 1
1wreset                         ‘reset 1-Wire bus
1wwrite &HCC                 ‘ignore ROM
1wwrite &HBE                 ‘read Scratchpad
T = 1wread(2)              ‘read 2 bytes
1wreset                          ‘reset 1-Wire bus
  T = T / 2
  Cls : Lcd “T =  “ ; _
T ; “C                            ‘display on LCD

Part of this program will display the current temperature that was measured with the DS18S20. Temperature is stored in the variable T.

The DS18S20 is being addressed with 1-Wire statements, which instruct the sensor what we want from it. I’ll assume that the comments are self explanatory. Only the Ignore ROM comment may need some explanation. The DS18S20 has a unique address (ID number) factory-programmed into it which is unique in the World – there are no two sensors with the same ID number! This address is stored within the sensor’s ROM. If we do not require this ID information, then we needn’t bother reading it, and that’s what Ignore ROM means. This example can be found in program 1Wire_1.bas.

If, however, there are more 1-Wire sensors on the 1-Wire bus then we have to read the IDs of each sensor on the bus, which makes the program a bit longer, but still short enough to be understood.

Demystification of 1-Wire® commands

2012_AVR_UK_79

Continue reading

Shop area

Last Updated on Wednesday, 01 August 2012 14:38
 
Free Joomla Templates from JoomlaShack