one wire library

This forum is about you. Feel free to discuss anything is related to embedded and electronics, your awesome projects, your ideas, your announcements, not necessarily related to ChibiOS but to embedded in general. This forum is NOT for support.
User avatar
alex31
Posts: 379
Joined: Fri May 25, 2012 10:23 am
Location: toulouse, france
Has thanked: 38 times
Been thanked: 62 times
Contact:

one wire library

Postby alex31 » Sat Oct 27, 2012 5:03 pm

This is a library for OneWire Master bus http://en.wikipedia.org/wiki/1-Wire
based on advices found on dallas documentation :
http://www.maximintegrated.com/app-note ... mvp/id/214
this library use an usart to avoid to consume cpu cycle in bit banging
the library is synchronous, but when waiting it yield the processor to chibios.

the usart is configured in half duplex mode, so there is only TX to wire,
RX is connected internally for data reception when the bus is in reception mode.

i have made a bundle with the library and a demo for discovery, demo compile with
2.5.x version of chibios. The demo get temperature from any number of maxim 18b20 connected,
and can get rom address from ibutton.


https://www.dropbox.com/s/hvb1uy955ns15ci/1wire.zip

Image

Image

** TARGET **

The demo runs on an ST STM32F4-Discovery board with one or several one wire
sensors connected :

a one wire componant need vdd, vss and data, in this demo data (DQ) of all
sensors should be connected on GPIOD PIN 8.

a 4,7Kohms pullup resistor should be connected between vdd (3.3V) and data bus
(GPIOD PIN 8).

output is done on a tty console on serial over usb : wire micro usb port of
discovery on your computer, then open hyperterminal to connect to it.

under linux, screen /dev/ttyACM0 does the job

** The Demo **


The demo show how to use a simple library for accessing one wire devices.

The demo lanch a basic shell and wait for commands :

mem : memory info
info : chibios info

ow (for one wire) =>

ow search : print the unique address of all the device connected on the bus
ow rom : print address of one device *ONLY* if there is only one device on the bus
ow t : get value of all the temperature sensors maxim 18b20 on the bus one
each after other.
ow dt : ask all the 18b20 sensors to initiate acquisition, wait for the acquisition
to be done, then get all the values, better way whan there is more than 1 sensors



Alexandre

User avatar
z80
Posts: 20
Joined: Mon Oct 08, 2012 5:36 pm

Re: one wire library

Postby z80 » Tue Feb 19, 2013 7:47 pm

Hello!

I have a question related to hardware for using 1-WIRE network with suggested library. I'd be very much obliged if one could explain me.

As I understand 1-Wire there should be open drain output type on a signal wire to prevent output vs output "fight". Is TX UART part configured here as opendrain somehow? Is it really safe for a microcontroller to use only pullup resistor without any diode or anything like that on TX line?

In other words what happens if 1-Wire pulls voltage down during stop bit (logical 1) generation on UART?

As in STM32 UART reference it is written: "TX is always released when no data is transmitted. Thus, it acts as a standard IO in idle or in reception. It means that the IO must be configured so that TX is configured as floating input (or output high open-drain) when not driven by the USART"

Thanks in advance!

User avatar
alex31
Posts: 379
Joined: Fri May 25, 2012 10:23 am
Location: toulouse, france
Has thanked: 38 times
Been thanked: 62 times
Contact:

Re: one wire library

Postby alex31 » Tue Feb 19, 2013 10:48 pm

What i understand is that configured in half duplex mode, usart pin is open drain and not push pull.

If you want to be sure of that, you can measure current from usart pin, it should never be more than 3.3/Rpullup,
if it is, i was wrong with my understanding.

Alexandre

User avatar
z80
Posts: 20
Joined: Mon Oct 08, 2012 5:36 pm

Re: one wire library

Postby z80 » Wed Feb 20, 2013 9:20 am

alex31 wrote: you can measure current from usart pin, it should never be more than 3.3/Rpullup

Thank you for the explanation! But how can I measure that current? My multimeter can't do that - it needs a few seconds to perform measurement. And here duration is as long as 1/115200 * 8 = 69us.

