Posts Tagged ‘1 wire’

1-Wire (OneWire) C18 library

November 17th, 2011 6 comments

So yesterday I wanted to get some temperature measurements from a DS18S20 thermometer to my PIC prototyping board. This thermometer uses the 1-Wire communication protocol so I searched around to find a 1-Wire library for the C18 compiler I am using. Maybe I am wrong but I couldn’t find any. So I created one, hence this post.

I had a post about the 1-Wire protocol a while back so you can read that if you are not familiar with it. To implement this protocol we need to work with precision timing. Ideally this could be written in asm. However, for convenience reasons I wrote this in C. I don’t really mind the minor performance penalty 🙂

Just to be clear, this is a library for the 1-Wire protocol, not for any of the supported devices. The library contains 3 main functions:

  • 1-Wire Reset
  • 1-Wire Write
  • 1-Wire Read

Using these three operations we can have full communication with any 1-Wire device. Let me demonstrate first and then I will write about how you can use it in your project.

A brief demonstration

To demonstrate this operation, I connected a DS18S20 thermometer and connected the DQ line on my PIC’s Port C Pin 1. The procedure I will follow is:

  • Issue a Reset pulse and observe the Presence of the thermometer
  • Issue the Skip Rom command (0xCC)
  • Issue the Convert T command (0x44)
  • Wait for 1+ second
  • Issue a Reset pulse and observe the Presence of the thermometer
  • Issue the Skip Rom command (0xCC)
  • Issue the Read Scratchpad command (0xBE)
  • And read the next two bytes which represent the temperature

Lets see the C code I loaded on my board Read more…

Incoming search terms:

  • ds18b20 c18 (18)
Categories: electronics Tags: , ,

The 1-wire (o/w) Protocol – DS18S20

November 13th, 2008 No comments

Hello again,

This post is actually going to become handy on the future posts I am planning for the DS18S20 thermometer. This is a well known and used thermometer as it simple to implement and quite accurate. I will do a brief description of the protocol it uses to communicate with our PIC. Through this protocol we can send commands to the DS18S20 and receive data and responses.
This is actually a brief review of the datasheet of the device which is already very simple to understand. This post is just to introduce the basics of the o/w protocol.

First you can download the latest pdf from here. Read more…

Incoming search terms:

  • DS18S20 (26)
  • ds18s20 pic (17)