Hey all, i'm trying to interface the Dallas DS18S20 with a PIC 16F628 and having some problems. I can't even get the PIC to detect the presense pulse generated by the sensor. Here's my code, i've got the data line of the sensor on bit 0 on porta.
Macros
Code:
TEMP_OUTPUT macro
BANK1 ;Change to BANK1
bcf TRISA,0 ;Set PORTA,0 to an output
BANK0 ;Back to BANK0
bcf PORTA,0 ;Set output pin LOW
endm
TEMP_INPUT macro
BANK1 ;To BANK1 again
bsf TRISA,0 ;Set PORTA,0 to an input
BANK0 ;Back to BANK0
endm
The NO_OW_DETECT routine is just sending something to an attached LCD to tell me the sensor has not been found, I haven't been able to get it to skip that at all yet, even though the sensor should be pulling that pin low.
Hopefully someone with some experience with these can help me out.
Making 1-wire devices work is very difficult if you are doing it for the first time. I have a very bad experience with them. It takes a lot of trial and error cycles to write your own routines to communicate with them because timings are very critical over here. Make sure that your delay 250uS routines are much accurate. Also count the over-head that it takes in calling a delay routine and suctract it from the delay count because all timings are in micro-seconds so over-head makes a lot of difference. In 8051 calling a subroutine takes 24uS@12MHz and if you don't consider that it doesn't work.
Do you think i'm waiting too long and missing the pulse then? I learnt the delay routines i'm using here from veys.com, he explains them very well and they have worked great for me in the past.
Did you get yours going in the end? It says in the datasheet to hold the output pin low for 480uS minimum, but i'm holding for 500uS so that shouldn't be a problem. Then it says the sensor waits 15-60uS before pulling the line low after detecting the rising edge, so i've waited 60 there. Only other thing it says is to keep the master rx for 480uS minimum, which I haven't done because I didn't think it would matter, i've just switched it right back to an output after checking the pin to see if it's clear.
Yes I got my setup running when I counted the over-head delay and subtracted it from delay count. My delay routine rounds off to 488uS for first step & 72uS for the second step.
My routine goes like this
DQ = 0
delay 480 ; ~488uS
DQ = 1
delay 60 ; ~72uS
present = DQ
delay 400 ; ~424uS
Stop
Damn, thought i'd found something then. Oh well, time to check all my timings again then, it must be those that are at fault. I have checked them with ISIS simulating my code, and I graphed the output and it all seems ok, if only there was a 1-wire library for it.