Unable to do the 1-wire temperature test with GRiSP 2

Alas they are not here are the differncenses (courtesy ChatGPT Pro) We only implemented the 18B20. PR wellcome :wink:

  1. Family code

    • DS18B20 has a family code of 0x28.
    • DS18S20 (and the older DS1820) has a family code of 0x10.
      Many 1-Wire libraries check the family code to decide how to interpret the scratchpad data. If you’re using a routine that was written specifically for the DS18B20, it may ignore or misinterpret a 0x10 device, giving the wrong reading.
  2. Resolution and scratchpad layout

    • DS18B20 supports user-selectable resolution from 9 to 12 bits. Typically, people run it at 12-bit resolution, yielding 0.0625°C increments.
    • DS18S20 outputs effectively 9 bits of resolution (0.5°C steps in the basic reading). However, it also uses additional registers (COUNT_PER_C, COUNT_REMAIN) if you want the fractional part (this is the so-called “extended” or “improved” resolution method).
      Because of these differences, the scratchpad (the block of bytes you read over 1-Wire) is laid out differently, and the formula for calculating the final temperature is different.
  3. Data format & calculation

    • DS18B20: The temperature data is in bytes 0 and 1 of the scratchpad, which can be directly interpreted (with some scaling, depending on resolution).
    • DS18S20: It always gives a 9-bit value in the main temperature register (bytes 0 and 1), but then you use bytes 6 and 7 (COUNT_PER_C and COUNT_REMAIN) to get a finer resolution. The standard formula (from the Maxim datasheet) is:
      [
      T = T_\text{reading} - 0.25 + \frac{\text{COUNT_PER_C} - \text{COUNT_REMAIN}}{\text{COUNT_PER_C}}
      ]
      This differs from how you would interpret DS18B20 data directly.
  4. Default resolution

    • DS18B20 is often used at 12-bit resolution (0.0625°C).
    • DS18S20 is fixed 9-bit for the main measurement (0.5°C). You must do extra math with the count registers to improve the resolution.
1 Like