Problems with 1-Wire DS2438 and PIC16F88
I've hit a road block while attempting to gather data off a Dallas DS2438 1-Wire Battery Monitor using a PIC16F88. Initially the script and wiring seemed correct. I've used a similar setup for a Dallas DS18B20 Temp Sensor and it worked like a charm. I assumed the sensor was damaged, but after giving 5 more a try, I figured I would post to see if anyone else had a suggestion.
The raw return is a bunch of 1's on the LCD. I've tried many different options, but with the same result.
Below is the PICBasic code I've been working with (although messy, but I'll fix later after I gain communication with the sensor) and a schematic. Any and all feedback is appreciated.
DS2438 Datasheet: http://datasheets.maxim-ic.com/en/ds/DS2438.pdf
PIC16F88 Datasheet: http://ww1.microchip.com/downloads/e...doc/30487c.pdf
DEFINE OSC 20 ' We're using a 20MHz oscillator
DQ_Pin VAR PORTB.2 ' One-wire Data-Pin "DQ" on PortB.2
Busy VAR BIT ' Busy Status-Bit
ANSEL = %00000000 ' set the AN's to digital
voltage VAR word
DEFINE DEBUG_REG PORTB ' Debug Port = PortB
DEFINE DEBUG_BIT 1 ' Debug.bit = 1
DEFINE DEBUG_BAUD 9600 ' Default baud rate = 9600
DEFINE DEBUG_MODE 1 ' Send Inverted serial data with debug
high PORTB.0 ' Proof of life LED
pause 500 'Let the LCD warm up
Start_Convert:
OWOUT DQ_Pin,1,[$CC, $B4] ' send voltage conversion command
Wait_Up:
OWIN DQ_Pin, 4, [Busy] ' Read busy-bit
IF Busy = 0 THEN Wait_Up ' Still busy..?, Wait_Up..!
PAUSE 15 ' Give it some time
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
GOSUB Convert_Volt
GOTO Start_Convert
Convert_Volt:
DEBUG $FE,$01 ' Clear the LCD
DEBUG "Voltage:" ,Dec voltage.Highbyte/100,".", DEC1 voltage.Lowbyte/10,"v",10,13 ' needs to be modified
DEBUG "Raw:", IBIN16 voltage, 10,13
pause 1000 ' Wait 1 second then loop
RETURN
END
http://146.145.203.135/images/DS2438-Schematic.jpg
DS2438 not clearing scratchpad
I’ve pulled out the logic analyzer to make sure the WriteScratchpad command was actually being sent. It is, USBee results after sending:
OWOUT GB1net,1,[SkipROM, WriteScratchpad,$00,$00]
OWOUT GB1net,1,[SkipROM, RecallMemory, $00]
OWOUT GB1net,1,[SkipROM, ReadScratchpad, $00]
OWIN GB1net,2,[STR DSbuffer\9]
Presences Pulse
CC < SkipROM
4E < WriteScratchpad
00 < Page 0
00 < write on byte of data “$00”
Reset Pulse
Presences Pulse
CC < SkipROM
B8 < RecallMemory
00 < Page 0
Reset Pulse
Presences Pulse
CC < SkipROM
BE < ReadScratchpad
00 < Page 0
0F < page 0, byte 0 status/configuration register was never set to $00
E8
15
28
03
00
00
00
4A <crc
Reset Pulse
Presences Pulse
I’ve changed DS2438 and get the same results?
Now what, most of the hair has already been sacrificed!
The world is not always as it appears!
OK, so you shouldn’t always jump to conclusions even if you have reason to do so. As stated in my previous post the scratchpad/config file is reading back $OF after being set to $00. I assumed the Vad was not working. I was wrong. It is working. It now appears the configuration bit Page $00 byte $00 bit.3 is clearing to allow Vad to function however ReadScratchpad config register always reads default values (?) The Vad is working fine. My only gripe is that I have to set the Vad bit on every loop before a convert. All other registers are changing as they should and read values as expected. I’ve ask Maxim if this is normal, no reply as yet. It acts as if the config register changes to default when read, weird.
Darrel, thanks for the reply, your right about the mode. I am still going to play around with the ReadScratchpad command to see if I can find some trick to make the DS2438 function as I think it should. Grain Moisture Content project is underway.