Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:57 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Multiple onewire devices

     Page 1 of 3    
Author Message
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 05:07am 14 Aug 2020
Copy link to clipboard 
Print this post

The CMM2 has the TEMPR function.
It works for situations where there is only one device connected to a pin.
This is the usual condition but there are times when a string of multiple devices is desired.

A few years ago jman produced a subroutine to enumerate multiple devices but it was restricted to 3 devices. This seems to have been a common problem with Arduino code as well.

This function ow_search() has been tested with 5 devices on both the CMM2 and micromite.
5 was all I could find but I am reasonably confident that it will work for any number.
It has two parameters: Pin number and flag.
If flag is non zero, the search function is reset allowing a fresh search to be done.
Normally, flag can be omitted and if it’s the first time the function is run, it starts a full search without the need for a reset.
If the search is repeated until an empty string is returned, this indicates that all devices have been found and the function is reset ready for another search.

The second function, ow_Tempr() takes 3 parameters.
Pin number, bit resolution and romcode as a string.
If bit number is omitted, the resolution is set to the default of 10 bits
If romcode$ is omitted, it assumes that there is only one device.
Just like the built-in TEMPR function, running the function with multiple devices attached will give wrong results with no error message.
Multiple devices require a romcode$

The ow_Tempr() function should also work with CS1820 and DS18S20 devices.
I don’t have any to test.

As well as the two functions, there is a short test program to demonstrate the functions.

With my 5 devices connected
16
-0.25

283053F3050000E4   75  19
283053F3050000E4   149  18.75
283053F3050000E4   297  18.875
283053F3050000E4   594  18.8125

2862D8F105000018   75  18
2862D8F105000018   150  18
2862D8F105000018   300  18
2862D8F105000018   598  17.9375

28CAA0F20500003E   75  18
28CAA0F20500003E   149  18
28CAA0F20500003E   298  18
28CAA0F20500003E   596  17.875

28AA42A3411401D5   90  18
28AA42A3411401D5   180  17.75
28AA42A3411401D5   359  17.625
28AA42A3411401D5   719  17.625

2877FCF10500004F   74  18
2877FCF10500004F   149  18.25
2877FCF10500004F   298  18.25
2877FCF10500004F   595  18.125

The first two lines are results from TEMPR and my function with no romcode$
Both are wrong and will vary depending on the combination of devices attached.

This is followed by searching for rom codes and the retrieving the temperature at each resolution. It also times the function as this can be an indication of suspect chips.

The odd one out is my recent purchase from Jaycar.

The functions:
 ' one-wire search and read mutiple devices on one pin
 ' also should read DS18S20 and DS1820 as well as DS18B20
 ' tested on CMM2 and micromite
 ' TassyJim August2020
 ' search based on code by jman and maximite source code
 '
 OPTION EXPLICIT
 DIM NextRomCode$
 DIM INTEGER t,b, pinN = 42
 DIM FLOAT tp

 PRINT
 PRINT TEMPR(pinN)
 PRINT ow_Tempr(pinN)
 PRINT
 DO
   NextRomCode$ = ow_search(PinN)
   IF NextRomCode$<>"" THEN
     FOR b = 9 TO 12
       t = TIMER
       tp = ow_Tempr(PinN,b,NextRomCode$)
       PRINT NextRomCode$;"  ";INT(TIMER-t-30);" ";tp
     NEXT b
   ENDIF
   PRINT
 LOOP UNTIL NextRomCode$ = ""
 
 ' ow_search() given pin number, returns all onewire devices found one at a time,
 ' as a string. After the last device, the next call will return an empty string.
 ' If there are no devices found "None found" is returned.
 ' Anything other than zero for the second parameter will cause the counter to reset,
 ' retrieving the first device
