4 years, 10 months ago.

DS18B20 resolution issue

Dear community,

I use OneWire library for communicating with DS18B20 temperature sensor. I configure sensor to work at different resolution and get incorrent temperature values at all resolutions except for 12bit.

In source code I see that data from temperature registers is converted to float by wrong way. The lower bits are not used and undefined (DS18B20 datasheet) so the final value is bigger than correct temperature value:

  • for 2 timers at 11bit resolution
  • for 4 times at 10 resolution
  • for 8 times at 9bit resolution

DS18B20.cpp :: convertTemperature

int16_t intTemp = ((scratchPadBuff[1] << 8) | scratchPadBuff[0]);
        
 switch(scratchPadBuff[4])
{
    case DS18B20::NineBit:
        temp = (intTemp * 0.5F);
    break;
            
    case DS18B20::TenBit:
        temp = (intTemp * 0.25F);
    break;
            
    case DS18B20::ElevenBit:
        temp = (intTemp * 0.125F);
    break;
            
    case DS18B20::TwelveBit:
        temp = (intTemp * 0.0625F);
    break;
            
    default:
        deviceResult = OneWireSlave::OperationFailure;
    break;
}

I hope you make changes to source code, because the library is very helpful.

Best regards, Konstantin

Software engineer

Question relating to:

Maxim's microcontrollers provide low-power, efficient, and secure solutions for challenging embedded applications.
Be the first to answer this question.