Problem with DS18s20, only showing -1.05 Solved!

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

bunny-rabbit
Posts: 42
Joined: Fri Jan 18, 2008 10:39 am
Location: Emmen/ Netherlands

Problem with DS18s20, only showing -1.05 Solved!

Post by bunny-rabbit » Fri May 08, 2009 5:52 pm

Hello!

I have connected a DS18s20 to my 18F452 but all it returns is -1.05

How is this possible?

My code:

Code: Select all

Device = 18F452
Clock = 10
Config OSC = HSPLL


#option GLCD_MODEL = S1D13700    
#option GLCD_MODE = 8080         // GLCD interface mode - 6800 or 8080
#option GLCD_DATA = PORTD        // data port
#option GLCD_EN = PORTE.2        // EN pin - 6800 mode
#option GLCD_RD = PORTE.2        // RD pin - 8080 mode
#option GLCD_RW = PORTB.1        // RW pin - 6800 mode
#option GLCD_WR = PORTE.1        // WR pin - 8080 mode
#option GLCD_A0 = PORTE.0        // A0 pin
#option GLCD_CS = PORTC.4        // chip select
#option GLCD_RES = PORTC.5       // reset pin

#option OW_PIN = PORTB.0



include "glcd.bas"
include "DS18s20.bas" 
include "convert.bas" 
include "tahoma.bas"
include "utils.bas" 

// ROM ID...FAMILY $10 ($64) ($00 08 01 9E BC 22) 
const DeviceROMID(8) as byte = ($10, $22, $BC, $9E, $01, $08, $00, $64) 

// working variables... 
dim TempA as shortint 
dim TempB as byte  

Sub Initialize()

   SetPin(PORTB.0)
   setalldigital()
   SetFont(Tahoma)
   High(PORTB.4)
   High(PORTC.2)
   High(PORTB.2)
   High(PORTB.3)
   
End Sub




Initialize()

// program start... 
RomID = DeviceROMID 

while true 
   cls(1)
   Convert 
   GetTemp(TempA, TempB) 
   Writeat(50, 100, DecToStr(TempA), ".", DecToStr(TempB,2))
    
   delayms(1000) 
wend
I tested it with the OW module. It found 1 device.

I wired the ds18s20 like this>

pin 1 GND
pin 2 PORTB.0
pin 3 5V

with a 4.7K resistor between 5V and PORTB.0

Thanks in advance!

Greets,
Gert
Last edited by bunny-rabbit on Mon May 11, 2009 9:40 pm, edited 1 time in total.

CharlieM
Registered User
Registered User
Posts: 211
Joined: Wed Oct 10, 2007 12:05 am

Post by CharlieM » Fri May 08, 2009 9:40 pm

Hi Gert,

I also had a lot of trouble with the DS18S20 module. You can try this code and see if it works for you. You will have to change the includes and the pic to suit your needs.

Code: Select all

Device = 18F4431 
Clock = 20
Config 
   OSC = HS,
   FCMEN = OFF,
   IESO = OFF,
   BOREN = OFF,
   BORV = 20,
   WDTEN = OFF,
   STVREN = OFF,
   LVP = OFF,
   DEBUG = OFF
 
Include "EP4_LCD.bas" 
Include "DS18S20.BAS"
Include "OW.BAS"
Include "convert.bas" 
Include"Utils.bas"            
 
// working variables... 
Dim Temperature As Word    
 
Dim TempString As String 
// program start... 
SetPin (PORTA.5)
SetAllDigital
             //power DS18S20 
          //One Wire is on A3 - needs pullup 
LCD.Cls
While 1 = 1 
If(Reset)Then               //returns true if device found 
    WriteByte(owSkipROM)    //Skip ROM 
    WriteByte($44)          //Convert 
    WaitForHigh()           //Wait for conversion to complete 
    Reset() 
    WriteByte(owSkipROM)    //Skip Rom 
    WriteByte($be)          //Read Scratch Pad 
    Temperature=ReadByte() 
    Temperature=Temperature+ReadByte()*256 
    TempString = DecToStr(Temperature*5)   // get temperature * 10 
