




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
中文4033字1-Wire搜索算法DallasSemiconductor的每片1-Wire?器件都有唯一的64位注冊碼它存儲在只讀存儲器(ROM)中。在1-Wire網(wǎng)絡(luò)中注冊碼用于1-Wire主機(jī)對從機(jī)器件進(jìn)行逐一尋址。如果1-Wire網(wǎng)絡(luò)中從機(jī)器件的ROM碼是未知的,可以通過搜索算法來找到此碼。本文不僅詳細(xì)地解釋了搜索算法,而且還提供了實(shí)現(xiàn)快速整合的例程該算法適用于任何具有1-Wire接口特性的現(xiàn)有產(chǎn)品及未來產(chǎn)品。表164位唯一的ROM注冊碼MSB64位ROM注冊碼LSB8位CRC校驗(yàn)碼MSBLSB48位序列號MSBLSB8位家族碼MSBLSB搜索算法搜索算法采用的是二叉樹型結(jié)構(gòu),搜索過程沿各分節(jié)點(diǎn)進(jìn)行,直到找到器件的ROM碼即葉子為止;后續(xù)的搜索操作沿著節(jié)點(diǎn)上的其它路徑進(jìn)行,按照同樣的方式直到找到總線上的所有器件代碼。搜索算法首先通過復(fù)位(Reset)和在線應(yīng)答脈沖(PresencePulse)時隙將1-Wire總線上的所有器件復(fù)位;成功地執(zhí)行該操作后,發(fā)送1個字節(jié)的搜索命令;搜索命令使1-Wire器件準(zhǔn)備、就緒開始進(jìn)行搜索操作。搜索命令分為兩類標(biāo)準(zhǔn)搜索命令(0F0H)用來搜索連接到網(wǎng)絡(luò)中所有器件;報警或有條件搜索命令(0ECH)只用來搜索那些處于報警狀態(tài)下的器件,這種方式縮小了搜索范圍,可以快速查找到所需要注意的器件。搜索命令發(fā)出之后,開始實(shí)際的搜索過程。首先總線上的所有從機(jī)器件同時發(fā)送ROM碼(也叫注冊碼)中的第一位(最低有效位)(參見圖1)。與所有的1-Wire通信一樣無論是讀取數(shù)據(jù)還是向從機(jī)器件寫數(shù)據(jù),都由1-Wire主機(jī)啟動每一位操作。按照1-Wire的特性,當(dāng)所有從機(jī)器件同時應(yīng)答主機(jī)時,結(jié)果相當(dāng)于全部發(fā)送數(shù)據(jù)位的邏輯AND;從機(jī)發(fā)送其ROM碼的第一位后,主機(jī)啟動下一位操作、接著從機(jī)發(fā)送第一位數(shù)據(jù)的補(bǔ)碼;從兩次讀到的數(shù)據(jù)位可以對ROM碼的第一位做出幾種判斷(參見表2)。按照搜索算法的要求,1-Wire主機(jī)必須向總線上的從機(jī)發(fā)回一個指定位;如果從機(jī)器件中ROM碼的當(dāng)前位的值與該數(shù)據(jù)位匹配,則繼續(xù)參與搜索過程;若從機(jī)器件的當(dāng)前位與之不匹配,則該器件轉(zhuǎn)換到等待狀態(tài),并保持等待狀態(tài)直到下一個1-Wire復(fù)位信號到來。其余63位ROM碼的搜索依然按照這種'讀兩位’、'寫一位’的模式進(jìn)行重復(fù)操作(參見表3)。表2檢索信息位
位(實(shí)際值)位(補(bǔ)碼)結(jié)論00從機(jī)ROM碼中的當(dāng)前位既有0,也有1;即存在差異01從機(jī)ROM碼中的當(dāng)前位均為0。10從機(jī)ROM碼中的當(dāng)前位均為1。11總線上沒有從機(jī)器件響應(yīng)。按照這種搜索算法進(jìn)行下去,最終除了一個從機(jī)器件外所有從機(jī)將進(jìn)入等待狀態(tài),經(jīng)過最后一輪檢測,就可得到最后保留(未進(jìn)入等待狀態(tài))器件的ROM碼。在后續(xù)搜索過程中,選用不同的路徑(或分支)來查找其它器件的ROM碼。需要注意的是本文ROM碼的數(shù)據(jù)位用第1位(最低有效位)到第64位(最高有效位)表示,而不是我們常用的那種第0位到第63位的模式;這樣設(shè)置允許將差異位置記數(shù)器初始值置為0,為以后的比較提供了方便。表31-Wire主機(jī)和從機(jī)的搜索過程主機(jī)從機(jī)1-Wire發(fā)出復(fù)位信號產(chǎn)生在線應(yīng)答脈沖。寫搜索命令(標(biāo)準(zhǔn)或報警)從機(jī)準(zhǔn)備搜索。讀第1位的AND從機(jī)發(fā)送ROM碼的第1位。讀第1位補(bǔ)碼的AND從機(jī)發(fā)送ROM碼的第1位的補(bǔ)碼。寫第1位指定位(依照算法)從機(jī)接收主機(jī)的指定位若所讀的位與ROM碼的第1位不匹配,則進(jìn)入等待狀態(tài)。讀第64位的AND從機(jī)發(fā)送ROM碼的第64位。讀第64位補(bǔ)碼的AND從機(jī)發(fā)送ROM碼的第64位的補(bǔ)碼。寫第64位指定位(依照算法)從機(jī)接收主機(jī)的指定位若所讀的位與ROM碼的第64位不匹配,則進(jìn)入等待狀態(tài)。從表4可以看出:如果所有總線上的器件在當(dāng)前位具有相同值,那么只有一條分支路徑可選;總線上沒有器件響應(yīng)的情況是一種異常狀態(tài),可能是要查找的器件在搜尋過程中與1-Wire總線脫離。如果當(dāng)前位既有0也有1,這種情況稱為位值差異,它對在后續(xù)搜索過程中查找器件起關(guān)鍵作用。搜索算法指定在第一輪查詢中若出現(xiàn)差異(數(shù)據(jù)位/補(bǔ)碼=0/0),則選用‘0’路徑。注意:這一點(diǎn)是由本文檔中介紹的特定算法決定的,其它算法中或許首先選用‘1’路徑。記錄最后一次值差異的位置以供下一次搜索使用,表3列出了出現(xiàn)值差異時路徑的選取情況。表4搜索路徑方向搜索位所在位置和最后一次值差異所在位置的比較路徑選取=采用路徑1<采用與上次相同的路徑來自上次搜索到的ROM碼)>采用路徑0搜索算法計(jì)算還對最初8位過程中出現(xiàn)的最后一次位差異保持跟蹤;64位注冊碼的前8位是家族碼,在器件的搜索過程中可以按照其家族碼進(jìn)行分類。記錄家族碼的最后一次差異可以用于有選擇性地跳過1-Wire器件的整個分組。如需進(jìn)行選擇性地搜索,可參考關(guān)于高級變量搜索的詳細(xì)解釋。64位ROM碼中包含8位循環(huán)冗余校驗(yàn)碼(CRC);CRC值用于驗(yàn)證是否搜索到正確的ROM碼注釋對實(shí)例中出現(xiàn)的符號進(jìn)行了說明;在本文檔的源代碼附錄中也將用到這些專用符號。注釋:id_bit—在位搜索中第一次讀取的值,該位是搜索過程中所有應(yīng)答器件的id_bit_number位的邏輯ANDcmp_id_bitid_bit位的補(bǔ)碼,該位是搜索過程中所有應(yīng)答器件的id_bit_number位的補(bǔ)碼的邏輯ANDid_bit_number記錄當(dāng)前搜索是1到64位ROM碼中哪一位的量LastDeviceFlag指明前一次搜索到的已是最后一個器件的標(biāo)志位LastDiscrepancy位指針指明下次搜索從哪個值差異位開始LastFamilyDiscrepancy位指針。用來指明LastDiscrepancy是否是在ROM碼中前8位家族碼內(nèi)和其位置last_zero上次被寫入0的值差異位的位置ROM_NO—記錄當(dāng)前正在查找的ROM,注冊碼的8字節(jié)緩沖器search_direction位變量其值用來指明搜索方向具有此數(shù)據(jù)位規(guī)定值的所有器件繼續(xù)響應(yīng)搜索操作其它器件轉(zhuǎn)入等待狀態(tài)直到下一次1-Wire復(fù)位搜索算法通過對LastDiscrepancy、LastFamilyDiscrepancy、LastDeviceFlag和ROM_NO值(參見表4)的處理利用上述流程實(shí)現(xiàn)了兩個不同類型的搜索操作;這兩個操作是搜索1-Wire器件ROM碼的基礎(chǔ)。FIRST‘FIRST’操作是搜索1-Wire總線上的第一個從機(jī)器件。該操作是通過將LastDiscrepancy、LastFamilyDiscrepancy和LastDeviceFlag置零,然后進(jìn)行搜索完成的。最后ROM碼從ROM_NO寄存器中讀出。若1-Wire總線上沒有器件,復(fù)位序列就檢測不到應(yīng)答脈沖,搜索過程中止。NEXT‘NEXT’操作是搜索1-Wire總線上的下一個從機(jī)器件;一般情況下此搜索操作是在‘FIRST’操作之后或上一次‘NEXT’操作之后進(jìn)行;保持上次搜索后這些值的狀態(tài)不變、執(zhí)行又一次搜索即可實(shí)現(xiàn)‘NEXT’操作。之后從ROM_NO寄存器中來讀出新一個ROM碼。若前一次搜索到的是1-Wire上的最后一個器件,則返回一個無效標(biāo)記FALSE,并且把狀態(tài)設(shè)置成下一次調(diào)用搜索算法時將是‘FIRST’操作的狀態(tài)。以下例舉了三個器件的搜索過程,為便于說明,設(shè)器件的ROM碼只有2位。搜索實(shí)例(為了簡化本例中省去了家族碼值差異位的記錄和跟蹤)FIRSTLastDiscrepancy=LastDeviceFlag=0?執(zhí)行1-Wire復(fù)位操作并等待在線應(yīng)答脈沖,若無在線應(yīng)答脈沖則結(jié)束id_bit_number=1,last_zero=0?發(fā)送搜索命令,0F0H讀第一個數(shù)據(jù)位id_bit:1(器件A)AND0(器件B)AND1(器件C)=0讀第一個數(shù)據(jù)位的補(bǔ)碼cmp_id_bit:0(器件A)AND1(器件B)AND0(器件C)=0?由于id_bit_number>LastDiscrepancy,設(shè)置search_direction=0,last_zero=1?發(fā)送當(dāng)前值為0的search_direction數(shù)據(jù)位,使器件A與器件C轉(zhuǎn)換到等待狀態(tài)id_bit_number值增到2讀第二個數(shù)據(jù)位id_bit:0(器件B)=0讀第二個數(shù)據(jù)位的補(bǔ)碼cmp_id_bit:1(器件B)=1由于數(shù)據(jù)位與其補(bǔ)碼不同設(shè)置,search_direction=id_bit?發(fā)送當(dāng)前值為0的search_direction數(shù)據(jù)位,查找到器件B的ROM_NO值為‘00’、并且是當(dāng)前選擇LastDiscrepancy=last_zeroNEXT1-Wire主機(jī)執(zhí)行復(fù)位操作并等待在線應(yīng)答脈沖,若無在線應(yīng)答脈沖則結(jié)束id_bit_number=1,last_zero=0?發(fā)送搜索命令,0F0H讀第一個數(shù)據(jù)位id_bit:1(器件A)AND0(器件B)AND1(器件C)=0讀第一個數(shù)據(jù)位的補(bǔ)碼cmp_id_bit:0器件A)AND1器件B)AND0器件C)=0由于id_bit_number=LastDiscrepancy,設(shè)置search_direction=1?發(fā)送當(dāng)前值為1的search_direction數(shù)據(jù)位,使器件B轉(zhuǎn)換到等待狀態(tài)id_bit_number值增值到2讀第二個數(shù)據(jù)位id_bit:0(器件A)AND1(器件C)=0讀第二個數(shù)據(jù)位的補(bǔ)碼cmp_id_bit:1(器件A)AND0(器件C)=0由于id_bit_number>LastDiscrepancy,設(shè)置search_direction=0,last_zero=2?發(fā)送當(dāng)前值為0的search_direction數(shù)據(jù)位,使器件C轉(zhuǎn)換到等待狀態(tài)查找到器件A的ROM_NO值為‘01’、并且是當(dāng)前選擇LastDiscrepancy=last_zeroNEXT?執(zhí)行1-Wire復(fù)位操作并等待在線應(yīng)答脈沖,若無在線應(yīng)答脈沖則結(jié)束id_bit_number=1,last_zero=0?發(fā)送搜索命令,0F0H讀第一個數(shù)據(jù)位id_bit:1(器件A)AND0(器件B)AND1(器件C)=0讀第一個數(shù)據(jù)位的補(bǔ)碼cmp_id_bit:0(器件A)AND1器件B)AND0器件C)=0?由于id_bit_number<LastDiscrepancy,設(shè)置search_direction=ROM_NO(第一位)=1?發(fā)送當(dāng)前值為1的search_direction數(shù)據(jù)位,使器件B轉(zhuǎn)換到等待狀態(tài)id_bit_number值增值2讀第二個數(shù)據(jù)位id_bit:0(器件A)AND1(器件C)=0讀第二個數(shù)據(jù)位的補(bǔ)碼cmp_id_bit:1(器件A)AND0(器件C)=0?由于id_bit_number=LastDiscrepancy,設(shè)置search_direction=1發(fā)送當(dāng)前值為1的search_direction數(shù)據(jù)位,使器件A轉(zhuǎn)換到等待狀態(tài)查找到器件C的ROM_NO值為‘11’、并且是當(dāng)前選擇LastDiscrepancy=last_zero值為0,所以設(shè)置LastDeviceFlag=TRUENEXTLastDeviceFlag值為TRUE,所以返回FALSELastDiscrepancy=LastDeviceFlag=0高級變量搜索有3種利用同一組狀態(tài)變量LastDiscrepancy、LastFamilyDiscrepancy、LastDeviceFlag、ROM_NO實(shí)現(xiàn)的高級變化搜索可以得到三種高級變量搜索算法,這幾種高級搜索算法允許來指定作為搜索目標(biāo)的器件的類型(家族碼)或者是指定需要跳過或驗(yàn)證某類型的器件是否在線(參見表4)。VERIFY‘VERIFY’操作用來檢驗(yàn)已知ROM碼的器件是否連接在1-Wire總線上,通過提供ROM碼并對該碼進(jìn)行目標(biāo)搜索就可確定此器件是否在線。首先將ROM_NO寄存器值設(shè)置為已知的ROM碼值,然后將LastDiscrepancy和LastDeviceFlag標(biāo)志位分別設(shè)置為64(40H)和0;進(jìn)行搜索操作,然后讀ROM_NO的輸出結(jié)果;如果搜索成功并且ROM_NO中存儲的仍是要搜索器件的ROM碼值,那么此器件就在1-Wire總線上。TARGETSETUP‘TARGETSETUP’操作就是用預(yù)置搜索狀態(tài)的方式首先查找一個特殊的家族類型,每個1-Wire器件都有一個字節(jié)的家族碼內(nèi)嵌在ROM碼中(參見圖1),主機(jī)可以通過家族碼來識別器件所具有的特性和功能。若1-Wire總線上有多片器件時,通常是將搜索目標(biāo)首先定位在需注意的器件類型上,為了將一個特殊的家族作為搜索目標(biāo),需要將所希望的家族碼字節(jié)放到ROM_NO寄存器的第一個字節(jié)中,并且將ROM_NO寄存器的復(fù)位狀態(tài)置零,然后將LastDiscrepancy設(shè)置為64(40H);把LastDeviceFlag和LastFamilyDiscrepancy設(shè)置為0。在執(zhí)行下一次搜索算法時就能找出所期望的產(chǎn)品類型的第一個器件;并將此值存入ROM_NO寄存器。需要注意的是如果1-Wire總線上沒有掛接所期望的產(chǎn)品類型的器件,就會找出另一類型的器件,所以每次搜索完成后,都要對ROM_NO寄存器中存儲的結(jié)果進(jìn)行校驗(yàn)。FAMILYSKIPSETUP‘FAMILYSKIPSETUP’操作用來設(shè)置搜索狀態(tài)以便跳過搜索到的指定家族中的所有器件,此操作只有在一個搜索過程結(jié)束后才能使用。通過把LastFamilyDiscrepancy復(fù)制到LastDiscrepancy,并清除LastDeviceFlag即可實(shí)現(xiàn)該操作;在下一搜索過程就會找到指定家族中的下一個器件。如果當(dāng)前家族碼分組是搜索過程中的最后一組,那么搜索過程結(jié)束并將LastDeviceFlag置位。表4搜索變量狀態(tài)的設(shè)置LastDiscrepancyLastFamilyDiscrepancyLastDeviceFlagROM_NOFIRST000結(jié)果NEXT不變不變不變結(jié)果VERIFY64隨意0設(shè)置ROM校驗(yàn),搜索完后檢查結(jié)果是否正確TARGETSETUP6400將第一個字節(jié)設(shè)置為家族碼復(fù)位狀態(tài)置零FAMILYSKIPSETUP復(fù)制LastFamilyDiscre-pancy不變0不變1-WireSearchAlgorithmAbstractDallasSemiconductor's1-Wire?deviceseachhavea64-bituniqueregistrationnumberinread-only-memory(ROM).Thatisusedtoaddressthemindividuallybya1-Wiremasterina1-Wirenetwork.IftheROMnumbersoftheslavedevicesonthe1-Wirenetworkarenotknown,thenusingasearchalgorithmcandiscoverthem.Thisdocumentexplainsthesearchalgorithmindetailandprovidesanexampleimplementationforrapidintegration.Thisalgorithmisvalidforallcurrentandfuturedevicesthatfeaturea1-Wireinterface.Table1BitUniqueROM'Registration'Number.MSB64-Bit'Registration'ROMNumberLSB8-BitCRC48-BitSerialNumber8-BitFamilyCodeMSBLSBMSBLSBMSBLSBSearchAlgorithmThesearchalgorithmisabinarytreesearchwherebranchesarefolloweduntiladeviceROMnumber,orleaf,isfound.Subsequentsearchesthentaketheotherbranchpathsuntilalloftheleavespresentarediscovered.Thesearchalgorithmbeginswiththedevicesonthe1-Wirebeingresetusingtheresetandpresencepulsesequence.Ifthisissuccessfulthenthe1-bytesearchcommandissent.Thesearchcommandreadiesthe1-Wiredevicestobeginthesearch.Therearetwotypesofsearchcommands.Thenormalsearchcommand(0F0hex)willperformasearchwithalldevicesparticipating.Thealarmorconditionalsearchcommand(0EChex)willperformasearchwithonlythedevicesthatareinsomesortofalarmstate.Thisreducesthesearchpooltoquicklyrespondtodevicesthatneedattention.Followingthesearchcommand,theactualsearchbeginswithalloftheparticipatingdevicessimultaneouslysendingthefirstbit(leastsignificant)intheirROMnumber(alsocalledregistrationnumber).(SeeFigure1.)Aswithall1-Wirecommunication,the1-Wiremasterstartseverybitwhetheritisdatatobereadorwrittentotheslavedevices.Duetothecharacteristicsofthe1-Wire,whenalldevicesrespondatthesametime,theresultwillbealogicalANDofthebitssent.AfterthedevicessendthefirstbitoftheirROMnumber,themasterinitiatesthenextbitandthedevicesthensendthecomplementofthefirstbit.Fromthesetwobits,informationcanbederivedaboutthefirstbitintheROMnumbersoftheparticipatingdevices.(SeeTable1.)Table2BitSearchInformationBit(true)Bit(complement)InformationKnown00Thereareboth0sand1sinthecurrentbitpositionoftheparticipatingROMnumbers.Thisisadiscrepancy.01Thereareonly0sinthebitoftheparticipatingROMnumbers.10Thereareonly1sinthebitoftheparticipatingROMnumbers.11Nodevicesparticipatinginsearch.Accordingtothesearchalgorithm,the1-Wiremastermustthensendabitbacktotheparticipatingdevices.Iftheparticipatingdevicehasthatbitvalue,itcontinuesparticipating.Ifitdoesnothavethebitvalue,itgoesintoawaitstateuntilthenext1-Wireresetisdetected.This'readtwobits'and'writeonebit'patternisthenrepeatedfortheremaining63bitsoftheROMnumber(seeTable2).Inthiswaythesearchalgorithmforcesallbutonedevicetogointothiswaitstate.Attheendofonepass,theROMnumberofthislastdeviceisknown.Onsubsequentpassesofthesearch,adifferentpath(orbranch)istakentofindtheotherdeviceROMnumbers.NotethatthisdocumentreferstothebitpositionintheROMnumberasbit1(leastsignificant)tobit64(mostsignificant).Thisconventionwasusedinsteadofbit0tobit63forconveniencetoallowinitializationofdiscrepancycountersto0forlatercomparisons.OnexaminationofTable1,itisobviousthatifalloftheparticipatingdeviceshavethesamevalueinabitpositionthenthereisonlyonechoiceforthebranchpathtobetaken.Theconditionwherenodevicesareparticipatingisanatypicalsituationthatmayariseifthedevicebeingdiscoveredisremovedfromthe1-Wireduringthesearch.Ifthissituationarisesthenthesearchshouldbeterminatedandanewsearchcouldbedonestartingwitha1-Wirereset.Table3WireMasterandSlaveSearchSequenceMasterSlave1-WireresetstimulusProducepresencepulse.Writesearchcommand(normaloralarm)Eachslavereadiesforsearch.
Read'AND'ofbit1Eachslavesendsbit1ofitsROMnumber.Read'AND'ofcomplementbit1Eachslavesendscomplementbit1ofitsROMnumber.Writebit1direction(accordingtoalgorithm)EachslavereceivesthebitwrittenbyMaster,ifbitreadisnotthesameasbit1ofitsROMnumberthengointoawaitstate.Read'AND'ofbit64Eachslavesendsbit64ofitsROMnumber.Read'AND'ofcomplementbit64Eachslavesendscomplementbit64ofitsROMnumber.Writebit64direction(accordingtoalgorithm)Eachslavereceivesthebitwrittenbymaster,ifbitreadisnotthesameasbit64ofitsROMnumberthengointoawaitstate.Theconditionwherethereareboth0sand1sinthebitpositioniscalledadiscrepancyandisthekeytofindingdevicesinthesubsequentsearches.Thesearchalgorithmspecifiesthatonthefirstpass,whenthereisadiscrepancy(bit/complement=0/0),the'0'pathistaken.Notethatthisisarbitraryforthisparticularalgorithm.Anotheralgorithmcouldbedevisedtousethe'1'pathfirst.Thebitpositionforthelastdiscrepancyisrecordedforuseinthenextsearch.Table3describesthepathsthataretakenonsubsequentsearcheswhenadiscrepancyoccurs.Table4SearchPathDirectionSearchBitPositionvsLastDiscrepancyPathTaken=takethe'1'path<takethesamepathaslasttime(fromlastROMnumberfound)>takethe'0'pathThesearchalgorithmalsokeepstrackofthelastdiscrepancythatoccurswithinthefirsteightbitsofthealgorithm.Thefirsteightbitsofthe64-bitregistrationnumberisafamilycode.Asaresult,thedevicesdiscoveredduringthesearcharegroupedintofamilytypes.Thelastdiscrepancywithinthatfamilycodecanbeusedtoselectivelyskipwholegroupsof1-Wiredevices.SeethedescriptionofADVANCEDSEARCHVARIATIONSfordoingselectivesearches.The64-bitROMnumberalsocontainsan8-bitcyclic-redundancy-check(CRC).ThisCRCvalueisverifiedtoensurethatonlycorrectROMnumbersarediscovered.SeeFigure1forthelayoutoftheROMnumber.Figure2showsaflowchartofthesearchsequence.NotetheReferencethatexplainsthetermsusedintheflowchart.Thesetermsarealsousedinthesourcecodeappendixtothisdocument.ReferenceId_bit—thefirstbitreadinabitsearchsequence.ThisbitistheANDofalloftheid_bit_numberbitsofthedevicesthatarestillparticipatinginthesearch.cmp_id_bit—thecomplementoftheid_bit.ThisbitistheANDofthecomplementofalloftheid_bit_numberbitsofthedevicesthatarestillparticipatinginthesearch.Id_bit_number—theROMbitnumber1to64currentlybeingsearched.LastDeviceFlag—flagtoindicateprevioussearchwasthelastdevice.LastDiscrepancy—bitindexthatidentifiesfromwhichbitthe(next)searchdiscrepancycheckshouldstart.LastFamilyDiscrepancy—bitindexthatidentifiestheLastDiscrepancywithinthefirst8-bitfamilycodeofROMnumber.last_zero—bitpositionofthelastzerowrittenwheretherewasadiscrepancy.ROM_NO—8-bytebufferthatcontainsthecurrentROMregistrationnumberdiscovered.search_direction—bitvalueindicatingthedirectionofthesearch.Alldeviceswiththisbitstayinthesearchandtherestgointoawaitstatefora1-Wirereset.TherearetwobasictypesofoperationsthatcanbeperformedbyusingthesearchalgorithmbymanipulatingtheLastDiscrepancy,LastFamilyDiscrepancy,LastDeviceFlag,andROM_NOregistervalues(seeTable4).TheseoperationsconcernbasicdiscoveryoftheROMnumbersof1-Wiredevices.FirstThe'FIRST'operationistosearchonthe1-Wireforthefirstdevice.ThisisperformedbysettingLastDiscrepancy,LastFamilyDiscrepancy,andLastDeviceFlagtozeroandthendoingthesearch.TheresultingROMnumbercanthenbereadfromtheROM_NOregister.Ifnodevicesarepresentonthe1-Wiretheresetsequencewillnotdetectapresenceandthesearchisaborted.NextThe'NEXT'operationistosearchonthe1-Wireforthenextdevice.Thissearchisusuallyperformedaftera'FIRST'operationoranother'NEXT'operation.Itisperformedbyleavingthestateunchangedfromtheprevioussearchandperforminganothersearch.TheresultingROMnumbercanthenbereadfromtheROM_NOregister.Iftheprevioussearchwasthelastdeviceonthe1-WirethentheresultwillbeFALSEandtheconditionwillbesettoexecutea'FIRST'withthenextcallofthesearchalgorithm.Thefollowinggoesthroughasimplesearchexamplewiththreedevices.Forillustration,thisexampleassumesdeviceswitha2-bitROMnumberonly.SearchExample(forsimplicitythefamilydiscrepancyregisterandtrackinghasbeenleftoutofthisexample)FIRSTLastDiscrepancy=LastDeviceFlag=0Do1-Wireresetandwaitforpresencepulse,ifnopresencepulsethendoneidbitnumber=1,lastzero=0Sendsearchcommand,0F0hexReadfirstbitid_bit:1(DeviceA)AND0(DeviceB)AND1(DeviceC)=0Readcomplementoffirstbitcmp_id_bit:0(DeviceA)AND1(DeviceB)AND0(DeviceC)=0Sinceid_bit_number>LastDiscrepancy,thensearch_direction=0,last_zero=1Sendsearch_directionbitof0,bothDeviceAandCgointowaitstateIncrementid_bit_numberto2Readsecondbitid_bit:0(DeviceB)=0Readcomplementofsecondbitcmp_id_bit:1(DeviceB)=1Sincebitandcomplementaredifferentthensearch_direction=id_bitSendsearch_directionbitof0,DeviceBisdiscoveredwithROM_NOof‘00’andisnowselectedLastDiscrepancy=last_zeroNEXTDo1-Wireresetandwaitforpresencepulse,ifnopresencepulsethendoneid_bit_number=1,last_zero=0Sendsearchcommand,0F0hexReadfirstbitid_bit:1(DeviceA)AND0(DeviceB)AND1(DeviceC)=0Readcomplementoffirstbitcmp_id_bit:0(DeviceA)AND1(DeviceB)AND0(DeviceC)=0Sinceid_bit_number=LastDiscrepancythensearch_direction=1Sendsearch_directionbitof1,DeviceBgoesintowaitstateIncrementid_bit_numberto2Readsecondbitid_bit:0(DeviceA)AND1(DeviceC)=0Readcomplementofsecondbitcmp_id_bit:1(DeviceA)AND0(DeviceC)=0Sinceid_bit_number>LastDiscrepancy,thensearch_direction=0,last_zero=2Sendsearch_directionbitof0,DeviceCgoesintowaitstateDeviceAisdiscoveredwithROM_NOof‘01’andisnowselectedLastDiscrepancy=last_zeroNEXTDo1-Wireresetandwaitforpresencepulse,ifnopresencepulsethendoneid_bit_number=1,last_zero=0Sendsearchcommand,0F0hexReadfirstbitid_bit:1(DeviceA)AND0(DeviceB)AND1(DeviceC)=0Readcomplementoffirstbitcmp_id_bit:0(DeviceA)AND1(DeviceB)AND0(DeviceC)=0Sinceid_bit_number<LastDiscrepancythensearch_direction=ROM_NO(firstbit)=1Sendsearch_directionbitof1,DeviceBgoesintowaitstateIncrementid_bit_numberto2Readsecondbitid_bit:0(DeviceA)AND1(DeviceC)=0Readcomplementofsecondbitcmp_id_bit:1(DeviceA)AND0(DeviceC)=0Sinceid_bit_number=LastDiscrepancy,thensearch_direction=1Sendsearch_directionbitof1,DeviceAgoesintowaitstateDeviceCisdiscoveredwithROM_NOof‘11’andisnowselectedLastDiscrepancy=last_zerowhichis0soLastDeviceFlag=TRUENEXTLastDeviceFlagistruesoreturnFALSELastDiscrepancy=LastDeviceFlag=0AdvancedSearchVariationsTherearethreeadvancedsearchvariationsusingthesamestateinformation,namelyLastDiscrepancy,LastFamilyDiscrepancy,LastDeviceFlag,andROM_NO.Thesevariationsallowspecificfamilytypestobetargetedorskippedanddevicepresentverification(seeTable4).VerifyThe'VERIFY'operationverifiesifadevicewithaknownROMnumberiscurrentlyconnectedtothe1-Wire.ItisaccomplishedbysupplyingtheROMnumberanddoingatargetedsearchonthatnumbertoverifyitispresent.First,settheROM_NOregistertotheknownROMnumber.ThensettheLastDiscrepancyto64(40hex)andtheLastDeviceFlagto0.PerformthesearchoperationandthenreadtheROM_NOresult.IfthesearchwassuccessfulandtheROM_NOremainstheROMnumberthatwasbeingsearchedfor,thenthedeviceiscurrentlyonthe1-Wire.TargetSetupThe'TARGETSETUP'operationisawaytopresetthesearchstatetofirstfindaparticularfamilytype.Each1-WiredevicehasaonebytefamilycodeembeddedwithintheROMnumber(seeFigure1).Thisfamilycodeallowsthe1-Wiremastertoknowwhatoperat
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年軍隊(duì)文職人員招聘之軍隊(duì)文職管理學(xué)考前沖刺模擬試卷A卷含答案
- 2025年軍隊(duì)文職人員招聘之軍隊(duì)文職公共科目題庫檢測試卷B卷附答案
- 2025年消防設(shè)施操作員之消防設(shè)備高級技能能力提升試卷B卷附答案
- 采購分包資源配置合同(2篇)
- 2023年全國碩士研究生考試《管理類聯(lián)考綜合能力》試題真題及答案
- 2025年黨史競賽知識題庫70題及答案
- 會計(jì)學(xué)成本會計(jì)模擬試題集
- 各行業(yè)各年度數(shù)據(jù)對比表格
- 泰坦尼克號的文化價值和社會反思:高中語文教學(xué)教案
- 經(jīng)濟(jì)學(xué)微觀經(jīng)濟(jì)學(xué)知識點(diǎn)歸納與解析
- 07SG111-1 建筑結(jié)構(gòu)加固施工圖設(shè)計(jì)表示方法
- 屋頂分布式光伏發(fā)電EPC項(xiàng)目 投標(biāo)方案(技術(shù)方案)
- 網(wǎng)約車停運(yùn)損失費(fèi)起訴狀模板
- 中國急性缺血性卒中診治指南(2023)解讀
- A型肉毒素治療知情同意書 注射知情同意書
- 混凝土采購項(xiàng)目整體供貨方案
- 血液透析導(dǎo)管溶栓及護(hù)理
- 公司外聘人員管理制度
- 慢病聯(lián)合用藥病
- 蘭州拉面-模板參考
- 武漢市2024屆高中畢業(yè)生二月調(diào)研考試(二調(diào))英語試卷(含答案)
評論
0/150
提交評論