PDA

View Full Version : one wire



karenhornby
- 18th June 2008, 12:35
Has anyone any suggestions on how to read the id code from 1wire products?
I've read up on the 1wire project on Rentron.com and have a slight problem
the code below assumes you have a serial 4 X 20 LCD
HOW would I modify this to work with a normal parallel 4 X 20 lcd module as I havent figured out how to convert it to serial yet, and it would be great if this code could be made work on a "normal" lcd module, or someone can give me ideas on it please?

What I eventually want to do is have 2 ds18b20's and actually use the 1wire properly instead of having them on seperate ports!


'************************************************* ***************
'* Name : 1-Wire-ID.Bas *
'* Author : Bruce Reynolds *
'* Date : 11/10/2001 *
'* Version : 1.0 *
'* Notes : 1-Wire Identifier *
'* ; Identifies & Prints 1-Wire Device Information *
'* : Uses 20 x 4 Serial LCD for Display *
'************************************************* ***************
DEFINE LOADER_USED 1 ' Boot loader is being used
DEFINE DEBUG_MODE 1 ' Send Inverted serial data with debug
DEFINE DEBUG_REG PortB ' Debug Port = PortB
DEFINE DEBUG_BIT 0 ' Debug.bit = PortB.0
DEFINE DEBUG_BAUD 9600 ' Default baud rate = 9600
DEFINE OSC 4 ' We're using a 4 MHz oscillator
DQ VAR PortC.0 ' One-wire data pin "DQ" on PortC.0
Clr CON 1 ' Serial LCD command to clear LCD
LINE1 CON 128 ' Line #1 of serial LCD
LINE2 CON 192 ' Line #2 of serial LCD
LINE3 CON 148 ' Line #3 of serial LCD
LINE4 CON 212 ' Line #4 of serial LCD
Ins CON 254 ' Instruction for LCD command-mode
ID VAR BYTE[8] ' Array storage variable for 64-bit ROM code

Begin:
PAUSE 500 ' Wait .5 second
DEBUG Ins,Clr ' Clear LCD on power-up

Start_Convert
OWOUT DQ, 1, [$33] ' Issue Read ROM command

ID_Loop:
OWIN DQ, 0, [STR ID\8]' Read 64-bit device data into the 8-byte array "ID"
DEBUG Ins,Line1,"Family Code = ",HEX2 ID[0],"h"
DEBUG Ins,Line2,"Ser# = ",HEX2 ID[1],HEX2 ID[2],HEX2 ID[3],HEX2 ID[4],HEX2 ID[5],HEX2 ID[6],"h"
DEBUG Ins,Line3,"CRC Value = ",HEX2 ID[7],"h"
ID_Device:
IF ID[0] = $5 THEN
DEBUG Ins, Line4, "Device = Switch "
ENDIF
IF (ID[0] = $28) OR (ID[0] = $22) THEN
DEBUG Ins,Line4, "Device = Temp Sensor"
ENDIF
IF ID[0] = $01 THEN
DEBUG Ins,Line4, "Device = Serial # "
ENDIF
PAUSE 10000 ' 10-second pause
GOTO Start_Convert

END


OR I noticed in his description he said...
The code is easy to convert to any PIC, and the serial LCD can easily be replaced by using any RS-232 terminal program.

Can anyone give me any ideas on doing this? as it would be a lot simpler to have a small board to plug the individual ds18b20's (or any other 1wire device) in and just read the 64-bit ROM number from each one and display on the pc, saves wasting an lcd module! I presume I'd just have to have a small board with a 5v regulator and that should be able to be powered from the com port? any clues as to how to communicate with the 1wire device or what program/commands?

mackrackit
- 18th June 2008, 12:54
This is from the PBP manual


