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

Is there any proper documentation for OneWire class?

Onewire api documentation DS18B20

Best Answer CW2, 27 January 2013 - 10:50 AM

Hi. I have found many examples of how to use a DS18B20 and exactly what code to write. However, I don't understand the why. Microsoft has some documentation for the Microsoft.SPOT.Hardware.OneWire class, however there are no descriptions. It mentions all of the methods, but there is no hint to exact implementation. What I specifically need help with is something like this;

 

[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]ow.WriteByte(0xBE)[/color]

[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]I know the 'ow' is the onewire object and the WriteByte() is the method, but why am I using '0xBE'? What is that?[/color]

 

Most of the .NET MF classes that provide functionality of hardware interfaces or protocols assume prior knowledge, often at rather deep level. An electronic engineer usually has to look into the specification or device datasheet, in this particular case DS18B20 datasheet provides detailed description of 1-Wire protocol communication and commands - these are that 'magic' 0xXX numbers in the code.

 

There are two kinds of 1-Wire commands, "ROM" and "Function": "ROM" commands are used for addressing and are supported by all 1-Wire devices, "Function" commands are device-specific.

 

0xCC is "SKIP ROM" command, which is used to address multiple slaves at once, for example when you want to start temperature conversion of all DS18B20 present on the bus (including case when there is only one device),

 

0xBE is "READ SCRATCHPAD" command to get the temperature measurement from a particular DS18B20 device.

 

It is considered good practice to use constants instead of hard-coded magic numbers, so you could define for example OneWireCommand class or enum with SkipRom = 0xCC, ReadScratchpad = 0xBE and use symbolic names, e.g. ow.WriteByte(OneWireCommand.SkipRom). I've done this in my alternative implementation.

Go to the full post


  • Please log in to reply
7 replies to this topic

#1 AndrejsM

AndrejsM

    Member

  • Members
  • PipPip
  • 18 posts
  • LocationAtlanta

Posted 26 January 2013 - 10:05 PM

Hi. I have found many examples of how to use a DS18B20 and exactly what code to write. However, I don't understand the why. Microsoft has some documentation for the Microsoft.SPOT.Hardware.OneWire class, however there are no descriptions. It mentions all of the methods, but there is no hint to exact implementation. What I specifically need help with is something like this;

 

[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]ow.WriteByte(0xBE)[/color]

[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]I know the 'ow' is the onewire object and the WriteByte() is the method, but why am I using '0xBE'? What is that?[/color]

 

[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]ow.WriteByte(0xCC)[/color]

[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]Same here, what is the '0xCC' ?[/color]

 

When do I ReadByte() or WriteByte() or TouchReset()? What exactly do the methods mean and which ones do you use, and when? I am a .NET engineer for my day job, however I am used to having SDK docs for everything I code. Writing standard software to be run on Windows 7 or 8 I understand. The lack of documentation for the OneWire class has me very frustrated!

 

Can anyone please help and point me in the right direction? Thanks.



#2 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 27 January 2013 - 04:32 AM

0xBE and 0xCC is the data you write. its a byte in hexdecimal format.

 

when you have to read and write is descibed in the devices datasheet you wanna use, also what (0xBE for instance)

 

0xBE is 190 in decimal btw (a byte)



#3 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 27 January 2013 - 08:29 AM

The Microsoft OneWire class is documented in the 4.3 library reference:http://msdn.microsof...t.spot.hardware(v=vs.102).aspxRegards,Mark

#4 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 27 January 2013 - 10:50 AM   Best Answer

Hi. I have found many examples of how to use a DS18B20 and exactly what code to write. However, I don't understand the why. Microsoft has some documentation for the Microsoft.SPOT.Hardware.OneWire class, however there are no descriptions. It mentions all of the methods, but there is no hint to exact implementation. What I specifically need help with is something like this;

 

[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]ow.WriteByte(0xBE)[/color]

[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]I know the 'ow' is the onewire object and the WriteByte() is the method, but why am I using '0xBE'? What is that?[/color]

 

