Electronics > Beginners

How to Implement 1-wire Devices

<< < (5/6) > >>

BradC:
Sort of.
onewire_reset_search() prepares the search routine with a blank canvas.
You then call onewire_search(). If it returns true you will find the serial number in ROM_NO.
I use this in onewire_gettemp() to get the temperature from the chip with the serial number in ROM_NO.

You can call onewire_search() repeatedly and it will iterate all the devices on the bus, putting the serial number in ROM_NO. When it returns false it has run out of devices on the bus and you call onwire_search_reset() to start again.

Because of the lack of memory on this chip, I have a button which iterates the devices on the bus and it just repeatedly does a conversion/read cycle. Each time I press the button it steps to the next device. When it runs out of devices it resets the search routine and starts again.

I'm sorry, my code is never well documented or particularly elegant.

I forget where I found the search routine. It was either in an app note or pseudocode somewhere. I've ported it around to a couple of languages and each time it's elegance loses something in translation.

Recently I started numbering devices with a "role" and stored this in the device eeprom. I use another CRC in the eeprom second byte to verify this device is actually programmed with my bits. That way I can pre-program the sensor before I put them in, and as the search routine steps through them it can identify which serial number is for which role. Saves me storing the serial numbers and makes sensor replacement a lot easier.

The point I was trying to make is onewire isn't difficult.

C:

--- Quote from: Docara on July 02, 2018, 09:29:34 am ---Hi,

Any uC really!

As mentioned I do not use/like the Arduino IDE, unfortunately this limits 'libraries'

At the moment I'm looking at the STM32F103 range or similar because I need a would like a CAN port and need two UART's although PIC's are not out and need quite a few I/O's

--- End quote ---

The STM32F103 or better would be good idea.
To have simple software you do need more Ram.
Better to have more then needed then not enough.

A UART is not a great interface between CPU's as you most often have to encode/decode data. It is probably best to create a packet like encoding. CAN does packets in hardware.

CAN is a great way to connect many controllers.
Remember that it is priority event based packet.

The One-wire bus uses packets.
With One-wire scan you can make this bus plug & play.
Think you will find that you need a lot of data per device if you want to have easy to create software with great function.

Before you start on higher level software, think of big picture.
You could have a one-wire temperature sensor controlling many outputs on many micro-controllers.

One-wire scan can give you a list of devices on the bus
Each device will need some data to the device & you will get some data back. You will need data for control values. You would probably like some Human data for this ID is _______

Great simple software would be using lists, arrays and structures.
Takes ram to do this.
Part of this would be creating event lists.

In place of writing a large amount of code, think of processing the data and making this easy.

You do this by having just one set of code that handles all the DS18B20's on bus and using RAM to get/save data.
To add an additional DS18B20 then becomes just setting up data after scan finds it.

In place of a serial interface to PC you you could have what looks like a USB drive to PC but Ram to controller.

Just so you know
A Raspberry Pi & linux can do One-wire. Each device is in the file tree. This lets linux software use commands for files to work with one-wire.






Docara:
Hi BradC

Please don't apologise  :)

The problem is if you don't know how to do something its always bloody difficult!! The thing is my only real experience is with the BASIC programming language years ago on the likes of BBC B Micro, Sinclair Spectrum etc or limited Assembly on a Z80 from the same time. So I'm really struggling with the logic of the C code.

At present I am looking trhrough a 1wire library for Ardiono on Github. I didn't realise you could examine code within libraries.

Does the CRC system come into play suring the search?

Matt

C:

If you want error free communications you use something like CRC to check for valid data.
So for a read you can not check CRC but will not know if there is an error.
For a write to a device that uses CRC you have to have proper value or device will think it's an error


madires:
The ROM code also includes a CRC8 to make sure that the addressing of devices is correct.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod