Hello. I am new to the .NET Gadgeteers and Microframework.
I am trying to use the OneWire library in MF 4.2 QFE2 with GHI Electronics extender.
I have the following hardware:
I am using the code example from TinyCLR for GHI SDK 4.2:
public static void Main()
{
// Change this your correct pin!
OutputPort myPin = new OutputPort((Cpu.Pin)EMX.Pin.IO4, false);
OneWire ow = new OneWire(myPin);
ushort temperature;
In my application, I am using pin 3 on the extender, with the following code…
When using the following code, the mainboard locks when it performs a 1-Wire bus reset (ow.TouchReset()), and I must use MFDeploy to erase deployment. in order to get the board back to a functional state.
The output window shows: A first chance exception of type ‘System.NotSupportedException’ occurred in MountaineerTest1.exe
Any thoughts would be appreciated.
GT.Socket socket = GT.Socket.GetSocket(extender.ExtenderSocketNumber, false, extender, null);
OutputPort myPin = new OutputPort(socket.CpuPins[3], false);
OneWire ow = new OneWire(myPin);
ushort temperature;
// read every second
while (true)
{
if (ow.TouchReset() > 0) {
ow.WriteByte(0xCC); // Skip ROM, we only have one device
ow.WriteByte(0x44); // Start temperature conversion
When using the following code, the mainboard locks when it performs a 1-Wire bus reset (ow.TouchReset()), and I must use MFDeploy to erase deployment. in order to get the board back to a functional state.
The output window shows: A first chance exception of type ‘System.NotSupportedException’ occurred in MountaineerTest1.exe
Any thoughts would be appreciated.
public void OneWire()
{
GT.Socket socket = GT.Socket.GetSocket(extender.ExtenderSocketNumber, false, extender, null);
OutputPort myPin = new OutputPort(socket.CpuPins[3], false);
OneWire ow = new OneWire(myPin);
ushort temperature;
// read every second
while (true)
{
if (ow.TouchReset() > 0) // THIS IS THE LINE WHICH PRODUCES
// A first chance exception of type 'System.NotSupportedException' occurred in MountaineerTest1.exe
{
ow.WriteByte(0xCC); // Skip ROM, we only have one device
ow.WriteByte(0x44); // Start temperature conversion
while (ow.ReadByte() == 0) ; // wait while busy
ow.TouchReset();
ow.WriteByte(0xCC); // skip ROM
ow.WriteByte(0xBE); // Read Scratchpad
temperature = (byte)ow.ReadByte(); // LSB
temperature |= (ushort)(ow.ReadByte() << 8); // MSB
Debug.Print("Temperature: " + temperature / 16);
Thread.Sleep(1000);
}
else
{
Debug.Print("Device is not detected.");
}
Thread.Sleep(1000);
}
}