FUNCTION ow_search(PinNbr AS INTEGER,f%) AS STRING
 LOCAL INTEGER i, RomNum, rom_byte_mask, id_bit, cmp_id_bit, Last_zero
 LOCAL INTEGER search_direction, id_bit_number
 LOCAL RomCode$
 STATIC INTEGER LastDeviceFlag, LastDiscrepancy, last_RomNum
 
 IF f% <> 0 THEN ' reset for a new search
   last_RomNum = 0
   LastDeviceFlag = 0
   LastDiscrepancy = 0
   'LastFamilyDiscrepancy = 0
 ENDIF
 
 ONEWIRE RESET PinNbr
 
 IF LastDeviceFlag = 1 THEN
   RomCode$ = ""
   last_RomNum = 0
   LastDeviceFlag = 0
   LastDiscrepancy = 0
   'LastFamilyDiscrepancy = 0
 ELSE
   RomNum = 0
   id_bit_number = 1
   rom_byte_mask = 1
   last_zero = 0
   
   ONEWIRE WRITE PinNbr,1,1,&HF0 'Send the Search ROM command (FO)
   DO
     ONEWIRE READ PinNbr, 4 , 2, id_bit, cmp_id_bit 'Get response from device
     IF (id_bit = 1 AND cmp_id_bit = 1) THEN ' shouldn't happen
       LastDeviceFlag = -1
       EXIT DO
     ENDIF
     IF id_bit <> cmp_id_bit THEN search_direction = id_bit ' no conflict
     IF ((id_bit = 0) AND (cmp_id_bit = 0)) THEN ' conflict
       IF id_bit_number = LastDiscrepancy THEN
         'id_bit_number = LastDiscrepancy then take "1" path
         search_direction = 1
       ELSEIF id_bit_number > LastDiscrepancy THEN
         'id_bit_number > LastDiscrepancy then take the "0" path
         search_direction = 0
       ELSE
         ' id_bit_number < LastDiscrepancy then take same path as last time
         IF (last_RomNum AND rom_byte_mask) > 0 THEN
           search_direction = 1
         ELSE
           search_direction = 0
         ENDIF
       ENDIF
       IF search_direction = 0 THEN
         Last_zero = id_bit_number
         'If last_zero < 9 Then LastFamilyDiscrepancy = last_zero
       ENDIF
     ENDIF
     
     ' add bit to rom code or leave at zero if search_direction = 0
     IF search_direction = 1 THEN RomNum = RomNum OR rom_byte_mask
     
     ONEWIRE WRITE PinNbr,4,1,search_direction ' send 1 or 0 as search direction
     id_bit_number = id_bit_number+1 ' increment id_bit_number
     rom_byte_mask = rom_byte_mask << 1
     
   LOOP UNTIL id_bit_number > 64 'Check for next bit
   
   IF LastDeviceFlag = -1 THEN
     LastDeviceFlag = 1
     RomCode$ = "None found"
   ELSE
     LastDiscrepancy = last_zero
     IF LastDiscrepancy = 0 THEN LastDeviceFlag = 1
     last_RomNum = RomNum
     
     RomCode$ = ""
     FOR i = 1 TO 8
       RomCode$ = RomCode$ + HEX$((RomNum AND &hFF),2)
       RomNum = RomNum>>8
     NEXT i
   ENDIF
 ENDIF
 ow_search = RomCode$
END FUNCTION
 
 ' bit (9-12) is optional and defaults to 10
 ' probe$ is optional if only one probe attached
 ' probe$ format = "2862D8F105000018"
 ' time taken is ~30mS plus conversion time
