Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 19:04 10 May 2024 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 : Several 1 Wire Devices on one BUS

Author Message
atmega8

Guru

Joined: 19/11/2013
Location: Germany
Posts: 712
Posted: 06:37am 03 Mar 2017
Copy link to clipboard 
Print this post

Hello,

i have several one wire devices on one bus.
One DS 18B20 and one DS 2438 on one printed circuit.
It is part of a home automation.

I will connect up to 10 of this printed circuits on the same bus.

Has anyone a stable working code/sample for reading and printing the values of the DS18B20 and the thre values of the DS2438 internal temperature and the two analog AD Inputs ?

Thank you very much for your support!


Atmega8 Edited by atmega8 2017-03-04
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1664
Posted: 01:33pm 03 Mar 2017
Copy link to clipboard 
Print this post

I've got 2 different MM's with around 6? DS18B20's on the same bus.
It should be possible to modify the code to read the DS2438's as well.

There's a stack of post, but this one has most of the complete code.

Cheers

Phil.
 
Zonker

Guru

Joined: 18/08/2012
Location: United States
Posts: 761
Posted: 04:36pm 03 Mar 2017
Copy link to clipboard 
Print this post

With extra room in the MZ cores, is it possible to "add" the search function, (maybe as something you can store in the library) back in..? I'm not to sure if anyone wants it, but, could you then just plug the next device onto the bus and have it connect up "automagically" ..?
 
atmega8

Guru

Joined: 19/11/2013
Location: Germany
Posts: 712
Posted: 12:05pm 04 Mar 2017
Copy link to clipboard 
Print this post

I remember there was a discussion with Geoff, these functions did not fit anymore in the MX...
I think Geoff had the code already.
Now with the new MZ, no problem of space.

Since 1Wire in home automation and bus systems with dozen of different 1Wire devices it would open the home automation world also for Mmbasic.

Really a god argument for putting this back in the MM+ code.

What do you think?

Atmega8
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8600
Posted: 12:33pm 04 Mar 2017
Copy link to clipboard 
Print this post

  Quote  With extra room in the MZ cores, is it possible to "add" the search function


It is in the MZ code - no idea how to use it or if it works


 
Zonker

Guru

Joined: 18/08/2012
Location: United States
Posts: 761
Posted: 03:02am 05 Mar 2017
Copy link to clipboard 
Print this post

Sweet Peter..!! I had no idea..!

When the MMX board get here, I will give this a try..

Thanks..!
 
atmega8

Guru

Joined: 19/11/2013
Location: Germany
Posts: 712
Posted: 05:37am 05 Mar 2017
Copy link to clipboard 
Print this post

What does it mean it's "in the code" ?

THX
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8600
Posted: 06:04am 05 Mar 2017
Copy link to clipboard 
Print this post

  Quote  What does it mean it's "in the code" ?


It means I've enabled the conditional compilation and the firmware responds to "onewire search" I assume the syntax is as per the colour maximite which is clunky as that version doesn't have 64-bit integers
 
atmega8

Guru

Joined: 19/11/2013
Location: Germany
Posts: 712
Posted: 11:16am 06 Mar 2017
Copy link to clipboard 
Print this post

Ok, waiting for Zonkers feed back ;-)...
 
atmega8

Guru

Joined: 19/11/2013
Location: Germany
Posts: 712
Posted: 10:59am 08 Mar 2017
Copy link to clipboard 
Print this post

Hi,

did anyone try the search function?
 
Zonker

Guru

Joined: 18/08/2012
Location: United States
Posts: 761
Posted: 12:55am 09 Mar 2017
Copy link to clipboard 
Print this post

My MMX boards have not arrived yet... Should be soon..!
 
atmega8

Guru

Joined: 19/11/2013
Location: Germany
Posts: 712
Posted: 08:06am 16 Mar 2017
Copy link to clipboard 
Print this post

news from zonker ??
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8600
Posted: 04:06am 19 Mar 2017
Copy link to clipboard 
Print this post

I've re-engineered and tested the onewire search facility for the MMX. Originally ONEWIRE SEARCH was a command and it returned the ID as 8 floating point variables. This was because of the limitation in the Maximite of all variables being 32-bit floating point numbers. In the Micromite we now have 64-bit integers - perfect for onewire IDs so search can now be a FUNCTION and, I hope it is agreed it much more logical.

The syntax is

