- - - HOME
- - - -
MICROLAN PROGRAMMING TUTORIALS INDEX
- - - - -
Other material for programmers
- - - - - - - MICROLAN CENTRAL: More general 1-Wire Information (Less focused on programming)
Programming systems to work with Dallas MicroLan (aka 1-wire) devices
Click here if you want to know more about the source
and format of these pages.
Have you heard of the 1-Wire family of ICs produced by Dallas, now part of Maxim?
Are you a programmer?
Wanting to write programs to make the 1-Wire chips "do their things"?
Then read on!
Or maybe you are interested in 1-Wire... but not yet ready to be writing your own software? If so, there is material for you at my main 1-Wire page.
Welcome fellow programmer!
MicorLans aren't "easy"... but how could they be, given their incredible power?
Are they here to stay? The people who run public transport in Istanbul obviously think so... to use it, even a casual tourist uses a 1-Wire iButton "purse", called an "Akbil", in which you store money for paying your fares. (Search of "akbil Istanbul" if you want to know more.)
What programming language do you use? Most of what I have on the web is slated towards the Delphi user. The page you are reading at the moment is "language neutral".
In a moment, I will give you an overview of writing applications for 1-Wire. Elsewhere I have more general discussions of what you can do with 1-Wire. I also have a "key-stroke-by-keystroke" guide to getting your first MicroLan up and running, i.e. the installation issues. And I have more detailed guides to programming for specific chips, e.g. temperature sensors, and the wonderful DS2438, with it's multiple functions... ADC and temperature sensing, among them. There are also 1-Wire chips with memory... in fact many of the chips "for" other things have small memories, for storing things like the label that should be associated with data from that chip.
Still reading, I see... great. Walk before you run... get yourself an adapter (I like the iButtonLink device... but beware: it puts 5v on a pin of the connector that is undefined in the Dallas spec. Useful! But you need to know it is there, and not have the wrong thing connected elsewhere on that line!) and a temperature sensor, and get a MicroLan up and running with just that and the free "try it out" software that you can download for free from Dallas. I'll loan you a sensor, ready connected to an RJ plug, which just plugs into any adapter I've ever seen, if you need that. (There will be a small charge for postage, and I'll need a $25 deposit... but don't let that be a big deal. I accept PayPal backed by an account. (Not PayPal backed by only a credit card... they charge more than I'll pay for passing on money from that source.)) Or just source and make your own... not hard! (Please don't ask for the loaner if you are just "thinking about" trying 1-Wire. Contact me about the loaner AFTER you order your adapter!)
Having got a working MicroLan (that's what you did if you followed the steps in the previous paragraph) you are now ready to write your own programs to do things. Well, you will be when you've downloaded the free SDK, but that's no big deal, and covered elsewhere.) This essay is just to try to convey the overall "shape" of the 1-Wire programmer's task...
Keep the Big Picture in mind.... With 1-Wire....
You have two areas to master. You need to understand the operation of the 1-Wire chips. You really do, sorry, have to master reading their data sheets. And you have to master the TMEX... the API that allows you to write computer programs to send things to, and read things from, MicroLans. (I've defined "MicroLan" a bit farther down the page.)
This has more about understanding the operation of the chips than about mastering TMEX.
Operation of chips...
First: You need to know that every chip has its own number, like cars have license plate numbers. I don't mean each FAMILY of chips... EACH chip has a different number, even two chips of the same part number. In the Dallas data sheets... and you do need to learn how to read them... which is mostly about learning what (vast) bits you can just skip over... this is sometimes called the "registration number" or "64 bit lasered ROM" (That term "ROM" appears in all sorts of places, and, to my reading, is used various ways. The multiple usage can be confusing.) By the way... while you "should" master and use the CRC code (you'll see stuff about it in data sheets), you can leave that for "later". One of the things to ignore... while you are getting started.)
Second: How you talk to 1-Wire chips:
All the 1-Wire chips in your system are connected in parallel to each other and to "the Master" (a PC, or some other source of programmable silicon control) via one wire, and a ground wire. This eponymous "one wire" is sometimes called Dallas "DQ", or "the 1-Wire bus". It is also sometimes called the "Dallas", or "1W" "Data/Power" line.
To use the MicroLan, you cause the Master to "do a reset". (That term crops up a couple of places in 1-Wire, and more in computing generally, and has lots of different meanings! Here we are talking about the Master (the PC with your application running in it, controlling the MicroLan) sending a "message" out over the "one wire". It is "seen" by all the 1-Wire chips, and causes them to return to their "just switched on" state. (The MicroLan "reset" (message) causes a "reset" (go back to a basic state) in all of the chips attached to the MicroLan. A reset of a 1-wire chip does NOT, by the way take it all the way back to the state it was when it was powered up. That would be a "hard reset". It just gets it to a particular point in the flow-chart of its operation. NOT (always) lost in a reset, for instance, would be the contents of the chip's memory. (Yes... there are 1-Wire chips with memory... both volatile and non volatile... but that's another story!) (I had to say "not (ALWAYS)..." because some chips purge some things on the 1-Wire reset, others don't.)
Sidebar: All messages to the chips on the MicroLan are similar to Morse code. The Master, through the adapter, NORMALLY keeps the voltage on DQ (the "one wire") at 5v. And normally all of the 1-Wire chips are just "listening", i.e. monitoring the state of that wire where it connects to them.
However, sometimes the master "switches it off", aka "pulls the voltage on that wire low". It does so for precisely timed intervals, and sometimes more than once. The pattern of the lows has an effect on the attached 1-wire chips. They interpret the pattern of the lows as a command or as data from the Master.
Now... in most operations... the first series of lows say....
a) "Reset" yourself (as already described). This gets everyone "listening"
then usually the master "says"....
"Unless you are chip number (xxx), turn yourself off again". This seems a bit unwieldy, perhaps... but it is how things are done. To recap: The messages from the Master are: "Everyone: wake up. Now, everyone but one: Go back to sleep again"! While "asleep", the 1-Wire chips ignore anything passing over DQ, EXCEPT a "reset" command.
b) The Master, having "got the attention of (just) the chip it wants then sends some more "Morse". (Actually, when you become a more advanced 1-Wire programmer, you will find that you can even address messages to groups of chips... but we'll stick with the simple "talk to one chip at a time" here.) What the Master sends will depend on what sort of chip it is talking to. There is a chip (DS2406) which has an "extra" pin (in the TO-92 ("transistor") package... two extra pins in the TSOC (6 leg SMT) package). That pin can be used to switch external things on and off. Or you can "read", across the MicroLan, the "state" (high or low) of that pin, if you've wired different external things to it.
Sadly, that wonderful flexible operation comes at a price. For my first pass through this, I'm going to pretend that the chip doesn't have the flexibility. Or the second pin of the TSOC package.) I'm going to pretend that the chip is only capable of switching that extra pin on or off.
Continuing section "b" of this discussion....
Every 1-Wire chip understands the "reset" command. The other commands it understands varies from chip to chip, but they follow patterns. Master one chip, and you've made a start on others.
Pressing on with my simplified "DS2406". It would be able to accept a "switch external device on" command, and a "switch it off" command.
To program your PC to issue the "Reset" and the "DS2406- turn external pin on/off" commands, you would use the routines provided by the TMEX API.
Of course, nothing is ever simple, and using the TMEX to talk to chip number "47000000227B3826" is a bit more than....
... but, with a few "housekeeping" overheads (e.g. connecting the PC to the adapter, which connects the MicroLan to the PC. Etc), the fundamental principles of using 1-Wire are that simple.
(Those are pseudo TMEX commands. There are no actual "SendCommand" or "SendReset" routines.... but there are things that do those jobs.)
So far so good, I hope.
c) Messages FROM chips on the MicroLan.
The Master is always in control. Think old fashioned schoolroom. The children speak when spoken to. (That's a good analogy, actually. There's even a mechanism for "the children" to "raise their hands", by the way!)
Let's look at a chip that can READ (as opposed to set, which we've covered) an extra pin of its package. From time to time, after establishing which chip it is talking to, the Master can "say", "Okay, now tell me the state of your external pin". After issuing that command, the Master will change the settings in the adapter briefly. Instead of KEEPING DQ at 5v, the adapter will WEAKLY "keep" it at 5v, but in a way that allows the client chip to "pull it low". After issuing the "tell me..." command, the Master, for a time, will "listen" to DQ. The client chip will "send Morse code" by a series of lows imposed by the client on DQ, and the Master will have the answer to what it asked for.
The simplified TMEX for something like that is along the lines of....
TMEX.SendCommand(5); // "5" would mean "tell me about the pin,
//and you'd know that the right command was "5" from the
d) That's most of what you need to know. One other generally important issue is INITIALIZATION....
Some of the 1-Wire chips are capable of really clever things. Again, I'm making something up, to create a manageable example, but let's pretend that there is a temperature sensing chip with a feature I will come to in a moment.
Using that chip might work like this....
TMEX.SendCommand(5); // "5" would mean, FOR THIS CHIP,
// "tell me the temperature"
... and if you used the code above, the answer would come back in degrees Celsius.
Now, Dallas COULD... not that it would be the best way to do this... make a chip that by default returned the temperature in degrees Celsius... but returned it in Fahrenheit, if you wanted that.
Here's how it would work....
Once, after the system's hard reset arising from awaking from being fully switched off, you would do....
TMEX.SendCommand(8); // "8" would mean, FOR THIS CHIP,
// "report temperatures IN FAHRENHEIT until further notice"
You would do that once. Such things are called initializations. In my nice simple example, you don't NEED to do an init. With some chips you do.
Once you have sent the "8" command to the chip, it continues to report temperatures in Fahrenheit, even after "resets" (of the 1-Wire "everyone wake up" kind). Until told (by a different init command) otherwise, or until a power failure and subsequent re-powering.
So... your program might be.....
TMEX.SendCommand(5); // "tell me the temperature"
Hope that helps!! Apologies for ending this somewhat abruptly... other projects call! Remember that at the start of this were links to lots of other resources for 1-Wire users of different types, requirements and skill sets. Already cited there: For more on MicroLans and why they're cool, see...
My guide to MicroLan
Click here if you're feeling kind! (Promotes my site via "Top100Borland")
Ad from page's editor: Yes.. I do enjoy compiling these things for you...
hope they are helpful. However.. this doesn't pay my bills!!! If you
find this stuff useful, (and you run an MS-DOS or Windows PC) please visit my freeware and shareware page,
download something, and circulate it for me? Links on your page to
this page would also be appreciated!
--Click here to visit editor's freeware, shareware page.--
Link to Tutorials main page
Info on how to contact this page's editor, Tom Boyd.
Page tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org
If this page causes a script to run, why? Because of things like Google panels, and the code for the search button. Why do I mention scripts? Be sure you know all you need to about spyware.
....... P a g e . . . E n d s .....