How do I access multiple 1-wire devices on a single pin?
Matt Armstrong
Posts: 4
As I understand it, the whole point of the 1-wire interface is to allow access to up to 64 unique devices on a single I/O pin. I am interested in using four DS2760·thermocouple sensors but cannot find any sample code that shows how to access more than one device on the same pin. All of the sample programs gather the unique ID from the device, but do not seem to make provisions for having more than one device on the I/O pin. Can anyone provide some sample code to address this?
Also, is there any way to access 1-wire devices using the Javelin stamp? I'm a software engineer by trade and specialize in desktop applications, so the syntax of PBASIC is taking some time for me to get used to, I'm much more comfortable working with OOP languages.
Thanks in advance for any help!
-Matt Armstrong
Also, is there any way to access 1-wire devices using the Javelin stamp? I'm a software engineer by trade and specialize in desktop applications, so the syntax of PBASIC is taking some time for me to get used to, I'm much more comfortable working with OOP languages.
Thanks in advance for any help!
-Matt Armstrong
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Visit the Piggyback Page
http://hometown.aol.com/newzed/index.html
·
If so, how do you modify it so that you can enumerate all the devices on the net? It seems that all the sample code expects there to be only one device conneted to an I/O pin.
I also need to figure out how to modify the code that reads the voltage and temperature from the device itself.
As you can see, the sample code seems to make no reference to the device ID. I've been playing around with the 1-Wire SDK for windows and it provides a method for enumerating devices and allows you to address individual devices.
Thanks again for any help you can give!
-Matt Armstrong
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Visit the Piggyback Page
http://hometown.aol.com/newzed/index.html
·
However, I did manage to get it up and running after a lot of playing around.......
I am sure Jon will castigate me for the messy code·· but I can post a snippet for you to try out·if you like
Regards
Alan
··
Perhaps you will find this descriptive summary of how to search for one wire devices helpful:
Begin quotation -
Finding multiple serial numbers on a 1-wire bus is certainly the most difficult operation associated with this protocol to visualize. The basic process determines the serial numbers of the devices present by successively eliminating devices from a pool of answering devices using the Search ROM command. The Search ROM command activates all devices on the bus. For each bit in the 48-bit serial number, 8-bit device number and 8-bit CRC, all currently selected devices will respond to two-bit read commands. During the first bit read time slot, all devices that have a zero in their serial number in the current bit position will respond on the bus with a zero. During the second bit read time slot, all devices that have a zero in their serial number in the current bit position will respond with a zero. These two reads have four possible outcomes. If two zeros are read (B), at least one device has a zero in that bit position and at least one device has a one in that bit position as well. If the first read returns a zero and the second returns a one, the only devices remaining on the bus have a zero in the current bit position. If the first read returns a one and the second read returns a zero, then all active devices have a one in the current bit position. Finally, if both reads return a one, then there are no devices currently active on the bus.
After reading these two bits, the bus master will transmit a zero or a one. If a one is transmitted all devices with a zero in the current bit position will drop off. If a zero is transmitted all devices with a one will drop off. By selectively dropping off duplicated bit positions, eventually a full 64-bit (48-bit serial number plus 8-bit CRC) value will have been accumulated and only one device will be left active on the bus. Once a device has been found, we repeat the process, selecting different branches each time, until all devices have been identified.
End quote
I hope you find that helpful and that it does not muddy the waters any further.
This was just something I found on the 'net and does not represent a process I have used personally. I have to agree with Jon Williams, that's one of the most convoluted and time consuming enumeration processes I've ever seen!
Regards,
Bruce Bates
In that case, how do I modify the code that reads from the device so that it can use these unique IDs? I'm still not clear on that.
Thanks!
-Matt
There are good 1-wire examples in several of the Stamp example Guides. Check out
I have tried most of these code examples with the actual device or a similar device. I ordered a sample of 8 different 1-wire devices from Dallas and have played with 7 of them. (One of the devices is a smd device and I haven't figured out how to connect to it effectively.)
The challenge will come when you connect them on a long wire. I am currently playing with a DS9097U Universal 1-Wire COM Port Adapter from Dallas (http://www.maxim-ic.com/quick_view2.cfm/qv_pk/2983). It helps a lot for short length wire runs (2-15 feet). Longer length wire runs require Dallas' The Link device (get it here http://www.aagelectronica.com/aag/index.html). The issue with the wire length is due to signal reflections and impedance mis-matches on the signal line. It's a bit tricky but doable.
I have confidence the 1-wire technolgy is reliable and powerful. Once you get by the tricky technical stuff it is fairly straight forward to work with. There are other technologies that may provide the same functionality with less headache. Check out the I2C devices. Jon Williams' comment was the I2C family had a richer feature list of devices available.
I will help with your questions if you ask.
Bob
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
······ Bob, Ottawa
W75 54 17·· N45 18 30
·········· G16 #27
I'm assuming the first line is the one that needs to change to accomodate multiple devices. The SkipNet constant is set to $CC. If I want to address just one device with a known ID, how do I do that? Let's just assume that the unique IDs are known, so searching is not necessary. Do I need to issue another command first to "activate" or "notify" the desired ID?
Thanks again!
-Matt
When you are ready to speak to a 1-wire device you notify it by sending·it's unique 64 bit address. If you have only one device then you can use the SkipROM (or SkipNet) code instead of an actual address. Every device responds when it receives a SkipROM code. If you have more than one device and you send SkipROM then all devices respond and you get communication collisions. Net result - no communication with anything.
So how do you send the device serial number? You send a MatchROM code followed by the 64 bit serial number. For example:
·· OWOUT OWpin,OW_FERst,[noparse][[/noparse]MatchROM, STR tempROM\8, ConvertTemp] ' start conversion
OWpin is the Stamp communication pin.
OW_FERst means Frontend_reset. This·is a logic level low signal·for a specific length of time triggering all devices to listen to the next command code. The stamp 1-wire instruction takes care of sending this correct logic level.
MatchROM is a command code to all devices saying "respond if your serial number·is sent next". Once the MatchROM code is sent the only device that will repsond is the device with the unique serial number. A reset signal will need to be sent to re-activate the other 1-wire devices.
So... your code:
· OWOUT OW, %0001, [noparse][[/noparse]SkipNet, RdReg, $0E]
· OWIN· OW, %0010, [noparse][[/noparse]tCuV.BYTE1, tCuV.BYTE0]
has a frontend_reset (the %0001 code) followed by a SkipNet command. The SkipNet command·is the same as a SkipROM command. (The DS2760 spec document·is the first 1-wire spec I've seen that calls·it SkipNet instead of SkipROM.) The SkipNet command says all 1-wire devices (and there should only be one) is to respond to the next command. The next command is the ReadRegister $0E command.
The OWIN line indicates to use a backend_reset (the %0010 code) meaning to reset all 1-wire devices after reading two bytes of signal data. This backend_reset is important since some devices will repond with many bytes of data and you can terminate transmission early by sending a reset signal after receiving the data you want.
You will need to replace the SkipNet command with a command like:
··MatchNet·· CON·· $55········· ' same hex value as MatchROM
· OWOUT OW, %0001, [noparse][[/noparse]MatchNet, STR tempROM\8, RdReg, $0E]····
· OWIN· OW, %0010, [noparse][[/noparse]tCuV.BYTE1, tCuV.BYTE0]
where· tempROM has the 8 byte unique serial number.
Does this answer your questions?
Bob
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
······ Bob, Ottawa
W75 54 17·· N45 18 30
·········· G16 #27