Most of the .NET MF classes that provide functionality of hardware interfaces or protocols assume prior knowledge, often at rather deep level. An electronic engineer usually has to look into the specification or device datasheet, in this particular case DS18B20 datasheet provides detailed description of 1-Wire protocol communication and commands - these are that 'magic' 0xXX numbers in the code.

 

There are two kinds of 1-Wire commands, "ROM" and "Function": "ROM" commands are used for addressing and are supported by all 1-Wire devices, "Function" commands are device-specific.

 

0xCC is "SKIP ROM" command, which is used to address multiple slaves at once, for example when you want to start temperature conversion of all DS18B20 present on the bus (including case when there is only one device),

 

0xBE is "READ SCRATCHPAD" command to get the temperature measurement from a particular DS18B20 device.

 

It is considered good practice to use constants instead of hard-coded magic numbers, so you could define for example OneWireCommand class or enum with SkipRom = 0xCC, ReadScratchpad = 0xBE and use symbolic names, e.g. ow.WriteByte(OneWireCommand.SkipRom). I've done this in my alternative implementation.



#5 Sgoddy

Sgoddy

    New Member

  • Members
  • Pip
  • 6 posts
  • LocationCambridgeshire, UK

Posted 27 January 2013 - 12:43 PM

If I could hijack this thread to post an arguably related follow-on question:

 

My Microsoft.SPOT.Hardware namespace doesn't have a OneWire class. Which file do I have to reference to pick this up please?

 

How does the class hook into any specific hardware implementation? Is this done at a low level or via a C# driver? In my specific case I'm talking about Netduino Go.

 

Ok, that's more than 1 question :-)

 

Steve the G.



#6 AndrejsM

AndrejsM

    Member

  • Members
  • PipPip
  • 18 posts
  • LocationAtlanta

Posted 27 January 2013 - 03:14 PM

Wow! Thank you all for your excellent and very speedy responses. You have given me several places to go find what I'm looking for. Thanks! Now it's off to do some research.



#7 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 28 January 2013 - 05:51 PM

My Microsoft.SPOT.Hardware namespace doesn't have a OneWire class. Which file do I have to reference to pick this up please?

  You'd need to add Microsoft.SPOT.Hardware.OneWire.dll assembly reference to your project.  

How does the class hook into any specific hardware implementation? Is this done at a low level or via a C# driver? In my specific case I'm talking about Netduino Go.

  OneWire methods are native, except FindAllDevices() which is managed. The 1-Wire protocol is implemented via 'bit-banging', i.e. in software (native driver).   As far as I know, Netduino Go does not include OneWire, so you'll probably get 'not implemented' exception when calling OneWire methods. If I remember it correctly, Chris has mentioned in one of the GoBus-related posts that they are planning 1-Wire profile support, which enables use of 1-Wire Go modules. So you'll be able to connect 1-Wire device, such as DS18B20 temperature sensor, to this 1-Wire module and OneWire methods will provide its functionality via virtualized 1-Wire communication link (over GoBus transport).



#8 unexpectedly

unexpectedly

    New Member

  • Members
  • Pip
  • 2 posts

Posted 30 August 2013 - 11:22 PM

It is considered good practice to use constants instead of hard-coded magic numbers, so you could define for example OneWireCommand class or enum with SkipRom = 0xCC, ReadScratchpad = 0xBE and use symbolic names, e.g. ow.WriteByte(OneWireCommand.SkipRom). I've done this in my alternative implementation.

 

Thank you. Emphasis added to the quote is by me. I was twitching about this before I got to your post. I'm new to netduino, C#, .NET, all that, but always make many many comments in your code. Two recent highlights while porting Adafruit ST7735 from AVR to PIC32:

 
[font="'courier new', courier, monospace;"][color=#008000;]//  Magical unicorn dust, 16 args[/color][/font]
[font="'courier new', courier, monospace;"][color=#008000;]//  (seriously though, not sure what these config values represent)[/color][/font]
 
... and later 
 
[color=#008000;][font="'courier new', courier, monospace;"]//  Sparkles and rainbows, 16 args[/color][/font]
[color=#008000;][font="'courier new', courier, monospace;"]//  (ditto)[/color][/font]
 
That kinda made my day.






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.