FUNCTION ow_Tempr(PinNbr AS INTEGER, bit AS INTEGER, probe$) AS FLOAT
 LOCAL FLOAT T1
 LOCAL INTEGER t, n, power, romcode, Tconv
 LOCAL INTEGER c1,c2,c3,c4,c5,c6,c7,c8
 LOCAL INTEGER d1,d2,d3,d4,d5,d6,d7,d8
 
 IF bit = 0 THEN
   bit = 10
 ELSEIF bit < 9 THEN
   bit = 9
 ELSEIF bit > 12 THEN
   bit = 12
 ENDIF
 
 Tconv=750
 ONEWIRE RESET PinNbr
 IF MM.ONEWIRE = 0 THEN                 ' no device
   T1 = 1000
 ELSE
   
   ONEWIRE WRITE PinNbr, 1,2,&hcc, &hb4
   ONEWIRE READ PinNbr,4,1,power
   
   IF probe$ = "" THEN ' romcode not specified so go get it.
     ONEWIRE WRITE PinNbr,1,1,&h33 'read ROM code
     ONEWIRE READ PinNbr,0,8,c1,c2,c3,c4,c5,c6,c7,c8
   ELSE
     romcode = VAL("&h"+probe$)
     c8 = romcode AND &hFF
     romcode = romcode >> 8
     c7 = romcode AND &hFF
     romcode = romcode >> 8
     c6 = romcode AND &hFF
     romcode = romcode >> 8
     c5 = romcode AND &hFF
     romcode = romcode >> 8
     c4 = romcode AND &hFF
     romcode = romcode >> 8
     c3 = romcode AND &hFF
     romcode = romcode >> 8
     c2 = romcode AND &hFF
     romcode = romcode >> 8
     c1 = romcode AND &hFF
   ENDIF
   IF c1=34 OR c1=40 THEN
     n = ((bit-9)<< 5) + 31           ' set resolution config byte
     ONEWIRE WRITE PinNbr,1,9,&h55,c1,c2,c3,c4,c5,c6,c7,c8
     ONEWIRE WRITE PinNbr,0,4, &h4e , &hFF,&hFF,n
   ENDIF
   ONEWIRE WRITE PinNbr,1,9,&h55,c1,c2,c3,c4,c5,c6,c7,c8
   IF power = 0 THEN
     ONEWIRE WRITE PinNbr,8,1, &h44   'apply strong pullup for passive
   ELSE
     ONEWIRE WRITE PinNbr,0,1, &h44
   ENDIF
   'read external when bit goes hi, for parasitic just wait
   IF power = 0 THEN
     PAUSE Tconv
   ELSE
     t = TIMER
     DO
       IF TIMER - t > 1000 THEN
         T1 = 1001
         EXIT DO
       ENDIF
       ONEWIRE READ PinNbr, 4, 1, n   ' conversion done?
     LOOP UNTIL n = 1
     'print int(timer - t);" ";
   ENDIF
 ENDIF
 
 IF T1 < 1000 THEN
   'read scratchpad
   ONEWIRE WRITE PinNbr,1,9,&h55,c1,c2,c3,c4,c5,c6,c7,c8
   ONEWIRE WRITE PinNbr,0,1,&hbe     ' command read data
   ONEWIRE READ PinNbr,2,8,d1,d2,d3,d4,d5,d6,d7,d8
   
   IF c1=34 OR c1=40 THEN            ' DS18S22 or DS18B20
     t= d1+(d2<<8)
     t = t AND (&hFFFF <<(12-bit))
     IF t > 32767 THEN t = t - 65536
     T1 = t/16
   ELSEIF c1=16 THEN                 ' DS18S20 or DS1820
     t= d1+(d2<<8)
     IF t > 32767 THEN t = t - 65536
     ' T1 = t/2 ' 9 bit
     T1 = (t>>1) - 0.25 + (d8-d7)/d8 ' using extended precision data
   ELSE
     T1 = 1002
   ENDIF
 ENDIF
 ow_Tempr = T1
END FUNCTION


Jim
VK7JH
MMedit
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 07:09am 14 Aug 2020
Copy link to clipboard 
Print this post

Fantastic - good work Jim  
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5089
Posted: 07:30am 14 Aug 2020
Copy link to clipboard 
Print this post

I was always curious how this would work, the enumeration of multiple devices in onewire. Good to see it in action...

Nice work TassyJim!
PicomiteVGA PETSCII ROBOTS
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1097
Posted: 07:15am 29 Aug 2020
Copy link to clipboard 
Print this post

