[SOLVED] One Wire library, what's behind

I am trying to use several DS2401 on a single 1-wire line. For a single DS2401, I can read the 64 bits rom code using the read rom command (33h) but a soon as I have two DS2401 on the same bus, there’s collisions (normal, both wants to answer at the same time). There’s a Search rom command on the DS2401 (opcode F0h) so enumarting the number of devices is possible. However the Search_IsDevicePresent doe snot returns any true value in my case (even with a single DS2401).

What could be wrong?

using System;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.Hardware;

namespace Test
    public class Program
        public static void Main()
            //turn off buzz
            OutputPort buz = new OutputPort(EMX.Pin.IO13,false);
            buz.Write(true); Thread.Sleep(50); buz.Write(false);

            // Change this your correct pin!
            Cpu.Pin myPin = EMX.Pin.IO2;

            OneWire ow = new OneWire(myPin);
            byte[] dev1 = new byte[8];
            //dev1= 1010110001011000000011010010100000000000000000001111110111111111
            dev1[0] = byte.Parse("172"); dev1[1] = byte.Parse("88"); dev1[2] = byte.Parse("13"); dev1[3] = byte.Parse("40");
            dev1[4] = byte.Parse("0"); dev1[5] = byte.Parse("0"); dev1[6] = byte.Parse("253"); dev1[7] = byte.Parse("255");

            byte[] dev2 = new byte[8];
            dev2[0] = byte.Parse("184"); dev2[1] = byte.Parse("164"); dev2[2] = byte.Parse("117"); dev2[3] = byte.Parse("40");
            dev2[4] = byte.Parse("0"); dev2[5] = byte.Parse("0"); dev2[6] = byte.Parse("118"); dev2[7] = byte.Parse("255");

            // read every second

                        Debug.Print("Dev 1 not found");
                    else Debug.Print("Dev 1 found");
                        Debug.Print("Dev 2 not found");
                    else Debug.Print("Dev 2 found");
                    Debug.Print("Device is not detected.");


Solved, the problem was a wrong device ID…

I just had to say, I never thought much about deer until this moment…

I don’t have a DS2401. Here’s my excerpts from the datasheet trawl I’ve just done…

[quote]Read ROM [33h] or [0Fh]
This command allows the bus master to read the DS2401s 8-bit family code, unique 48-bit serial number, and 8-bit CRC. This command can only be used if there is a single DS2401 on the bus.[/quote]

So the ReadROM command will always “fail”.

I would suggest the best way to approach this is by scanning the bus with the SearchROM command. Here’s a sample code that just collects IDs of all OW devices on the wire.

        public static void Main()
            bool ledState = false;

            OutputPort led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, ledState);
            const short MaxOWDevices = 20;
            ushort temperature;
            ushort temperature_fraction;

            byte[] ow_readvalue = new byte[9];

            byte[][] OW_List = new byte[MaxOWDevices][];
            char[] OutStr = new char[40];
            short OW_number = 0;

            short i = 0, j = 0;

            // Change this your correct pin!
            OneWire ow = new OneWire((Cpu.Pin)FEZ_Pin.Digital.Di7);

            for (i = 0; i < MaxOWDevices; i++)
                OW_List[i] = new byte[8];

              if (ow.Reset())

                    OW_number = 0;
                    while (ow.Search_GetNextDevice(OW_List[OW_number]))
                    Debug.Print("Found: " + OW_number + " devices");

This is possibly a better scenario anyway - evaluate what devices you have on the bus and then figure out what that means?

hope this helps

Ah cool - those addresses are beasts to type in :wink:

Your reply came in while I was typing away it seems…