Problems with 1-Wire DS2438 and PIC16F88


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Code:
    OWOUT DQ_Pin,1,[$CC, $BE, $00] ' Skip ROM search, send Convert V, Read page 00h
    OWIN DQ_Pin,2,[voltage.lowbyte, voltage.highbyte] ' Read two bytes
    $BE is the Read Scratchpad command. (just a comment prob)

    The Read Scratchpad command always starts reading at address 0 of the selected page.

    The first 2 bytes of page 0 are STATUS/CONFIGURATION and TEMP LSB.
    The STATUS/CONFIGURATION defaults to 1's, which is probably what you're seeing.

    The Voltage value is at addresses 3-4, so you'll need to read at least 5 bytes to get to the Voltage.

    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=3415&stc=1&d=124285359 2">
    Attached Images Attached Images  
    DT

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Here's an easy way to read the whole page ...

    Using a technique shown here (Typcasting Variables inside of Arrays)

    Code:
    <font color="#000000"><b>DSbuffer  </b><font color="#008000"><b>VAR BYTE</b></font>[<font color="#800000"><b>9</b></font>] <b>BANK0</b>
    <font color="#008000"><b>ASM
    </b></font><font color="#000080">DSstat    = _DSbuffer      </font><font color="#0000FF"><b><i>; byte
    </i></b></font><font color="#000080">DStemp    = _DSbuffer + 1  </font><font color="#0000FF"><b><i>; word
    </i></b></font><font color="#000080">DSvolts   = _DSbuffer + 3  </font><font color="#0000FF"><b><i>; word
    </i></b></font><font color="#000080">DScurrent = _DSbuffer + 5  </font><font color="#0000FF"><b><i>; word
    </i></b></font><font color="#000080">DSthres   = _DSbuffer + 7  </font><font color="#0000FF"><b><i>; byte
    </i></b></font><font color="#000080">DScrc     = _DSbuffer + 8  </font><font color="#0000FF"><b><i>; byte
    </i></b></font><font color="#008000"><b>ENDASM
    
    </b></font><b>DSstat    </b><font color="#008000"><b>VAR  BYTE  </b></font><b>EXT </b><font color="#0000FF"><b><i>; Status/Configuration
    </i></b></font><b>DStemp    </b><font color="#008000"><b>VAR  WORD  </b></font><b>EXT </b><font color="#0000FF"><b><i>; Temperature
    </i></b></font><b>DSvolts   </b><font color="#008000"><b>VAR  WORD  </b></font><b>EXT </b><font color="#0000FF"><b><i>; Voltage
    </i></b></font><b>DScurrent </b><font color="#008000"><b>VAR  WORD  </b></font><b>EXT </b><font color="#0000FF"><b><i>; Current
    </i></b></font><b>DSthres   </b><font color="#008000"><b>VAR  BYTE  </b></font><b>EXT </b><font color="#0000FF"><b><i>; Threshold
    </i></b></font><b>DScrc     </b><font color="#008000"><b>VAR  BYTE  </b></font><b>EXT </b><font color="#0000FF"><b><i>; CRC</i></b></font>
    Then you can read page 0 like this ...<table><tr><td>
    Code:
    <font color="#008000"><b>OWOUT </b></font><b>DQ_Pin</b>,<font color="#800000"><b>1</b></font>,[<font color="#800000"><b>$CC</b></font>, <font color="#800000"><b>$B8</b></font>, <font color="#800000"><b>$00</b></font>] <font color="#0000FF"><b><i>' Skip ROM search, Recall Memory page 0
    </i></b></font><font color="#008000"><b>OWOUT </b></font><b>DQ_Pin</b>,<font color="#800000"><b>1</b></font>,[<font color="#800000"><b>$CC</b></font>, <font color="#800000"><b>$BE</b></font>, <font color="#800000"><b>$00</b></font>] <font color="#0000FF"><b><i>' Skip ROM search, Read page 0
    </i></b></font><font color="#008000"><b>OWIN  </b></font><b>DQ_Pin</b>,<font color="#800000"><b>2</b></font>,[<font color="#008000"><b>STR </b></font><b>DSbuffer</b>\<font color="#800000"><b>9</b></font>]<font color="#0000FF"><b><i>' Read 9 bytes</i></b></font>
    </td><td valign=top><br><br>Recall Memory added: see next few posts.</td></tr></table>
    After reading, all the values will be in the correct variables, with the correct size (word/byte), ready to be used.

    hth,
    Last edited by Darrel Taylor; - 22nd May 2009 at 01:22. Reason: Recall

  3. #3
    Join Date
    May 2009
    Location
    Philadelphia, PA
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    Thanks for your help, Darrel! Your EXT methods will be a great help with other projects.

    After adding in your code, I noticed that the raw data was still a series of 1's. I switched to a DS18B20 using your suggested code (with slight modification to the one-wire commands) and it worked perfectly.

    For kicks, I removed all of the 1-Wire devices and the raw data is still showing 1's. Seems like the PIC is reading the pin's state (pulled up with a resistor) rather than the data coming over the DQ wire. While the wiring and code seem correct and appear to conform with the datasheets, perhaps I'm missing something?

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Try adding this before the Read command. (after the conversion)

    Code:
    OWOUT DQ_Pin,1,[$CC, $B8, $00] ' Recall Memory page 0
    From the datasheet ...
    Recall Memory [B8hxxh]
    This command recalls the stored values in EEPROM / SRAM page xxh to the scratchpad page xxh.
    This command must proceed a Read SPxx command in order to read any page of memory on the DS2438.
    hth,
    DT

  5. #5
    Join Date
    May 2009
    Location
    Philadelphia, PA
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    That worked perfectly. While I figured the recall function was a bit redundant, after some more studying of the datasheet, it now makes sense. I'll post the complete code and schematic once I've completed the project.

    Thanks for your help, Darrel.

Members who have read this thread : 1

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