Again OneWire-problems

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
CS
Posts: 127
Joined: Thu Nov 02, 2006 9:14 am

Again OneWire-problems

Post by CS » Sat Dec 02, 2006 8:12 pm

Hi all,

in an other thread David Barker told me that every sample should work. Now I'm a little bit confused (and not able to find the error).

The following program (owsearch.bas)

Code: Select all


Device = 18F452
Clock = 20

// import modules...
Include "ow.bas"
Include "convert.bas"
Include "usart.bas"

// on find event handler...
Event OnFind()
   Dim Index As Byte
   USART.Write("FAMILY $", HexToStr(SearchFamily,2))
   USART.Write(" ($",HexToStr(SearchID(7),2),")")
   USART.Write(" ($")
   Index = 6
   Repeat
      USART.Write(HexToStr(SearchID(Index),2))
      Dec(Index)
   Until Index = 0
   USART.Write(")",13,10)
End Event
 
// working variables...
Dim DeviceCount As Byte   

// program start...
SetBaudrate(br115200)
SetPin(PORTC.0)
DeviceCount = Search(owSearchROM, OnFind)
USART.Write(DecToStr(DeviceCount), " device(s) found", 13, 10)

returns 2 RomId's

1. ($BE) ($000801018F83)
2. ($6C) ($000801018B9A)

The following program (DS18B20DisplayTempAll.bas) returns nothing !!!

Code: Select all


Device = 18F452
Clock = 20

// import modules...
Include "DS18B20.bas"
Include "convert.bas"
Include "usart.bas"

// on display temperature event...
Event OnDisplayTemp()
   Dim TempA As ShortInt
   Dim TempB As Word
   Dim Index As Byte
   
   RomID = SearchRomID
   GetTemp(TempA, TempB)
   USART.Write(DecToStr(TempA),".",DecToStr(TempB,4), $BA, "C")
   
   // display ROM ID...
   USART.Write(" ($")
   Index = 6
   Repeat
      USART.Write(HexToStr(SearchRomID(Index),2))
      Dec(Index)
   Until Index = 0
   USART.Write(")",13,10)
End Event
   
// program start...
SetBaudrate(br115200)
SetPin(PORTC.0)

// if we have some DS1820 devices connected to the bus,
// then display temperature for each one...
If Count > 0 Then
   While true
      ConvertAll               
      FindAll(OnDisplayTemp)
      DelayMS(1000)
   Wend
EndIf

And the next program (DS18B20Displaytemp.bas) displays "No Device found!"

Code: Select all


Device = 18F452
Clock = 20

// import modules...
Include "DS18B20.bas"
Include "convert.bas"
Include "usart.bas"

// working variables...
Dim 
   TempA As ShortInt,
   TempB As Word
   
// program start...
SetBaudrate(br115200)
SetPin(PORTC.0)

// Find() will search the bus for a single DS1820 device
// and load its ROM ID into the DS1820 public variable RomID - you
// could do this manually. For example, RomID = MyRomID...

If Not Find Then
   USART.Write("No device found", 13, 10)
Else
   While true
      Convert
      GetTemp(TempA, TempB)
      USART.Write(DecToStr(TempA),".",DecToStr(TempB,4), $BA, "C", 13, 10)
      DelayMS(1000)
   Wend
EndIf

There is a way to set the RomId manually but I only return errors from the compiler when I try this. Wich part of the RomID (from the found one above) should I set and how?
Have anyone seen the DS1820 Samples run ok?

Thanks

CS

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Sat Dec 02, 2006 8:47 pm

You have not given the full output from the owsearch.bas example, so I cannot see the device family. Please supply the full information. Here is my output

FAMILY $28 ($3F) ($0000002CD16E)
FAMILY $05 ($F1) ($00000019F75D)
FAMILY $05 ($90) ($0000001A20B7)
FAMILY $23 ($CA) ($0000005C62EE)
4 device(s) found

CS
Posts: 127
Joined: Thu Nov 02, 2006 9:14 am

Post by CS » Sat Dec 02, 2006 9:05 pm

Sorry for that!

Here is my output:

FAMILY $10 ($6C) ($000801018B9A)
FAMILY $10 ($BE) ($000801018F83)
2 device(s)found.

Thanks

CS

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Sat Dec 02, 2006 9:08 pm

That device is a DS18S20, not a DS18B20 - different family.

