I have FEZ Panda 2 that has a ds18b20 one-wire sensor connected to it. The problem i have is that the sensor always returns the same value for the temperature. Sensor works fine when it’s connected to the Arduino board and it reports the correct temperature. I’m testing this with this code:
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.FEZ;
namespace ds18b20Test
{
public class Program
{
public static void Main()
{
ushort temperature;
byte[] sp = new byte[9];
Cpu.Pin myPin = (Cpu.Pin)FEZ_Pin.Digital.Di5;
OneWire ow = new OneWire(myPin);
ow.Reset();
ow.WriteByte(0xCC); // Skip ROM, we only have one device
ow.WriteByte(0xBE); // read scratchpad
ow.Read(sp, 0, 9);
Debug.Print(">>> " + ConvertBytesToHexString(sp, true));
ow.Reset();
ow.WriteByte(0xCC); // Skip ROM, we only have one device
ow.WriteByte(0x4E); // write scratchpad
ow.WriteByte(0xFD);
ow.WriteByte(0x4F);
ow.WriteByte(0x1F);
ow.Reset();
ow.WriteByte(0xCC); // Skip ROM, we only have one device
ow.WriteByte(0xBE); // read scratchpad
ow.Read(sp, 0, 9);
Debug.Print(">>> " + ConvertBytesToHexString(sp, true));
ow.Reset();
ow.WriteByte(0xCC);
ow.WriteByte(0x44); // Start temperature conversion
Thread.Sleep(1000);
bool r = ow.Reset();
ow.WriteByte(0xCC);
ow.WriteByte(0xBE); // Read Scratchpad
ow.Read(sp, 0, 9);
Debug.Print(">>> scratchpad after convert: " + ConvertBytesToHexString(sp, true));
Thread.Sleep(Timeout.Infinite);
}
public static string ConvertBytesToHexString(byte[] bytes, bool insertSpace)
{
string output = String.Empty;
for (int i = 0; i < bytes.Length; i++)
{
output += ByteToHex(bytes[i]);
output += insertSpace ? " " : "";
}
return output;
}
public static string ByteToHex(byte b)
{
const string hex = "0123456789ABCDEF";
int lowNibble = b & 0x0F;
int highNibble = (b & 0xF0) >> 4;
string s = new string(new char[] { hex[highNibble], hex[lowNibble] });
return s;
}
}
}
What i always get from this is:
F8 07 FD 4F 1F FF 01 10 29
F8 07 FD 4F 1F FF 01 10 29
scratchpad after convert: F8 07 FD 4F 1F FF 01 10 29
On Arduino the the sensor works. One thing i did notice is that the same thing happens on the Arduino when don’t call the OneWire library write with the second parameter which basically disables the interrupts.
Found some topics on this forum that describe something similar, but i still don’t know how to fix my problem. As far i can tell all the assemblies are loaded correctly.
So if anyone has any suggestions it would be much appreciated.