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: GermanyPosts: 712 |
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 |
||||
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1664 |
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 StatesPosts: 761 |
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: GermanyPosts: 712 |
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 KingdomPosts: 8600 |
It is in the MZ code - no idea how to use it or if it works |
||||
Zonker Guru Joined: 18/08/2012 Location: United StatesPosts: 761 |
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: GermanyPosts: 712 |
What does it mean it's "in the code" ? THX |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8600 |
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: GermanyPosts: 712 |
Ok, waiting for Zonkers feed back ;-)... |
||||
atmega8 Guru Joined: 19/11/2013 Location: GermanyPosts: 712 |
Hi, did anyone try the search function? |
||||
Zonker Guru Joined: 18/08/2012 Location: United StatesPosts: 761 |
My MMX boards have not arrived yet... Should be soon..! |
||||
atmega8 Guru Joined: 19/11/2013 Location: GermanyPosts: 712 |
news from zonker ?? |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8600 |
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) The new function is included in MMX V5.3.15 |
||||
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1664 |
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) 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] |
||||
Print this page |