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=1011100010100100011101010010100000000000000000000111011011111111
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
while(true)
{
if(ow.Reset())
{
if(!ow.Search_IsDevicePresent(dev1))
Debug.Print("Dev 1 not found");
else Debug.Print("Dev 1 found");
if(!ow.Search_IsDevicePresent(dev2))
Debug.Print("Dev 2 not found");
else Debug.Print("Dev 2 found");
}
else
{
Debug.Print("Device is not detected.");
}
Thread.Sleep(500);
}
}
}
}