Command Operation
$FE, 1 Clear display
$FE, 2 Return home
$FE, $0C Cursor off
$FE, $0E Underline cursor on
$FE, $0F Blinking cursor on
$FE, $10 Move cursor left one position
$FE, $14 Move cursor right one position
$FE, $80 Move cursor to beginning of first line
$FE, $C0 Move cursor to beginning of second line
$FE, $94 Move cursor to beginning of third line
$FE, $D4 Move cursor to beginning of fourth line

$FE is the same as Ins CON 254

Make sure you have the DEFINES like the manual has with the exception of


‘ Set number of lines on LCD
DEFINE LCD_LINES 2

Change to 4

And follow the schematic, POT and all (several seem to not use the pot and wonder why it will not work, some LCDs will not require it, but when in doubt...)

karenhornby
- 18th June 2008, 13:18
Thanks, that actually helped a LOT, even though it threw me at first and I had to read it several times...

IF I've got what your saying right, the code to use a standard 4 line lcd module becomes this?

'************************************************* ***************
'* Name : 1-Wire-ID.Bas *
'* Author : Bruce Reynolds, modified by Me! *
'* Date : 18/16/2008 *
'* Version : 1.1 *
'* Notes : 1-Wire Identifier *
'* ; Identifies & Prints 1-Wire Device Information *
'* : Uses 20 x 4 PARELLEL LCD for Display *
'************************************************* ***************
DEFINE LOADER_USED 1 ' Boot loader is being used
DEFINE OSC 4 ' We're using a 4 MHz oscillator
DQ VAR PortC.0 ' One-wire data pin "DQ" on PortC.0

ID VAR BYTE[8] ' Array storage variable for 64-bit ROM code

Begin:
PAUSE 500 ' Wait .5 second
lcdout $fe, 1 ' Clear LCD on power-up

Start_Convert
OWOUT DQ, 1, [$33] ' Issue Read ROM command

ID_Loop:
OWIN DQ, 0, [STR ID\8]' Read 64-bit device data into the 8-byte array "ID"
lcdout $FE, $80 "Family Code = ",HEX2 ID[0],"h"
lcdout $FE, $C0"Ser# = ",HEX2 ID[1],HEX2 ID[2],HEX2 ID[3],HEX2 ID[4],HEX2 ID[5],HEX2 ID[6],"h"
lcdout $FE, $94 "CRC Value = ",HEX2 ID[7],"h"
ID_Device:
IF ID[0] = $5 THEN
lcdout $FE, $D4, "Device = Switch "
ENDIF
IF (ID[0] = $28) OR (ID[0] = $22) THEN
lcdout $FE, $D4 "Device = Temp Sensor"
ENDIF
IF ID[0] = $01 THEN
lcdout $FE, $D4 "Device = Serial # "
ENDIF
PAUSE 10000 ' 10-second pause
GOTO Start_Convert

END
And follow the schematic, POT and all (several seem to not use the pot and wonder why it will not work, some LCDs will not require it, but when in doubt...)
POT??? Didn't actually see a schematic. I'm assuming you mean the pot to vary the contrast of the lcd?

Oh sorry 2 other things
I assume this can be used with most small pic's ?
2nd one
Using a DS2405 switch, am I right in thinking that once I've sent a command to either turn it on or off then it stays latched in that state untill it's addressed again and told to do something else?

Just seen another problem.


OWOUT DQ, 1, [$55,$05,$C5,$C3,$08,$00,$00,$00,$CD]' Match ROM, byte-sized, reset before
I understand the $55 is Match rom BUT it says

The red hexadecimal number $55 is the command for Match ROM.
The blue hexadecimal numbers $05,$C5,$C3,$08,$00,$00,$00,$CD
are the unique 64-bit ROM code numbers inside the specific DS2405
addressable 1-wire switch we're trying to communicate with.
The problem I have is the hex code for the device
Using his device ID routine (above) it comes back with an example but only shows 6 sets of 2digit Hex numbers but above addressing the 1wire units, it shows the address as 8 sets of 2 digits

UNLESS? in his example aboe the $05 is the family code, and the $CD at the end is the CRC code??
So any device I want to address I'd put the Family code first then the 64bit address then finish it with the CRC code?