As I understand there is another way to check if port is really open drain during transfer. To do that it is enough to replace pullup with pulldown and check what happens with oscilloscope.

User avatar
alex31
Posts: 379
Joined: Fri May 25, 2012 10:23 am
Location: toulouse, france
Has thanked: 38 times
Been thanked: 62 times
Contact:

Re: one wire library

Postby alex31 » Wed Feb 20, 2013 2:15 pm

on usart, when no data is transmitted, the signal is held in the mark condition (logic '1', vcc).
if you unplug 1wire bus, when nothing is transmitted, since the level is high, you can measure continuous current between usart pin and ground.

Alexandre

dcrystalj
Posts: 1
Joined: Fri Jun 07, 2013 12:37 am

Re: one wire library

Postby dcrystalj » Fri Jun 07, 2013 12:39 am

alex31 wrote:This is a library for OneWire Master bus http://en.wikipedia.org/wiki/1-Wire
based on advices found on dallas documentation :
http://www.maximintegrated.com/app-note ... mvp/id/214
this library use an usart to avoid to consume cpu cycle in bit banging
the library is synchronous, but when waiting it yield the processor to chibios.

the usart is configured in half duplex mode, so there is only TX to wire,
RX is connected internally for data reception when the bus is in reception mode.

i have made a bundle with the library and a demo for discovery, demo compile with
2.5.x version of chibios. The demo get temperature from any number of maxim 18b20 connected,
and can get rom address from ibutton.


https://www.dropbox.com/s/hvb1uy955ns15ci/1wire.zip

Image

Image

** TARGET **

The demo runs on an ST STM32F4-Discovery board with one or several one wire
sensors connected :

a one wire componant need vdd, vss and data, in this demo data (DQ) of all
sensors should be connected on GPIOD PIN 8.

a 4,7Kohms pullup resistor should be connected between vdd (3.3V) and data bus
(GPIOD PIN 8).

output is done on a tty console on serial over usb : wire micro usb port of
discovery on your computer, then open hyperterminal to connect to it.

under linux, screen /dev/ttyACM0 does the job

** The Demo **


The demo show how to use a simple library for accessing one wire devices.

The demo lanch a basic shell and wait for commands :

mem : memory info
info : chibios info

ow (for one wire) =>

ow search : print the unique address of all the device connected on the bus
ow rom : print address of one device *ONLY* if there is only one device on the bus
ow t : get value of all the temperature sensors maxim 18b20 on the bus one
each after other.
ow dt : ask all the 18b20 sensors to initiate acquisition, wait for the acquisition
to be done, then get all the values, better way whan there is more than 1 sensors



Alexandre


can you please provide me which enviroment you are using? on some tutorial page or something?
because i am using IAR.
Also can you tell me how to get temperature without running shell and putting commands there??

avrhack
Posts: 140
Joined: Tue Dec 24, 2013 1:42 pm
Has thanked: 17 times
Been thanked: 3 times

Re: one wire library

Postby avrhack » Sat Dec 28, 2013 2:35 pm

Excellent work Alexandre. I saw the original article and was just about to start writing code for it, but you've already done all the hard work.

This works perfectly on my STM32F3Discovery with a couple of 18B20s under 2.6.1.

The only bit I changed was a minor compile warning in usartDictionaryAddPair on the line reading:

while (i++ < ARRAY_LEN(usartDict.drv))

I removed the post-increment and added it at the end of the while loop. Appreciate there's nothing wrong with your code as the increment happens after the comparison so your logic is spot-on, but I hate compiler warnings :)

Thanks again for sharing such an excellent library.

arsenix
Posts: 5
Joined: Wed Oct 26, 2011 1:14 am

Re: one wire library

Postby arsenix » Thu Feb 04, 2016 10:45 pm

Digging up a post from long ago...

Is anyone using this library? It seems to work but only if we compile without optimization (O0), with O2 it stops working. We've been digging but so far have't figured out why.


Return to “User Projects”

Who is online

Users browsing this forum: No registered users and 11 guests