one wire


Closed Thread
Results 1 to 8 of 8

Thread: one wire

  1. #1
    Join Date
    Mar 2008
    Posts
    79

    Default one wire

    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!
    Code:
    '****************************************************************
    '*  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?

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    This is from the PBP manual
    Code:
    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
    Code:
    ‘ 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...)
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Mar 2008
    Posts
    79


    Did you find this post helpful? Yes | No

    Default

    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?
    Code:
    '****************************************************************
    '*  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.
    Code:
     
    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
    Code:
    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?
    Last edited by karenhornby; - 18th June 2008 at 13:46.

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    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
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Mar 2008
    Posts
    79


    Did you find this post helpful? Yes | No

    Default

    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?
    Last edited by karenhornby; - 18th June 2008 at 15:44.

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    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.
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Post

    Hi, Karen

    1) Go here :

    http://www.maxim-ic.com/products/ibu...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/...e.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
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  8. #8
    Join Date
    Mar 2008
    Posts
    79


    Did you find this post helpful? Yes | No

    Default

    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

Similar Threads

  1. 1 Wire Search Routine
    By Dave in forum Code Examples
    Replies: 3
    Last Post: - 4th March 2016, 07:39
  2. Need Single wire serial LCD converter example
    By polymer52 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 16th December 2009, 02:30
  3. how can I make 1 wire between two pic 16f877
    By povulon in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 30th July 2008, 14:44
  4. Oscillator stops when touching with a wire
    By Wilbert Ingels in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 25th April 2008, 08:51
  5. RPM with wire and PIC
    By Dwayne in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th December 2004, 20:42

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts