DS18S20 temp sensor won't go below 32F

I have a weather station that uses a DS18S20 temperature sensor outside. For the most part, it's been very accurate, but the last couple of nights, the temperature has gone below freezing, however the sensor never reads below 32. The graph my website generates shows the temperature flatlining, then rising as the sun comes up. Has anyone else had this problem with the DS18S20? Here's my website address if you want to see the raw data:

http://scoopjones.us/bakweather/read.php

Thanks,
Evan Jones

The data is nice, but the code would be better.

You're probably just not reading the data stream correctly. Have you read http://datasheets.maximintegrated.com/en/ds/DS18B20.pdf or similar description of what the sensor outputs (see page 4 in the link)?

Code please...

Ok, here’s the code:

float TempC(int pin) {                  // Fetch outside temperature in Celsius
  int HighByte, LowByte, TReading, SignBit, Tc_100;
  float temp;
  OneWireReset(pin);
  OneWireOutByte(pin, 0xcc);
  OneWireOutByte(pin, 0x44); // perform temperature conversion, strong pullup for one sec
  OneWireReset(pin);
  OneWireOutByte(pin, 0xcc);
  OneWireOutByte(pin, 0xbe);
  LowByte = OneWireInByte(pin);
  HighByte = OneWireInByte(pin);
  TReading = (HighByte << 8) + LowByte;
  SignBit = TReading & 0x8000;  // test most sig bit
  if (SignBit) // negative
  {
    TReading = (TReading ^ 0xffff) + 1; // 2's comp
  }
  Tc_100 = (6 * TReading) + TReading / 4;    // multiply by (100 * 0.0625) or 6.25
  return Tc_100;
}

int TempF(int pin) {                     // Fetch temperature in Fahrenheit
  int temp;
  temp = (int)((float)(TempC(pin))/100) * 1.8 + 32;
  return temp;
}

The DS18S20 returns the temperature as a twos complement number (as does the DS18B20) so you don't need to test the sign bit. You are just changing all negative numbers to positive ones.

Pete

I think you are losing lots of accuracy here:

  temp = (int)((float)(TempC(pin))/100) * 1.8 + 32;

Better make that

  temp = (int) (TempC(pin) * 0.018 + 32) ;

and avoid the integer division !