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.
helltek Newbie Joined: 04/02/2015 Location: United StatesPosts: 29
Posted: 06:21pm 13 Apr 2020
Copy link to clipboard
Print this post
Is there somewhere basic program for Micromite to search ONE WIRE bus? I tried to make sense of the Maxim flowchart but can't figure it out. I can read 1 or 2 devices but when I connect more, my search fails or runs in never-ending loop. https://pdfserv.maximintegrated.com/en/an/AN187.pdf 'Maxim 1-wire search algorithm
CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2171
Posted: 07:44pm 13 Apr 2020
Copy link to clipboard
Print this post
I have never used it directly (if you discount the DS18B20 temp sensor where I use TEMPR) but, One-wire support is part of MMBasic. Taking a look at Appendix C of the Micromite Manual;
It says "For users of MMBasic on earlier devices... The OWSEARCH command and the OWCRC8() and OWCRC16() functions are not implemented", so I suspect any querying of the bus would be successive progression of the READ and dealing with null-responses (MM.ONEWIRE) - don't know what qualifies as "earlier"(?) Edited 2020-04-14 05:53 by CaptainBoing
helltek Newbie Joined: 04/02/2015 Location: United StatesPosts: 29
Posted: 09:04pm 13 Apr 2020
Copy link to clipboard
Print this post
I tried to write basic program following the Maxim flowchart and my program doesn't work. Reads one device over and over. Someone good in basic programming would find my errors easily. I'm not able to figure it out.
--------------------------------
'Hardware '-------------------- 'PIC32MX170F256B-50I/SP 28 pin DIP 'Micro with MMBasic firmware V5.5.2 '1k pullup resistor to 5V on PIN owp '1-wire data bus pullup on 5V tolerant pin
maxdevices = 16 'maximum number of 1-wire devices Dim ROMcode%(maxdevices) 'ROMcode is the full 64-bit device number Dim Family(maxdevices) 'Family code is 1 byte Dim SerNo%(maxdevices) 'Serial number is 6 bytes Dim CRC(maxdevices) 'CRC is 1 byte
GOSUB one_wire_search
END 'End of one_wire_search prog '####################
'SUBROUTINES
one_wire_search:
devices = 0
discover_first_device:
'Maxim flowchart: cmp_id_bit = 0 'complement of id_bit id_bit = 0 'one bit of id_bit_number id_bit_number = 1 'ROM bit number 1 to 64 LastDeviceFlag = 0 'last device in search LastDiscrepancy = 0 'next search discrepancy check start LastFamilyDiscrepancy = 0 'last discrepancy in family code last_zero = 0 'last zero written in discrepancy ROM_NO = 0 '8-byte buffer search_direction = 0 'devices with this bit stay in search
count64bits: For id_bit_number = 1 To 64 OneWire READ owp, 4, 1, a 'read 1 bit of 1-wire devices OneWire READ owp, 4, 1, b 'read complement of 1 bit 'Print "search "i" rd_a " Bin$(a,1)" rd_b " BIN$(b,1);
search_direction=a If a + b = 2 Then GoTo one_wire_owERROR2 'bit and complement bit don't match If a + b = 0 And id_bit_number=lastdiscrepancy Then search_direction=1 If a + b = 0 And id_bit_number>lastdiscrepancy Then search_direction=0 If a + b = 0 And id_bit_number<lastdiscrepancy Then search_direction=a If search_direction=0 THEN last_zero=id_bit_number If last_zero<9 THEN LastFamilyDiscrepancy=last_zero a=search_direction
OneWire WRITE owp, 4, 1, a 'write bit to continue search
Print Bin$(a,1); '################
If id_bit_number>0 And id_bit_number<9 Then Family_nbr=Family_nbr+(a<<(id_bit_number-1)) If id_bit_number>8 And id_bit_number<57 Then SerNo_nbr%=SerNo_nbr%+(a<<(id_bit_number-9)) If id_bit_number>56 And id_bit_number<65 Then CRC_nbr=CRC_nbr+(a<<(id_bit_number-57)) ROMcode_nbr%=ROMcode_nbr%+(a<<(id_bit_number-1))
Next id_bit_number
devices = devices + 1
If devices <= maxdevices Then Family(devices)=Family_nbr If devices <= maxdevices Then SerNo%(devices)=SerNo_nbr% If devices <= maxdevices Then CRC(devices)=CRC_nbr If devices <= maxdevices Then ROMcode%(devices)=ROMcode_nbr%
'check crc c1%=0 'clear crc "c1" prior sending first byte b1%=Family(devices): n=1 'byte or bytes to calculate crc on and the number of bytes sent GoSub crc_8 b1%=SerNo%(devices): n=6 'byte or bytes to calculate crc on and the number of bytes sent GoSub crc_8 b1%=CRC(devices): n=1 'byte or bytes to calculate crc on and the number of bytes sent GoSub crc_8
If c1%<>0 Then id_bit_number=devices: GoSub one_wire_owERROR3: RETURN IF ROMcode%(1)=0 THEN devices=0: GOSUB one_wire_owERROR1: RETURN
Print Print "-------------------" Print
LastDiscrepancy=last_zero If LastDiscrepancy <> 0 Then GoTo discover_next_device 'search for more devices LastDeviceFlag=1
one_wire_search_end: owERROR=0 Return
one_wire_owERROR1: owERROR=1 Print: Print "owERROR1 MM.ONEWIRE = 0, Devices not found": Print if TLCD_MENU=4 then Text 3, 42, "Device Not Found", LT, 1, 1, &Hff3333, &H000000 'LCD TEXT devices = 0: dev1wire = 0 Return
one_wire_owERROR2: owERROR=2 Print: Print "owERROR2 True bit + Complement bit in search" id_bit_number " do not match": Print Return
one_wire_owERROR3: owERROR=3 Print: Print "owERROR3 CRC(device"(id_bit_number)") does not match": Print Return
'-------------------- 'CRC-8 '-------------------- 'Calculate CRC-8 for integer "b1%" of any size from 1 byte up to full 1-wire device number '"b1%" is the integer, '"n" = number of bytes 'Add the CRC-8 value into integer "c1%" after each byte '"c1%" is cleared to zero for the first byte sent '"d1%" is the data after each shift '"e1%" is the CRC-8 Polynomial
'Compare CRC LSB bit with DATA LSB bit 'If they are equal shift right CRC and DATA 'If they are not equal shift both CRC and DATA and XOR 'the Polynomial to ehe CRC after being shifted 'Use the final CRC for the next byte
'The Polynomial e1% x8+x5+x4+1 is 10001100b in binary form
If i<8 And (c1% And &b00000001)=(d1% And &b00000001) Then c1%=c1%>>1: d1%=d1%>>1: x=0 :i=i+1 If i<8 And (c1% And &b00000001)<>(d1% And &b00000001) Then c1%=c1%>>1: d1%=d1%>>1: c1%=(e1% Xor c1%): x=1: i=i+1
If i<8 Then GoTo crc_8_loop
Print "byte b1%="Hex$((b1% And &hFF),2)"h crc="Hex$(c1%,2)"h"
If n>1 Then b1%=(b1%>>8): n=n-1: GoTo crc_8 'break integer b1 into separate bytes
Return
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1667
Posted: 10:27pm 13 Apr 2020
Copy link to clipboard
Print this post
This is the code I played about with a few years back. Credits go to Jman...
I didn't have a lot of success as it seemed to only find up to 3 of the 6 DS18B20's on the bus.
I did find that removing them one at a time produced different result; as if certain number patterns caused it to drop out.
Spent a fair bit of time looking for answers, but in the end just went back to reading serial numbers one at a time.
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1667
Posted: 10:43pm 13 Apr 2020
Copy link to clipboard
Print this post
I've got a vague recollection that matherp revisited OWSearch at one point in the MMExtreme firmware.
On checking the function is mentioned on Page 29 of the 5.3.15 MM Extreme Manual I have here.
Have never got to try in on my MMX though.
helltek Newbie Joined: 04/02/2015 Location: United StatesPosts: 29
Posted: 12:41am 14 Apr 2020
Copy link to clipboard
Print this post
I really wonder if the Maxim Dallas 1-wire theory actually works. Someone would have program that works reliably. The Maxim App Note is inconsistent and has errors and typos. I feel like reading Chinese manual. If Maxim released updated App Note easy to follow and without errors, they could revive the 1-wire product line and sell lot of 1-wire devices to the IoT and SmartHome market.