Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

DS18S20 interface with 16F84A Assebly Sample Coding

Status
Not open for further replies.
When I first played around with DS18S20 I read this document and it is all you need:

**broken link removed**

It's an excellent app note which actually walks you through the development of the code. The best thing about it is that it goes in parallel with the datasheet specification and explains everything as it progresses. You will understand the o/w 100%...
 
When I first played around with DS18S20 I read this document and it is all you need:

**broken link removed**

It's an excellent app note which actually walks you through the development of the code. The best thing about it is that it goes in parallel with the datasheet specification and explains everything as it progresses. You will understand the o/w 100%...

Thank you. Thats what i need
 
After writing the the Read Rom command, you then use a special instance of the OWin routine, by looping for eight bytes. So for instance:

Code:
Sub OWinRom
For EightBytes = 1 to 8  ;OWrom routine
    For Clocks = 1 to 8  ;OWin routine
        ...
        ...
    Next
    ;Display ROM byte or plug into ram location
Next
end sub

So basically, you are reading the scratchpad eight times to get the device ID.
 
After writing the the Read Rom command, you then use a special instance of the OWin routine, by looping for eight bytes. So for instance:

Code:
Sub OWinRom
For EightBytes = 1 to 8  ;OWrom routine
    For Clocks = 1 to 8  ;OWin routine
        ...
        ...
    Next
    ;Display ROM byte or plug into ram location
Next
end sub

So basically, you are reading the scratchpad eight times to get the device ID.

I don't think that is quite right. The Read-Rom command doesn't involve the scratch pad.

The 64 bits of the ROM (8 bits of family code - 0x10, 48 bit serial number and 8 bit CRC) just read out without a break.

Obviously, if this lot is being read with an 8 bit microprocessor, the result will be in 8 bytes of data. There would usually be a loop to read 8 bits, and that loop would be run 8 times, but there are lots of way of doing it.

Page 15 of the datasheet, on the left side of the flow diagram, shows the routine. It is:-

Master issues reset
DS18S20 issues presence pulse
Master sends 0x33
DS18S20 sends ROM contents (with each bit initiated by the master)
 
I don't think that is quite right. The Read-Rom command doesn't involve the scratch pad.
An unfortunate choice of words, its been awhile.

Since the original poster was looking at a PIC16f84A, the byte wise data seems most logical, easiest to manipulate, and read. This becomes evident when it comes time to Match Rom using data tables.
 
Yes, I've used the 0x33 command to read the 64 bit serial number on a 12F675 project;

Code:
;******************************************************************
;
;  get 64-bit serial number and device family code
;
GetSN
        owReset                 ; reset one-wire devices          |B0
        btfss   owByte,0        ; ow device found?                |B0
        return                  ; no, return, else                |B0
        owSend (h'33')          ; DS1820 'read rom' command       |B0
        owRead(owBuff,8)        ; read 8 bytes -> owBuf           |B0
        bcf     DS18B20         ; clr DS18B20 family flag         |B0
        movf    owBuf+0,W       ; get family ID byte              |B0
        xorlw   h'28'           ; is it DS18B20?                  |B0
        skpnz                   ; no, skip, else                  |B0
        bsf     DS18B20         ; set DS18B20 family flag         |B0
        return                  ;                                 |B0

;******************************************************************
 
Thank you very much for your answers.
I managed to use READ ROM [33h] command.
Now I have a problem using MATCH ROM [55h] command.
If I want to use read 2 sensors, I can only read the temperature from only one of the sensor.
If I use only one sensor with MATCH ROM [55h] command everything it is ok.
I written the ROM codes in an array in the program.
Any ideas ?
 
Thank you very much for your answers.
I managed to use READ ROM [33h] command.
Now I have a problem using MATCH ROM [55h] command.
If I want to use read 2 sensors, I can only read the temperature from only one of the sensor.
If I use only one sensor with MATCH ROM [55h] command everything it is ok.
I written the ROM codes in an array in the program.
Any ideas ?
 
I am sure there is a tricky way to read out the sensors after a SkipRom, ConvertT. You could try outside loops first for each sensor, then proceed from there. My ReadTable SensorOne would equal your SensorOne(eightbytes) array.

Code:
For count = 1 to NumSensors
    MstrRst
    MatchRom
    OWoutRom
    ConvertT
    ...
    MsterRst
    MatchRom
    OWoutRom
    ReadScratch
    OWin
    ....
    ....
count = count + 1
Next
;****************
Sub OWoutRom
    For EightBytes = 1 to 8
    If count = 1 Then ReadTable SensorOne,EightBytes, SerialNum
    If count = 2 Then ReadTable SensorTwo,EightBytes, SerialNum
    ....
    ....
    OWout (SerialNum)
    Next
end sub
 
Now I get some strange result when reading negative temperature using Temperature = Temp_read - 0.25 + ((Count_per_C - Count_Remain)/Count_per_C) formula.
 
This road has been plowed many times before, try using the forum search, or the data sheet. Next up, SearchRom? AlarmSearch? please give me schematic, source code, and hex file?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top