Announcement

Collapse
No announcement yet.

Communicating with Multiple 1-wire Dallas DS18B20 Temperature Sensors

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

  • Communicating with Multiple 1-wire Dallas DS18B20 Temperature Sensors

    I have written some code to pull the 64 bit serial numbers from my DS18B20 temperature sensors. When I try to communicate with one sensor using the "Match ROM" command I don't seem to get an appropriate response for temperature conversion. Is there something funny going on with how I am sending the 64 bit serial number using the OW_Write command? I know var can only be 16 bits so I split it up in an array to send. I can use the "Read ROM" command with a single sensor and things work but if I try to address the sensor with the "Match ROM" command I can't seem to get things going. Any ideas? Thanks.



    In this example below I have one sensor on the bus and am just trying to make it do a conversion and read it via the "Match ROM" command.



    [HTML]#platform "GOLDELOX-GFX2"
    //Read multiple 1-Wire Temp sensors
    //1 Sensor is currently hooked up and I am trying to communicate with it by matching ROM code
    #inherit "4DGL_16bitColours.fnc"
    //================================================================
    func main()
    var x;
    var y;
    var z;
    var t1;
    var color := BLUE;
    var rem1;
    var sens_ser1[4] := [0x28E4, 0x37B7, 0x0300, 0x00CE]; // 64 bit serial number, 28 = device type, E437B7030000 = serial, CE = CRC
    var c := 0;
    gfx_Clipping(ON);
    pin_Set(ONEWIRE, IO1); // set either I/O pin to 1 wire mode
    if(OW_Reset()) // initialise and test
    print("No device detected");
    while(1);
    endif
    gfx_Cls();
    while(1)
    txt_Set(TEXT_COLOUR, GREEN);
    //======================================
    print("Inside");
    gfx_MoveTo(0,9);
    print("Temp");
    gfx_MoveTo(0,35);
    gfx_Circle(80,9,1,BLUE);
    print("Outside");
    gfx_MoveTo(0,44);
    print("Temp");
    gfx_Circle(80,44,1,BLUE);
    //======================================
    txt_Set(TEXT_COLOUR, color); //0xFFFF = White
    OW_Reset();
    OW_Write(0x55);
    c:=0;
    for (c:=0;c

  • #2


    Maybe the OW_Write function itself is not condusive to writing the 64 bit address?

    Comment


    • #3


      Only thing I can see is that you are writing 16bit quantities here:-

      HTML Code:
      OW_Write(sens_ser1[c])
      the OW_Write function only takes 8bits, so only the low order byte of each word is being sent.

      try making the table bytes, and send 8 consecutive bytes, and hopefully it should work.

      Not quite sure what the endianess should be, I have never tried this before
      so you may have to play around a bit to get it right.
      Regards,
      Dave

      Comment


      • #4


        I actually had it set up as 8 bytes originally, but that wasn't working either so I figured I would change it to match the length a var can be, which is 16 bits. I am still working on it but have still not been able to address the 1-wire devices with match ROM. I wrote a similar application using some C code with a PIC and 16x2 LCD. Everything worked like I thought it would, the Match ROM command was working fine so I am not really sure what is going on in this instance with the OLED display programming.

        Comment


        • #5


          Is the OW_Write command just sending byte data out on the one-wire pin, nothing more?

          Comment


          • #6


            yes OW_Write(..) only sends 8 bits, OW_Read() receives 8bits
            Regards,
            Dave

            Comment


            • #7


              Has anyone at 4D used this command successfully to address a device via it's 64bit ROM code? I wrote something up in a quick PicBasic program to see if I could address it this way and things seem to work fine:



              OWOUT DQ, 1, [$55,$28,$B1,$FE,$22,$00,$00,$00,$5D,$44]



              The "1" sends the reset pulse before the data stream, $55 is the "Match ROM" command, $28 $5A $42 $B7 $03 $00 $00 $67 is the device type, serial and CRC. $44 is the "Convert" command. Sending this in my test using a PIC seems to work fine for addressing the DS18B20 and going on to receive valid temp data. This is the last thing to get working in my product before I release the hardware. The only thing I can see to do at this point is locate a a logic analyzer and see what is really happening or move on to a different product and/or interface.

              Comment


              • #8


                I cant see any reason why it wont work, but will try to help.

                What value is your pullup resistor?

                Have you been able to read the serial number with Goldelox ?

                If you post the code you used for reading serial number, and the code you are using to try writing the device, we can try it here.
                Regards,
                Dave

                Comment


                • #9


                  I am using a 4.7kohm pull-up resistor. I can read the serial number with the Goldelox.



                  Here is what I use to read the device serial number - this all seems to work fine and displays the number on the OLED for me. I then record this number to put in my other set of code to try and address the Dallas 1-wire temp sensor.



                  [HTML]#platform "GOLDELOX-GFX2"
                  #inherit "4DGL_16bitColours.fnc"
                  //Identify Device
                  func main()
                  pin_Set(ONEWIRE, IO1);// set either I/O 1 pin to 1 wire mode
                  if(OW_Reset()) // initialise and test
                  print("No device detected");
                  while(1);
                  endif
                  gfx_Cls();
                  while(1)
                  OW_Reset(); // Must send a reset command each time to read the data
                  OW_Write(0x33); // Read Rom Command
                  ID_Loop();
                  wend
                  endfunc

                  func ID_Loop()
                  var ID[7];
                  var x := 0;
                  for (x:=0;x

                  Comment


                  • #10


                    [HTML]var ID[7]; var x := 0; for (x:=0;x
                    Regards,
                    Dave

                    Comment


                    • #11


                      Thanks! I completely missed that. I think I have it going now (making the array the right length changed the CRC byte). I am reading two sensors in Deg C on the same bus. Thanks for being my second pair of eyes on this, I greatly appreciate it.

                      Comment


                      • #12


                        I am trying to test bit 15 when I do an OW_Read9() to see wheter or not it is a 1 (negative temp) or a 0 (positive temp). I have been looking through the manual but am not sure if the command I am using to do this is correct:



                        [HTML] t := OW_Read9();
                        t := t + (OW_Read9()

                        Comment


                        • #13


                          you are shifting the result left 64 times

                          [HTML]OW_Read9()
                          Regards,
                          Dave

                          Comment


                          • #14


                            Have you had success?

                            Still here to help if required.
                            Regards,
                            Dave

                            Comment


                            • #15


                              Yes,



                              I used a bitwise '&' and then just took the 1's complement and added 1 to that. Worked out well. Thanks for the help.

                              Comment

                              Working...
                              X