One-wire communications

Go To Last Post
13 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello everyone,

Does anyone know of a good tutorial which cover one wire communications and how to set it up?

I am getting this temperature sensor for my project: https://www.sparkfun.com/products/11050. I am going to be connecting it to the ATMega128 microcontroller. I read through the datasheet but it is still a little unclear about one wire communications. Hardware wise, I think it is pretty straight forward. But what I got, I need to use two pins on the microcontroller; one for Tx and one for Rx. These two pins will be connected to the same wire and need to be isolated from each other as in one cannot see what the other is doing. Is this correct? Does it matter which two pins I connect to the microcontroller or can pick any other two pins?

The part that I am a little unclear on is how do I code for one wire communications? It looks like that everything is related to being high for x amount of uS or being low for y amount of uS. In that case, I guess I can use a timer to time how long everything is high or low. What would you do?

Any help would be much appreciated. Than you.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You only need one port pin. The software will either configure it to output a logic 0 or set it as an input. This is termed 'open collector' or 'open drain'. The external pullup resistor is required. There would have to be a ton of example code for Dallas 1wire or more specifically the ds1820 et al.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

philm0 wrote:
Does anyone know of a good tutorial which cover one wire communications and how to set it up?

There are many protocols which use just one wire.

I take it you mean 1-Wire(TM) - the specific Maxim (formerly Dallas) protocol :?:

The place to go is, unsurprisingly, the Maxim website - as they are they inventors & owners of the protocol!

I wrote:
The two key documents that you need to read are:

APPLICATION NOTE 126: 1-Wire Communication Through Software
Abstract: A microprocessor can easily generate 1-Wire(TM) timing signals if a true bus master is not present (e.g., DS2480B, DS2490). This application note provides an example, written in 'C', of the basic standard speed 1-Wire master communication routines. The four basic operations of a 1-Wire bus are Reset, Write 1 bit, Write 0 bit, and Read bit. Byte functions can then be derived from multiple calls to the bit operations. The time values provided produce the most robust 1-Wire master for communication with all 1-Wire devices over various line conditions.
http://pdfserv.maxim-ic.com/en/a...

You can take the code straight from this document - all you have to add is a delay function.

APPLICATION NOTE 148: Guidelines for Reliable 1-Wire Networks
Abstract: The 1-Wire(TM) protocol was originally designed for communication with nearby devices connection a way to add auxiliary memory on a single microprocessor port pin. Customers unique applications that involved extending the bus and moving the slave devices farther and master. Problems came up as the bus lengths exceeded both the capabilities of the bus masters of the protocol. 1-Wire device designs responded to the call with added features and protocols, (networking) capabilities, durable steel containers (iButtons), and mechanisms to assure valid even in severely intermittent contact situations.
This document explains the typical 1-Wire networking topologies and makes recommendations operation. It also presents how various 1-Wire masters impact these recommendations.

http://pdfserv.maxim-ic.com/en/a...

This document shows you various hardware drive schemes from a single port pin, through a single FET, to advanced drivers.

The full list of all iButton and 1-Wire App Notes is here:
http://www.maxim-ic.com/appnotes...


Originally posted at: http://www.8052mcu.com/forum/read/149007

 

#1Wire

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Wed. Apr 22, 2020 - 10:09 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Check out the Arduino code for it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

there are a Ton of projects(ok there are 4) in the projects area using the DS1820 temp sensor, just search for DS18 to find them.

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, thank you jccordill,, I will take a look at that.

Right now, I am concerned with how to hook it up. In the datasheet, to showed two pins, on for transmitting and another for receiving. And both of the are connected to the same line.

If I am reading Kartman's post correctly, I use only one pin?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you're doing it via uart you use two pins. But since you have a microcontroller, you only need one pin. Have you looked at the Arduino example?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
Have you looked at the Arduino example?

Or the Maxim application notes :?:

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

philm0 wrote:
In the datasheet, to showed two pins, on for transmitting and another for receiving. And both of the are connected to the same line.

If I am reading Kartman's post correctly, I use only one pin?


If you have a single pin that can both read & write, then use it. Otherwise you will need separate pins to read & write.

Simples!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you use an UART, all the timing is done in hardware. Either Atmel or Maxim has an app note detailing this.

EDIT: AVR libc has a function for calculating 1-Wire CRCs.


include <util/crc16.h>
.
.
.
crc = _crc_ibutton_update(crc, data);
.
.
.

Gamu The Killer Narwhal
Portland, OR, US
_________________
Atmel Studio 6.2
Windows 8.1 Pro
Xplained boards mostly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Maxim also make "bridge" chips which present a standard UART, SPI or I2C interface to the microcontroller, and do all the timing & line driving in hardware for you...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
a single pin that can both read & write

Sometimes known as a bidirectional pin.

The quasi-bidirectional pins of an 8051 are good for this.

Note that the pin doesn't need to read & write at the same time - it is sufficient that it can switched between read & write (within the protocol timing constraints).

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

GTKNarwhal wrote:
If you use an UART, all the timing is done in hardware. Either Atmel or Maxim has an app note detailing this.

Maxim's is here: http://www.maximintegrated.com/a...

Atmel:

http://www.atmel.com/images/doc2...

http://www.atmel.com/images/avr2...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...