Hi Jim

Decided it was time I checked this out.

I connected 4 x DS18B20's to a 28 pinner, pin 2 running 5.0408

It didn't like the STATIC INTEGER in the first function so I made it a global INTEGER. I don't know how this affects things.

It worked but all the times are coming out the same as per below.

I'm using a 2k7 resistor

RUN
[17:08:50]
[17:08:51] 22.5
[17:08:51]-0.25
[17:08:51]
[17:08:52]28900381070000CD   760  23
[17:08:53]28900381070000CD   761  22.75
[17:08:54]28900381070000CD   760  22.75
[17:08:55]28900381070000CD   760  22.75
[17:08:55]
[17:08:56]28EE348107000093   760  22.5
[17:08:56]28EE348107000093   760  22.5
[17:08:57]28EE348107000093   760  22.625
[17:08:58]28EE348107000093   761  22.625
[17:08:58]
[17:08:59]28EEF78007000070   761  22.5
[17:09:00]28EEF78007000070   760  22.75
[17:09:00]28EEF78007000070   760  22.75
[17:09:01]28EEF78007000070   760  22.6875
[17:09:01]
[17:09:02]28750281070000C2   760  22.5
[17:09:03]28750281070000C2   760  22.75
[17:09:04]28750281070000C2   760  22.75
[17:09:05]28750281070000C2   760  22.625
[17:09:05]
[17:09:05]
[17:09:05]>


Now to sit down & work out what exactly how the program works.

Brian
ChopperP
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 07:37am 29 Aug 2020
Copy link to clipboard 
Print this post

STATIC or GLOBAL shouldn't make any difference.

All the same time indicates that you are using parasitic power.
When you are on parasitic power and multiple devices, it is safest to wait for the maximum time.

Other wise, you would have to work out which devices run at what speed and then you might be able to shorten the time.
Slow and steady wins the race.

Or use 3 wires.

Jim
VK7JH
MMedit
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1097
Posted: 07:43am 29 Aug 2020
Copy link to clipboard 
Print this post

I'm using 3 wires as per the manual. Separate power, signal & return wires.

I assume all devices are in parallel with the one resistor.

Brian
ChopperP
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 07:53am 29 Aug 2020
Copy link to clipboard 
Print this post

In that case, either:
my code thinks that one or more of your sensors is in passive mode.
or
your sensors can't change resolution.

You could try one at a time and compare the time with the builtin function for various bit resolution.

Jim
VK7JH
MMedit
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1097
Posted: 08:00am 29 Aug 2020
Copy link to clipboard 
Print this post

OK, will have a play.

Thanks Jim

Brian
ChopperP
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1097
Posted: 08:46am 29 Aug 2020
Copy link to clipboard 
Print this post

Jim

Checked the 4 sensors individually for the 4 modes from the MMEdit Chat command line.

They seem to be working OK with my setup. (Must be your program )

[18:33:51]tempr start 2,0: timer = 0: ? tempr(2): ? timer
[18:33:51] 22
[18:33:51] 104
[18:33:54]> tempr start 2,1: timer = 0: ? tempr(2): ? timer
[18:33:58] 22.5
[18:33:58] 204
[18:34:00]> tempr start 2,2: timer = 0: ? tempr(2): ? timer
[18:34:05] 22.375
[18:34:05] 404
[18:34:07]> tempr start 2,3: timer = 0: ? tempr(2): ? timer
[18:34:12] 22.375
[18:34:12] 804

[18:34:12]> tempr start 2,0: timer = 0: ? tempr(2): ? timer
[18:36:19] 24
[18:36:19] 104>
[18:36:22]> tempr start 2,1: timer = 0: ? tempr(2): ? timer
[18:36:27] 23.75
[18:36:27] 204
[18:36:29]> tempr start 2,2: timer = 0: ? tempr(2): ? timer
[18:36:35] 23.5
[18:36:35] 404
[18:36:38]> tempr start 2,3: timer = 0: ? tempr(2): ? timer
[18:36:44] 23.25
[18:36:44] 804