CS
Posts: 127
Joined: Thu Nov 02, 2006 9:14 am

Post by CS » Sat Dec 02, 2006 10:54 pm

Hi,

can you nevertheless explain how I have to set the RomID because I think it's the same on DS18B20 or DS18S20.

My output looks like that:

FAMILY $10 ($6C) ($000801018B9A)
FAMILY $10 ($BE) ($000801018F83)
2 device(s)found.

The RomID is declared as byte( 8 ). Wich part from my RomID's must I use? And how?

Thanks
CS

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Sun Dec 03, 2006 9:22 am

> can you nevertheless explain how I have to set the RomID
> because I think it's the same on DS18B20 or DS18S20.

It's very easy. Here is an example which works with a DS18B20, using the following details (obtained from owsearch.bas)

FAMILY $28 ($3F) ($0000002CD16E)

Code: Select all

// import modules...
include "DS18B20.bas"
include "convert.bas"
include "usart.bas"

// ROM ID...FAMILY $28 ($3F) ($0000002CD16E) 
const DeviceROMID(8) as byte = ($28, $6E, $D1, $2C, $00, $00, $00, $3F)

// working variables...
dim TempA as shortint
dim TempB as word
   
// program start...
RomID = DeviceROMID
SetBaudrate(br115200)
SetPin(PORTC.0)
while true
   Convert
   GetTemp(TempA, TempB)
   USART.Write(DecToStr(TempA),".",DecToStr(TempB,2), $BA, "C",13,10)
   delayms(1000)
wend
For the DS18S20, just change

Code: Select all

include  "DS18B20.bas" --> include "DS18S20.bas" 
dim TempB as word --> dim TempB as byte

CS
Posts: 127
Joined: Thu Nov 02, 2006 9:14 am

Post by CS » Sun Dec 03, 2006 10:41 am

Hi David,

thanks for that explanation. Now it is clear, why my program doesn't run.
I used the RomId obtained from the owsearch.bas without using the family id instead i filled it with $00 (because of eight bit) I also started from the left instead of starting from the right of the returned RomID :oops:

Thanks again

CS

P.S.: Did you read the message that I got because of the problem to receive the full version of Swordfish?

Anonymous

Post by Anonymous » Thu Dec 28, 2006 10:39 pm

Gentlemen,

While trying your compiler with an Easypic4 board and aDS18S20, I ran into a problem. Not really a problem but a small issue.

Code: Select all

// if device and clock are omitted, then the compiler defaults to 
// 18F452 @ 20MHz - they are just used here for clarity...
Device = 18F4520
Clock = 8

// import modules...
Include "DS18S20.bas"
Include "convert.bas"
Include "usart.bas"

// ROM ID...FAMILY $28 ($3F) ($0000002CD16E) 
//const DeviceROMID(8) as byte = ($28, $6E, $D1, $2C, $00, $00, $00, $3F)
 
'My DS18S20 ID's
// ROM ID...FAMILY $10 ($5D) ($000800EDD7DA) 
Const DeviceROMID(8) As Byte = ($10, $DA, $D7, $ED, $00, $08, $00, $5D) 


// working variables...
Dim 
   TempA As ShortInt,
   TempB As Byte
   
// program start...
RomID = DeviceROMID 
SetBaudrate(br9600)
ADCON1 = $FF // PORTE as digital (GLCD)
SetPin(PORTA.5)


   While true
      Convert
      GetTemp(TempA, TempB)
      USART.Write(DecToStr(TempA),".",DecToStr(TempB,2), $BA, "C", 13, 10)      
      DelayMS(1000)
   Wend
The program works but issue is the temp display comes back as 23.05 C
instead of 23.50 C.
If I change the line

Code: Select all

USART.Write(DecToStr(TempA),".",DecToStr(TempB,2), $BA, "C", 13, 10)  
to

Code: Select all

USART.Write(DecToStr(TempA),".",DecToStr(TempB,4), $BA, "C", 13, 10)  
The result is 23.0005 C

Is this a problem with the library or my program example?

Thanks in advance,
Durango

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Fri Dec 29, 2006 10:52 am

> Is this a problem with the library or my program example?

It is a problem with your program example. The DS18S20 does not have the same resolution as an DS18B20. You should use

Code: Select all

USART.Write(DecToStr(TempA),".",DecToStr(TempB), $BA, "C", 13, 10) 
instead.

Post Reply