seemanta
Member level 4
Hi,
I am using the following routines for reading/writing from/to the DS1820 temperature sensor.
I am able to send the reset pulse and also able to get the presence pulse.
However, when sending the read scratchpad command, 0BEh, it is not working, because as per the datasheet, I am supposed to get the value as 50h. I am only getting FFh which is not correct.
I am posting the code, I would be grateful if anyone can look at it and let me know what is the mistake I am making.
SEND_BYTE and GET_BYTE are the main routines to write/read a single byte from the DS1820. Remaining are just helper routines. Also, for the moment, I am omitting the DELAY routines. Basically, I have used the delay routine for generating the bus timings.
And yes, almost forgot to mention, i/o line P2.5 is the one connected to the DQ line of the DS1820.
As always, thanks in advance for all the help I receive from this board!
regards,
Seemanta
I am using the following routines for reading/writing from/to the DS1820 temperature sensor.
I am able to send the reset pulse and also able to get the presence pulse.
However, when sending the read scratchpad command, 0BEh, it is not working, because as per the datasheet, I am supposed to get the value as 50h. I am only getting FFh which is not correct.
I am posting the code, I would be grateful if anyone can look at it and let me know what is the mistake I am making.
SEND_BYTE and GET_BYTE are the main routines to write/read a single byte from the DS1820. Remaining are just helper routines. Also, for the moment, I am omitting the DELAY routines. Basically, I have used the delay routine for generating the bus timings.
And yes, almost forgot to mention, i/o line P2.5 is the one connected to the DQ line of the DS1820.
Code:
SEND_BYTE: ;DATA TO SEND IS IN A
MOV R0,#8
_START: JB ACC.0, SEND_1
LCALL WRITE_0
JMP FWD
SEND_1: LCALL WRITE_1
FWD: RR A
DJNZ R0,_START
RET
GET_BYTE: ;DATA READ WILL BE RETURNED IN A
MOV B,#00H
MOV R0,#3
MOV R1,#3
_START2:
LCALL READ_DATA
ANL A,#20H
BACK: RL A
DJNZ R0,BACK
ORL B,A
INC R1
MOV A,R1
MOV R0,A ;R1 AND R0 ARE SAME NOW, READY FOR NEXT CYCLE.
XRL A,#11
JNZ _START2
MOV A,B
RET
WRITE_0:
CLR P2.5
LCALL DELAY_65US
SETB P2.5
RET
WRITE_1:
CLR P2.5
LCALL DELAY_12US
SETB P2.5
RET
READ_DATA:
CLR P2.5
NOP ;FOR ABOUT 1US DELAY(1.085 US, TO BE PRECISE)
NOP
SETB P2.5 ;BUS RELEASED NOW
NOP
NOP
MOV A,P2 ;READ THE DATA
SETB P2.5 ;SET BUS TO HIGH STATE AGAIN
RET
As always, thanks in advance for all the help I receive from this board!
regards,
Seemanta