[18:36:44]> tempr start 2,0: timer = 0: ? tempr(2): ? timer
[18:37:27] 24.5
[18:37:27] 104
[18:37:27]> tempr start 2,1: timer = 0: ? tempr(2): ? timer
[18:37:34] 24.25
[18:37:34] 204
[18:37:34]> tempr start 2,2: timer = 0: ? tempr(2): ? timer
[18:37:42] 23.75
[18:37:42] 404
[18:37:42]> tempr start 2,3: timer = 0: ? tempr(2): ? timer
[18:37:47] 23.4375
[18:37:47] 804

[18:37:47]> tempr start 2,0: timer = 0: ? tempr(2): ? timer
[18:38:12] 25.5
[18:38:12] 104
[18:38:12]> tempr start 2,1: timer = 0: ? tempr(2): ? timer
[18:38:17] 25
[18:38:17] 204
[18:38:17]> tempr start 2,2: timer = 0: ? tempr(2): ? timer
[18:38:21] 24.625
[18:38:21] 404
[18:38:21]> tempr start 2,3: timer = 0: ? tempr(2): ? timer
[18:38:25] 24.375
[18:38:25] 804


Interesting exercise.

Brian
ChopperP
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 11:25am 29 Aug 2020
Copy link to clipboard 
Print this post

And what happens with one sensor with my program?
VK7JH
MMedit
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1097
Posted: 12:07pm 29 Aug 2020
Copy link to clipboard 
Print this post

One sensor with your prog.

[22:05:13]RUN
[22:05:13]
[22:05:13] 22.75
[22:05:14] 22.75
[22:05:14]
[22:05:14]28900381070000CD   761  23
[22:05:15]28900381070000CD   761  22.75
[22:05:16]28900381070000CD   760  22.75
[22:05:17]28900381070000CD   760  22.75
[22:05:17]
[22:05:17]
[22:05:17]>


BTW, I updated the firmware & reinstated STATIC. Made no difference to the readings as can be seen.

Brian
ChopperP
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1097
Posted: 12:07pm 29 Aug 2020
Copy link to clipboard 
Print this post

One sensor with your prog.

[22:05:13]RUN
[22:05:13]
[22:05:13] 22.75
[22:05:14] 22.75
[22:05:14]
[22:05:14]28900381070000CD   761  23
[22:05:15]28900381070000CD   761  22.75
[22:05:16]28900381070000CD   760  22.75
[22:05:17]28900381070000CD   760  22.75
[22:05:17]
[22:05:17]
[22:05:17]>


BTW, I updated the firmware & reinstated STATIC. Made no difference to the readings as can be seen.

Brian
ChopperP
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1097
Posted: 12:07pm 29 Aug 2020
Copy link to clipboard 
Print this post

One sensor with your prog.

[22:05:13]RUN
[22:05:13]
[22:05:13] 22.75
[22:05:14] 22.75
[22:05:14]
[22:05:14]28900381070000CD   761  23
[22:05:15]28900381070000CD   761  22.75
[22:05:16]28900381070000CD   760  22.75
[22:05:17]28900381070000CD   760  22.75
[22:05:17]
[22:05:17]
[22:05:17]>


BTW, I updated the firmware & reinstated STATIC. Made no difference to the readings as can be seen.

Brian
ChopperP
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1097
Posted: 12:07pm 29 Aug 2020
Copy link to clipboard 
Print this post

One sensor with your prog.

[22:05:13]RUN
[22:05:13]
[22:05:13] 22.75
[22:05:14] 22.75
[22:05:14]
[22:05:14]28900381070000CD   761  23
[22:05:15]28900381070000CD   761  22.75
[22:05:16]28900381070000CD   760  22.75
[22:05:17]28900381070000CD   760  22.75
[22:05:17]
[22:05:17]
[22:05:17]>


