using System;
public class Program
{
public static void Main()
Console.WriteLine("Temp {0}", Xfer());
}
private readonly static double FullRaw = Math.Pow(2.0, 12.0); // 12-bit value, should be 4096;
private readonly static double[] ParamValues = new double[] { 10000.0, Double.PositiveInfinity };
protected static double TempC(double raw, double fullRaw, double RB, double RM)
double fN;
raw += 0.5; // Center of bit cell
if (Double.IsPositiveInfinity(RM)) { // Inf Center Resistor
fN = RB*raw/(fullRaw - raw); // scale balance resistor by this that is the resistance
} else {
double RU, VU, VL, V; // Variables
RU = 10000.0; // Upper and Lower Divider
VU = (RU+RM)/(2.0*RU+RM); // resistor In Reference Chain
VL = RU/(2.0*RU+RM);
V = VL + ((VU - VL) * raw/fullRaw);
fN = RB * V / (1.0-V);
fN = Math.Log10(fN); // equation deals with log of resistance
return 560.112 - 267.344*fN + 51.576*fN*fN - 5.539*fN*fN*fN + 0.24814*fN*fN*fN*fN;
public static Double Xfer()
byte[] raw = new byte[] {0xbf, 0x07, 0x00, 0x00};
UInt32[] rawData = new UInt32[4];
rawData[0] = BitConverter.ToUInt32(raw, 0);
double fN = TempC(Convert.ToDouble(rawData[0]), FullRaw, ParamValues[0], ParamValues[1]);
double temp = Math.Round(fN, 2);
return temp;