id% = owsearch(pin, flag [,serial_number_mask)

Flags are:
0 - Continue an existing search
1 - start a new search
4 - Continue an existing search for devices in the requested family
5 - start a new search for devices in the requested family (the MSB of the serial_number_mask)
8 - skip the current device family and return the next device
16 - verify that the device with the serial number in serial_number_mask is available


The system variable MM.ONEWIRE is maintainted as expected (1=success, 0=failure/no result)

  Quote  Micromite eXtreme MMBasic Ver 5.03.15 @ 200MHz
Copyright 2011-2017 Geoff Graham
Copyright 2016-2017 Peter Mather

> ? hex$(owsearch(113,1))'start a new search
2861F7F504000073
>
> ? hex$(owsearch(113,0))'Continue the search
285D70BF030000F8
>
> ? hex$(owsearch(113,0))'Continue the search
0
>
> ? hex$(owsearch(113,16,&H285D70BF030000F8))'Check for a specific device
2861F7F504000073
>
> ? hex$(owsearch(113,16,&H285D70BF030000F7))'Check for a specific device
0
>
> ? hex$(owsearch(113,5,&H2900000000000000))'Search for a particular family
0
>
> ? hex$(owsearch(113,5,&H2800000000000000))'Search for a particular family
2861F7F504000073
>
> ? hex$(owsearch(113,4,&H2800000000000000))'Continue the search for a particular family
285D70BF030000F8
>
> ? hex$(owsearch(113,1))'start a new search
2861F7F504000073
>
> ? hex$(owsearch(113,8))'Skip to the next family
0
>



The new function is included in MMX V5.3.15 Edited by matherp 2017-03-20
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1664
Posted: 10:04am 19 Mar 2017
Copy link to clipboard 
Print this post

With regards to 1-Wire search on other MM's.

JMan wrote this a while back & initially it seemed to work.

But on further investigation I found it only found some of the devices on the bus, not all of them.

As if it was terminating early.

Seemed Ok with 3 particular DS18B20 but if I added more to the initial 3 things responded unpredictably.

Wondering if you might spot the issue while the search logic is fresh in you mind.

Thanks

Phil.

Edit:-

It would really great @pmather is you could export you MMX function as an external function for the other MM's.

But I don't know how demanding a task that is.

[Code]'1-Wire Serial Number Search - Multiple Devices Attached.
'Code by Jman 04 April 2016
Option Explicit
Dim A%, PinNbr
Dim id_bit, cmp_id_bit, LastDeviceFlag, Last_zero
Dim search_direction, id_bit_number, LastDiscrepancy
Dim DeviceCount, ROM_NO(8)
Dim LastFamilyDiscrepancy, I, J
PinNbr = 16

'===================================================================
Device_loop: 'Device loop: loop for all devices on the bus
OneWire Reset Pinnbr

If LastDeviceFlag = 1 Then Print "--Done--": End
id_bit_number = 1
last_zero = 0

OneWire Write PinNbr,1,1,&HF0 'Send the Search ROM command (FO)

'===================================================================
Check_bit:
OneWire Read PinNbr, 4 , 2, id_bit, cmp_id_bit 'Get response from device

If (id_bit = 1 And cmp_id_bit = 1) Then GoTo No_device
If Not ((id_bit = 0) And (cmp_id_bit = 0)) Then
search_direction = id_bit
I=Fix(((id_bit_number)-1)/8)
Rom_NO(I) = Rom_NO(I) << 1
ROM_NO(I) = Rom_no(I)+search_direction
EndIf

If ((id_bit = 0) And (cmp_id_bit = 0)) Then GoSub conflict

OneWire Write PinNbr,4,1,search_direction ' send 1 or 0 as search direction
id_bit_number = id_bit_number+1 ' incredement id_bit_number

If id_bit_number <= 64 Then GoTo Check_bit 'Check for next bit
If id_bit_number > 64 Then LastDiscrepancy = last_zero
If LastDiscrepancy = 0 Then LastDeviceFlag = 1

For i= 0 To 7
A%=Rom_no(I)
Rom_No(I) = ((A% * &h202020202) And &h10884422010) Mod 1023 'Thanks Rob
Next I

Print "Family ";Hex$(ROM_NO(0),2);"H"
Print "ID:", Hex$(ROM_NO(1),2),Hex$(ROM_NO(2),2),Hex$(ROM_NO(3),2),Hex$(ROM_NO(4),2),Hex$(ROM_NO(5),2),Hex$(ROM_NO(6),2)
Print "CRC:", Hex$(ROM_NO(7),2)
Print
deviceCount = deviceCount + 1

For J=0 To 7
Rom_no(J)=0
Next J

If LastDeviceFlag = 0 Then GoTo Device_loop
Print "DeviceCount";deviceCount, " device(s)."
Print "--Done--":End

'===================================================================
NO_device: 'Since both response bits are 11, there are no devices
Print " No devices present"
End

'===================================================================
Conflict: 'id_bit_number = LastDiscrepancy then take "1" path
If (id_bit_number) = LastDiscrepancy Then
search_direction = 1
I=Fix(((id_bit_number)-1)/8)
Rom_NO(I) = Rom_NO(I) << 1
Rom_NO(I) = Rom_NO(I)+search_direction
EndIf

'id_bit_number > LastDiscrepancy then take the "0" path
If (id_bit_number > LastDiscrepancy) Then
search_direction = 0
I=Fix(((id_bit_number)-1)/8)
Rom_NO(I) = Rom_NO(I) << 1
ROM_NO(I) = ROM_NO(I)+search_direction
Rom_NO(I) = Rom_NO(I)+search_direction
GoSub Family
EndIf

' id_bit_number < LastDiscrepancy then take same path as last time
If (id_bit_number < LastDiscrepancy) Then
I=Fix(((id_bit_number)-1)/8)
search_direction = ROM_NO(I)
If search_direction = 0 Then GoSub Family
EndIf

Return
'===================================================================
Family: 'LastFamilyDiscrepancy bit index set
Last_zero = id_bit_number
If last_zero <9 Then
LastFamilyDiscrepancy = last_zero
EndIf

Return
'===================================================================
[/code]Edited by Phil23 2017-03-20
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024