mackrackit
- 18th June 2008, 15:16
The LCD code looks OK. Have you tried it yet? Yes, it will work with any PIC with enough pins.

POT??? Didn't actually see a schematic. I'm assuming you mean the pot to vary the contrast of the lcd?The drawing is at the end of the LCD section in the PBP manual.

I will have to leave the one wire stuff for someone else. Sorry

karenhornby
- 18th June 2008, 15:40
Thats fine thanks :)
Actually I've only skipped through the manual to bits I really need to research that I cant find answers elsewhere, but I found the easiest and best way to learn was study other bits of code and try and figure out whats going on, then modify it to do what I want, adding other bits as I need.
Probably the wrong way but it works for me, although i might annoy some people with so many questions!
No havent tried it yet, I'm trying to work out the whole code before I build the project then I can just program it and try the various sections in "situ" although I will have to build a small board just to get the rom address of the 1wire devices I have!
Although I might make it a bit more interesting by adding a header or an ICD2 or Pickit2 and a zif socket then I can use the board to get the addresses, AND program the pics
OH anyone know the answer to this?
IF I make the mclr pin an input will the pic still program ok If i just oplug it into a programmer? I wont disable it's ability to be programmed if all pins are designated inputs or outputs?

mackrackit
- 18th June 2008, 16:11
IF I make the mclr pin an input will the pic still program ok If i just oplug it into a programmer? I wont disable it's ability to be programmed if all pins are designated inputs or outputs?
The only thing to watch out for is the high voltage (13 v or so) on MCLR during programing. Some sort of isolation is all that is needed . Anything from a diode to a switch. Remember, MCLR pin can only be an INPUT.

You have the PICKIT2 docs? There are isolation drawings there and I think on the PBP web site.

Acetronics2
- 18th June 2008, 17:32
Hi, Karen

1) Go here :

http://www.maxim-ic.com/products/ibutton/software/tmex/index.cfm

download the soft corresp. to you system ...

2) Download the dS2480 Datasheet ... and get one or two of them ( think to the SAMPLES !!! )

3) Give me a PM mail where I can send you the Scheme, PCB and parts placement.

OR

Build THAT ...

http://www.elektor.de/jahrgang/2008/juni/thermo-snake.497315.lynkx

You'll be able to read the Device IDs ...

OR

Just read your Datasheet ...



READ ROM [33h]
This command can only be used when there is one slave on the bus. It allows the bus master to read the
slave’s 64-bit ROM code without using the Search ROM procedure. If this command is used when there
is more than one slave present on the bus, a data collision will occur when all the slaves attempt to
respond at the same time.





64-BIT LASERED ROM CODE
Each DS18B20 contains a unique 64–bit code (see Figure 6) stored in ROM. The least significant 8 bits
of the ROM code contain the DS18B20’s 1-Wire family code: 28h. The next 48 bits contain a unique
serial number. The most significant 8 bits contain a cyclic redundancy check (CRC) byte that is
calculated from the first 56 bits of the ROM code. A detailed explanation of the CRC bits is provided in
the CRC GENERATION section. The 64-bit ROM code and associated ROM function control logic allow
the DS18B20 to operate as a 1-Wire device using the protocol detailed in the 1-WIRE BUS SYSTEM
section of this datasheet.
64-BIT LASERED ROM CODE Figure 6
8-BIT CRC 48-BIT SERIAL NUMBER 8-BIT FAMILY CODE (28h)
MSB LSB MSB LSB MSB LSB



and buid a little application just to read the ID ...

Something more ???

Alain

karenhornby
- 18th June 2008, 20:24
Totally perfect thanks :)
not sure if I'll buy the usb adaptor or just make the interface yet but really good info and exactly what I was looking for
I would just make an interface but it's going to take a few weeks for samples or orders to get from US to UK so might be easier just to buy the usb one made up
especially as they are srface mount devices and I cant guarantee my hand or eyes are good enough to work with them