Announcement

Collapse
No announcement yet.

One Wire DS18B20 bit shift problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • One Wire DS18B20 bit shift problem

    Hi Guys,

    Firstly thanks to all involved for creating such a fantastic product!

    I am trying to write some code to interface with a DS18B20 one wire temp sensor.

    For the most part its working however just looking at the data i get back, i am certain that my MSB is bit shifted by one bit. (Unless my finger is actually at 65 degrees C )

    I'm buying my first DSO this week so i should be able to do some more indepth analysis of what is wrong, but while im waiting I thought I would try here.

    Code:

    HTML Code:
    OW_Reset(); // reset
    OW_Write(0xCC); // Skip ROM search (Only one sensor connected)
    OW_Write(0x44); // Do a temperature conversion
    OW_Reset(); // reset
    
    OW_Write(0xCC); // Skip ROM search (Only one sensor connected)
    OW_Write(0xBE); // read scratchpad memory. 
    temp_LSB := OW_Read();
    temp_MSB := OW_Read();
    
    print ("0x", [HEX2] temp_LSB);
    print (" ", [HEX2] temp_MSB);
    This will typically return for example:

    0xDD 02 in ambient or
    0xAA 04 with a hot sweaty finger on the sensor.


    When i am sure it should return:

    0xDD 01 in ambient or
    0xAA 02 with a hot sweaty finger on the sensor.

    Any suggestions?

    Thanks,

    Dave

  • #2


    Hi Dave, let us know what you find with the scope, if you are certain there is a problem we will hook a device up and look into it, but just remember that the data is returned in 0.125 degree steps and will need shifting anyway to get the desired result.

    In the mean time, here is some test code that may help

    //==================================================================================================
    // For this demo to work, a Dallas DS1821 must be connected to pin_1 AND POWERED FROM 5V.
    // DS1821 pin1 = Gnd / pin2 = data in/out / pin 3 = +5v
    //==================================================================================================


    var temp_buf, stat_buf;

    func main()

    gfx_Cls();

    pause(1000);

    txt_MoveCursor(0,0);


    pin_Set(ONEWIRE, PIN_1); // set either I/O pin to 1 wire mode

    if(OW_Reset()) // initialise and test
    print("No device detected");
    while(1);
    endif

    txt_Set(TEXT_COLOUR, LIGHTGREY);
    txt_Set(FONT_SIZE, FONT_LARGE);

    // OW_Write(0x0C); // write status
    // OW_Write(0b01000010); // set continuous convertion

    repeat
    txt_MoveCursor(0, 0);
    print ("result=", OW_Reset() );
    OW_Write(0xEE); // start conversion

    OW_Reset(); // reset
    OW_Write(0xAA); // get temperature

    temp_buf := OW_Read();

    OW_Reset(); // optional
    OW_Write(0xAC); // optional read status
    stat_buf := OW_Read(); // optional 82 when DS1821 run

    txt_MoveCursor(1, 0);
    print ("temp_buf=0x", [HEX2] temp_buf );

    txt_MoveCursor(2, 0);
    print ("stat_buf=0x", [HEX2] stat_buf );

    forever

    endfunc
    Regards,
    Dave

    Comment


    • #3

      Code:
      var temp_LSB, temp_MSB;func main()gfx_Cls();pause(1000);txt_MoveCursor(0,0);pin_Set(ONEWIRE, 0); // set either I/O pin to 1 wire modepin_Set(OUTPUT, 1);if(OW_Reset()) // initialise and testprint("No device detected");while(1);endifrepeattxt_MoveCursor(0, 0);//print ("result=", OW_Reset() ,"\n");//OW_Write(0x44); // start conversionOW_Reset(); // resetOW_Write(0xCC); // Skip ROM search (Only one sensor connected)OW_Write(0x44); // Do a temperature conversionOW_Reset(); // resetOW_Write(0xCC); // Skip ROM search (Only one sensor connected)OW_Write(0xBE); // read scratchpad memory.temp_LSB := OW_Read();pin_HI(1);temp_MSB := OW_Read();pin_LO(1);print ("0x", [HEX2] temp_LSB);print (" ", [HEX2] temp_MSB);foreverendfunc

      CRO trace demonstrates the problem, both bytes are bit shifted to the right by one bit. The MSB makes it easy to observe this phenomena:



      This should read "10000000"; 0x01

      But the uOLED-128-G1 reads it as "01000000"; 0x02

      Place a finger on the sensor to increase the temp 10 degrees or so:




      This should read "01000000"; 0x02

      But the uOLED-128-G1 reads it as "00100000"; 0x04








      Comment


      • #4


        Hi Dave, thanks for your concise report, we will hook a DS1820device up within the next day or so and run some tests. Will let you know asap.
        Regards,
        Dave

        Comment


        • #5


          Look forward to your feedback, thanks!

          Comment


          • #6


            Hi guys, got any feedback?

            Comment


            • #7


              Hi Dave, yes you are correct, there is a problem there and the value returned should have been shifted 1 place to the right. A temporary workaround is to shift right 1 place. This problem has been corrected for the next PmmC and Workshop release due towards the end of next week.
              Regards,
              Dave

              Comment

              Working...
              X