BTW, I updated the firmware & reinstated STATIC. Made no difference to the readings as can be seen.

Brian
ChopperP
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1097
Posted: 12:08pm 29 Aug 2020
Copy link to clipboard 
Print this post

OK, 4 posts ????
ChopperP
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 12:24pm 29 Aug 2020
Copy link to clipboard 
Print this post

Unfortunately using the following to measure the conversion time is meaningless:
  tempr start 2,0: timer = 0: ? tempr(2): ? timer

This is because MMBasic waits for a fixed time (as specified in the DS18B20 data sheet) for the conversion.  It does not query the sensor to figure out if it has completed early.  This applies if TEMPR START was or was not used.

The TEMPR() function was intended for casual users who just wanted to get a temperature.  For more sophisticated applications you can use the ONEWIRE commands as TassyJim has done and they allow you to explore all the complexities of the DS18B20.

Edit: It has just occurred to me that if a clone DS18B20 takes longer than the datasheet time MMBasic will not be able to read its result (because it is still converting when MMBasic checks). Hmmm...

Geoff
Edited 2020-08-29 22:37 by Geoffg
Geoff Graham - http://geoffg.net
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1097
Posted: 12:45pm 29 Aug 2020
Copy link to clipboard 
Print this post

Hi Geoff

Wouldn't it still give an indication that the conversions were  done within the specified time according to TEMPR START or am I not understanding this correctly?

Brian
ChopperP
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 02:19pm 29 Aug 2020
Copy link to clipboard 
Print this post

I am not quite sure what you are asking but, to be clear, this is what happens:

When you use the function TEMPR() it:
- Triggers the conversion.
- Starts a timer and waits for it to finish.
- Then queries the DS18B20 and returns its reading.

When you use the command TEMPR START it:
- Triggers the conversion.
- Starts a timer who's value depends on the specified accuracy.
When you later use the function TEMPR() it:
- Checks the timer and if not finished it will wait for it to finish.
- Then queries the DS18B20 and returns its reading.

The DS18B20 can be repeatedly queried to check if it has finished but I had issues with getting that to work reliably so I opted for a simple timer.  

Remember, you can always use the ONEWIRE commands to do the more complicated stuff like this. For example (this is untested):

' use a defined function to get the temperature
' The sensor is connected to the pin 18
Print "The temperature is:" GetTemp(18)


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Function to get the temperature from a Dallas DS18B20.
' The DS18B20 is connected to the pin specified by PinNbr
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function GetTemp (PinNbr)
 Local T1, T2, b, t
 OneWire Reset PinNbr                        ' reset
 OneWire Write PinNbr, 1, 2, &hcc, &h44      ' start conversion
 Pause 100
 t = Timer
 Do
   If Timer - t > 1000 Then Error "Sensor not responding"
   OneWire Read PinNbr, 4 , 1 , b            ' conversion done?
 Loop Until b = 1
 OneWire Write PinNbr, 1, 2, &hcc, &hbe      ' command read data
 OneWire Read PinNbr, 2, 2, T1, T2           ' get the data
 GetTemp = ((T2 And &b111) * 256 + T1) / 16
 If T2 And &b1000 Then GetTemp = -GetTemp    ' adjust if negative
End Function


It might be worth revisiting this to see if I can poll the DS18B20 reliably - I will add that to the todo list for the next version.  Another thing that I would like to do is to allow interrupts to be serviced while waiting.

Geoff
Edited 2020-08-30 00:38 by Geoffg
Geoff Graham - http://geoffg.net
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 09:38pm 29 Aug 2020
Copy link to clipboard 
Print this post

