Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Problem with Native OneWire on Netduino Plus 2


  • Please log in to reply
1 reply to this topic

#1 nickNetduino

nickNetduino

    Member

  • Members
  • PipPip
  • 12 posts

Posted 11 November 2012 - 04:41 PM

I've been able to natively read the temp from a single DS18B20 on my new Netduino Plus 2 using non-parasite power. My trouble comes with trying to read multiple DS18B20's using parasite power. I can see the devices ok (populated into "deviceList") however I am getting erroneous readings. I'm sure my writebyte's/readbyte's must be off or something. Here is the pertinent code and a link to the datasheet (using page 18, example 1 as a reference). Please let me know if you have any insight. Thank you so much!

http://datasheets.ma.../ds/DS18B20.pdf

static float getOWTempByAddress(OneWire owBus)
        {
            ArrayList deviceList = owBus.FindAllDevices();

            foreach (byte[] device in deviceList)
            {
                Debug.Print("Found ID: " + bytesToHexString(device, true));
            }

            byte[] deviceToCheck = (byte[])deviceList[0]; //lets just look at the first device as a test

            float TemperatureC = 0;
            int tempLow = 0;
            int tempHigh = 0;
            int temptemp;

            owBus.TouchReset();
            owBus.WriteByte(0x55); //match rom
            foreach (byte theByte in deviceToCheck)
            {
                  owBus.WriteByte(theByte);
            }
            owBus.WriteByte(0x44); //start temp conversion
            while (owBus.ReadByte() == 0) ; //wait while busy
            owBus.TouchReset();
            owBus.WriteByte(0x55); //match rom
            foreach (byte theByte in deviceToCheck)
            {
                  owBus.WriteByte(theByte);
            }
            owBus.WriteByte(0xBE); //read scratchpad
            tempLow = owBus.ReadByte(); //LSB
            tempHigh = owBus.ReadByte(); //MSB
            temptemp = (((int)(tempHigh) << 8) | tempLow);
            TemperatureC = temptemp * 0.0625f;

       
            }
            return (float)((TemperatureC * 9.00 / 5.00) + 32.00);
        }

Edited by Chris Walker, 11 November 2012 - 05:19 PM.
added [code][/code] tags


#2 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 11 November 2012 - 05:15 PM

I think the problem is that temperature conversion (when using parasite power) requires strong pull-up on the data line, i.e. step 6 "DQ line held high by strong pullup". You'd probably need to use the external MOSFET, as shown on Figure 4, page 6 in the datasheet.

Also, you'd need to issue the complete read sequence for each sensor (Reset, MatchROM, ReadScratchpad), because only the device that exactly matches the 64-bit ROM code sequence will respond to the function command issued by the master; all other slaves on the bus will wait for a reset pulse. The conversion can be started simultaneously (Reset, SkipRom, ConvertT), but the read-out requires the complete sequence for each sensor.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.