//this is a bodge to display temperature with one decimal place
       
    LCD.WriteAt(1,1,"Temp=",TempString(0),TempString(1),".",TempString(2)," Deg C") 
//to just display it normal use this next line 
   ' LCD.WriteAt(1,1,"Temp = ",DecToStr(Temperature/2)," Deg C") 
    //Reset() 
  //  WriteByte(owReadROM)    //read rom 
   // For i=0 To 7 
   //    LCD.WriteAt(2,(7-i)*2,HexToStr(ReadByte,2)) 
    //Next 
Else 
   LCD.WriteAt(1,1,"No Device Found!") 
EndIf
Wend 
End
HTH
Running version 2.2.4.0 ICC 1.2.1.0
Regards CharlieM

bunny-rabbit
Posts: 42
Joined: Fri Jan 18, 2008 10:39 am
Location: Emmen/ Netherlands

Post by bunny-rabbit » Sat May 09, 2009 10:26 am

Thnx for your reply. :).

I now only get 24,4 Deg.

Strange :(..

CharlieM
Registered User
Registered User
Posts: 211
Joined: Wed Oct 10, 2007 12:05 am

Post by CharlieM » Sat May 09, 2009 12:06 pm

What is your hardware setup? is it a bread board or a development board of some kind? I tested the code I posted on a 18F4431 and a Easypic4 development board and it works good.
Running version 2.2.4.0 ICC 1.2.1.0
Regards CharlieM

bunny-rabbit
Posts: 42
Joined: Fri Jan 18, 2008 10:39 am
Location: Emmen/ Netherlands

Post by bunny-rabbit » Sat May 09, 2009 12:40 pm

Its my own PCB design.

What can be wrong?
I have a 4.7k pull up on de data, is that correct?

When i search for the device it finds it every time, so my harware is good, isn't it?

CharlieM
Registered User
Registered User
Posts: 211
Joined: Wed Oct 10, 2007 12:05 am

Post by CharlieM » Sat May 09, 2009 1:47 pm

Yes 4.7K on the data line is right.The only other thing I can think of is are yu sure that you have a 18S20 and not a 18B20?
Running version 2.2.4.0 ICC 1.2.1.0
Regards CharlieM

bunny-rabbit
Posts: 42
Joined: Fri Jan 18, 2008 10:39 am
Location: Emmen/ Netherlands

Post by bunny-rabbit » Sat May 09, 2009 2:00 pm

Yes its definitely a DS18S20.

I tried a new one but still nothing.

OW says the following:

Family : $10 / $F5

00 08 01 9E E7 E7

So the hardware must be ok right?

CharlieM
Registered User
Registered User
Posts: 211
Joined: Wed Oct 10, 2007 12:05 am

Post by CharlieM » Sat May 09, 2009 2:09 pm

Ok so what code are you using now? yours or the one I posted?
Running version 2.2.4.0 ICC 1.2.1.0
Regards CharlieM

bunny-rabbit
Posts: 42
Joined: Fri Jan 18, 2008 10:39 am
Location: Emmen/ Netherlands

Post by bunny-rabbit » Sat May 09, 2009 2:11 pm

The one you posted..

CharlieM
Registered User
Registered User
Posts: 211
Joined: Wed Oct 10, 2007 12:05 am

Post by CharlieM » Sat May 09, 2009 2:15 pm

Ok the code I posted does not need or look for a device ID. you just connect the device and it works.
Running version 2.2.4.0 ICC 1.2.1.0
Regards CharlieM

bunny-rabbit
Posts: 42
Joined: Fri Jan 18, 2008 10:39 am
Location: Emmen/ Netherlands

Post by bunny-rabbit » Sat May 09, 2009 2:23 pm

No i just wanted you to know that my OW device is working.

I copyed your code directly, only thing i did was change some things so it would work on my pic.

What i use:

Code: Select all

Device = 18F452
Clock = 40
Config OSC = HSPLL 
 

#option GLCD_MODEL = S1D13700    
#option GLCD_MODE = 8080         // GLCD interface mode - 6800 or 8080
#option GLCD_DATA = PORTD        // data port
#option GLCD_EN = PORTE.2        // EN pin - 6800 mode
#option GLCD_RD = PORTE.2        // RD pin - 8080 mode
#option GLCD_RW = PORTB.1        // RW pin - 6800 mode
#option GLCD_WR = PORTE.1        // WR pin - 8080 mode
#option GLCD_A0 = PORTE.0        // A0 pin
#option GLCD_CS = PORTC.4        // chip select
#option GLCD_RES = PORTC.5       // reset pin
  
Include "GLCD.bas" 
Include "DS18S20.BAS" 
Include "OW.BAS" 
Include "convert.bas" 
Include "Utils.bas"            
Include "FixedFont.bas"  
// working variables... 
Dim Temperature As Word    
  
Dim TempString As String 
// program start...
High(PORTC.2) 
SetPin (PORTB.0) 
SetAllDigital 
GLCD.SetFont(Fixed)
             //power DS18S20 
          //One Wire is on A3 - needs pullup 
Cls(1) 
While 1 = 1 
If(Reset)Then               //returns true if device found 
    WriteByte(owSkipROM)    //Skip ROM 
    WriteByte($44)          //Convert 
    WaitForHigh()           //Wait for conversion to complete 
    Reset() 
    WriteByte(owSkipROM)    //Skip Rom 
    WriteByte($be)          //Read Scratch Pad 
    Temperature=ReadByte() 
    Temperature=Temperature+ReadByte()*256 
    TempString = DecToStr(Temperature*5)   // get temperature * 10 
//this is a bodge to display temperature with one decimal place 
        
    WriteAt(1,20,"Temp=",TempString(0),TempString(1),".",TempString(2)," Deg C") 
//to just display it normal use this next line 
   ' LCD.WriteAt(1,1,"Temp = ",DecToStr(Temperature/2)," Deg C") 
    //Reset() 
  //  WriteByte(owReadROM)    //read rom 
   // For i=0 To 7 
   //    LCD.WriteAt(2,(7-i)*2,HexToStr(ReadByte,2)) 
    //Next 
Else 
   WriteAt(1,20,"No Device Found!") 
EndIf 
Wend 
End

CharlieM
Registered User
Registered User
Posts: 211
Joined: Wed Oct 10, 2007 12:05 am

Post by CharlieM » Sat May 09, 2009 2:42 pm

You can try using #option ow_pin = PORTB.0 instead of set pin portb.0
Running version 2.2.4.0 ICC 1.2.1.0
Regards CharlieM

bunny-rabbit
Posts: 42
Joined: Fri Jan 18, 2008 10:39 am
Location: Emmen/ Netherlands

Post by bunny-rabbit » Sat May 09, 2009 2:45 pm

Same result :(..

User avatar
ohararp
Posts: 194
Joined: Tue Oct 03, 2006 11:29 pm
Location: Dayton, OH USA
Contact:

Post by ohararp » Sat May 09, 2009 3:56 pm

bunny, I am almost certain the code is written for the DS18B20. The DS18S20 will not work. Where did you get the DS18S20 library?
Thanks Ryan
$25 SMT Stencils!!!
www.ohararp.com/Stencils.html

bunny-rabbit
Posts: 42
Joined: Fri Jan 18, 2008 10:39 am
Location: Emmen/ Netherlands

Post by bunny-rabbit » Sat May 09, 2009 6:15 pm

ok i now have a DS18B20 running still the same...

I used the swordfish DS18S20 library...

Post Reply