Try again.
(I copy and pasted something that had a text string that the forum didn't like)

Try changing your pullup resistor to 4.7k. WE might as well go with the datasheet recommendation.

AT about line 140 of my code, I check to see if we are on parasitic power.
Try adding a line
PRINT "Power= ";power

after

ONEWIRE WRITE PinNbr, 1,2,&hcc, &hb4
   ONEWIRE READ PinNbr,4,1,power



From the datasheet:
  Quote  The 1-Wire bus requires an external pullup resistor of approximately 5kohms; thus, the idle state for the 1-Wire bus is high.


In some situations the bus master may not know whether the DS18B20s on the bus are parasite powered or powered by external supplies. The master needs this information to determine if the strong bus pullup should be used during temperature conversions. To get this information, the master can issue a Skip ROM CCh command followed by a Read Power Supply B4h command followed by a 'read time slot'. During the read time slot, parasite powered DS18B20s will pull the bus low, and externally powered DS18B20s will let the bus remain high. If the bus is pulled low, the master knows that it must supply the strong pullup on the 1-Wire bus during temperature conversions.


Jim
VK7JH
MMedit
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1097
Posted: 10:46pm 29 Aug 2020
Copy link to clipboard 
Print this post

@TJ

Changed to a 4k7 & added PRINT "Power= ";power;


     ONEWIRE WRITE PinNbr, 1,2,&hcc, &hb4
     ONEWIRE READ PinNbr,4,1,power
     PRINT "Power = ";power "  ";


First printout is with PARASITIC (2 wire) power & the second Normal power. No difference

[08:38:22]RUN
[08:38:22]
[08:38:22] 18.5
[08:38:22]Power =  0  -0.25
[08:38:23]
[08:38:23]Power =  0  28900381070000CD   761  18.5
[08:38:24]Power =  0  28900381070000CD   762  18.5
[08:38:25]Power =  0  28900381070000CD   762  18.375
[08:38:26]Power =  0  28900381070000CD   761  18.4375
[08:38:27]
[08:38:27]Power =  0  28EE348107000093   761  18.5
[08:38:27]Power =  0  28EE348107000093   762  18.75
[08:38:28]Power =  0  28EE348107000093   761  18.75
[08:38:29]Power =  0  28EE348107000093   761  18.75
[08:38:30]
[08:38:30]Power =  0  28EEF78007000070   761  18.5
[08:38:31]Power =  0  28EEF78007000070   762  18.75
[08:38:32]Power =  0  28EEF78007000070   761  18.625
[08:38:32]Power =  0  28EEF78007000070   761  18.625
[08:38:33]
[08:38:33]Power =  0  28750281070000C2   762  18.5
[08:38:34]Power =  0  28750281070000C2   762  18.75
[08:38:35]Power =  0  28750281070000C2   761  18.625
[08:38:36]Power =  0  28750281070000C2   761  18.5625
[08:38:36]
[08:38:36]
[08:38:36]> RUN
[08:39:38]
[08:39:38] 18
[08:39:38]Power =  0  -0.25
[08:39:39]
[08:39:39]Power =  0  28900381070000CD   761  19
[08:39:40]Power =  0  28900381070000CD   761  19
[08:39:41]Power =  0  28900381070000CD   761  19
[08:39:41]Power =  0  28900381070000CD   761  18.9375
[08:39:42]
[08:39:42]Power =  0  28EE348107000093   761  18.5
[08:39:43]Power =  0  28EE348107000093   762  18.75
[08:39:44]Power =  0  28EE348107000093   761  18.75
[08:39:45]Power =  0  28EE348107000093   761  18.75
[08:39:46]
[08:39:46]Power =  0  28EEF78007000070   761  18.5
[08:39:46]Power =  0  28EEF78007000070   762  18.75
[08:39:47]Power =  0  28EEF78007000070   761  18.75
[08:39:48]Power =  0  28EEF78007000070   761  18.75
[08:39:49]
[08:39:49]Power =  0  28750281070000C2   762  18.5
[08:39:50]Power =  0  28750281070000C2   762  18.75
[08:39:51]Power =  0  28750281070000C2   761  18.75
[08:39:51]Power =  0  28750281070000C2   761  18.6875
[08:39:52]
[08:39:52]
[08:39:52]>


Brian
ChopperP
 
     Page 1 of 3    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025