版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、<p> 1-Wire 搜索算法</p><p> Dallas Semiconductor的每片1-Wire®器件都有唯一的64位注冊(cè)碼它存儲(chǔ)在只讀存儲(chǔ)器(ROM)中。在1-Wire網(wǎng)絡(luò)中注冊(cè)碼用于1-Wire主機(jī)對(duì)從機(jī)器件進(jìn)行逐一尋址。如果1-Wire網(wǎng)絡(luò)中從機(jī)器件的ROM 碼是未知的,可以通過(guò)搜索算法來(lái)找到此碼。本文不僅詳細(xì)地解釋了搜索算法,而且還提供了實(shí)現(xiàn)快速整合的例程該算法適用于
2、任何具有1-Wire接口特性的現(xiàn)有產(chǎn)品及未來(lái)產(chǎn)品。</p><p> 表1 64 位唯一的ROM 注冊(cè)碼</p><p><b> 搜索算法</b></p><p> 搜索算法采用的是二叉樹型結(jié)構(gòu),搜索過(guò)程沿各分節(jié)點(diǎn)進(jìn)行,直到找到器件的ROM碼即葉子為止;后續(xù)的搜索操作沿著節(jié)點(diǎn)上的其它路徑進(jìn)行,按照同樣的方式直到找到總線上的所有器件代碼
3、。</p><p> 搜索算法首先通過(guò)復(fù)位(Reset)和在線應(yīng)答脈沖(Presence Pulse)時(shí)隙將1-Wire總線上的所有器件復(fù)位;成功地執(zhí)行該操作后,發(fā)送1個(gè)字節(jié)的搜索命令;搜索命令使1-Wire器件準(zhǔn)備、就緒開始進(jìn)行搜索操作。</p><p> 搜索命令分為兩類標(biāo)準(zhǔn)搜索命令(0F0H)用來(lái)搜索連接到網(wǎng)絡(luò)中所有器件;報(bào)警或有條件搜索命令(0ECH)只用來(lái)搜索那些處于報(bào)警狀態(tài)
4、下的器件,這種方式縮小了搜索范圍,可以快速查找到所需要注意的器件。</p><p> 搜索命令發(fā)出之后,開始實(shí)際的搜索過(guò)程。首先總線上的所有從機(jī)器件同時(shí)發(fā)送ROM 碼(也叫注冊(cè)碼)中的第一位(最低有效位)(參見圖1)。與所有的1-Wire通信一樣無(wú)論是讀取數(shù)據(jù)還是向從機(jī)器件寫數(shù)據(jù),都由1-Wire主機(jī)啟動(dòng)每一位操作。按照1-Wire的特性,當(dāng)所有從機(jī)器件同時(shí)應(yīng)答主機(jī)時(shí),結(jié)果相當(dāng)于全部發(fā)送數(shù)據(jù)位的邏輯AND;從機(jī)
5、發(fā)送其ROM碼的第一位后,主機(jī)啟動(dòng)下一位操作、接著從機(jī)發(fā)送第一位數(shù)據(jù)的補(bǔ)碼;從兩次讀到的數(shù)據(jù)位可以對(duì)ROM碼的第一位做出幾種判斷(參見表2)。</p><p> 按照搜索算法的要求,1-Wire主機(jī)必須向總線上的從機(jī)發(fā)回一個(gè)指定位;如果從機(jī)器件中ROM碼的當(dāng)前位的值與該數(shù)據(jù)位匹配,則繼續(xù)參與搜索過(guò)程;若從機(jī)器件的當(dāng)前位與之不匹配,則該器件轉(zhuǎn)換到等待狀態(tài),并保持等待狀態(tài)直到下一個(gè)1-Wire復(fù)位信號(hào)到來(lái)。其余63
6、位ROM 碼的搜索依然按照這種‘讀兩位’、‘寫一位’的模式進(jìn)行重復(fù)操作(參見表3)。</p><p><b> 表2 檢索信息位</b></p><p> 按照這種搜索算法進(jìn)行下去,最終除了一個(gè)從機(jī)器件外所有從機(jī)將進(jìn)入等待狀態(tài),經(jīng)過(guò)最后一輪檢測(cè),就可得到最后保留(未進(jìn)入等待狀態(tài))器件的ROM碼。在后續(xù)搜索過(guò)程中,選用不同的路徑(或分支)來(lái)查找其它器件的ROM碼。
7、需要注意的是本文ROM碼的數(shù)據(jù)位用第1位(最低有效位)到第64位(最高有效位)表示,而不是我們常用的那種第0位到第63位的模式;這樣設(shè)置允許將差異位置記數(shù)器初始值置為0,為以后的比較提供了方便。</p><p> 表3 1-Wire 主機(jī)和從機(jī)的搜索過(guò)程</p><p> 從表4 可以看出:如果所有總線上的器件在當(dāng)前位具有相同值,那么只有一條分支路徑可選;總線上沒(méi)有器件響應(yīng)的情況是
8、一種異常狀態(tài),可能是要查找的器件在搜尋過(guò)程中與1-Wire 總線脫離。如果當(dāng)前位既有0也有1,這種情況稱為位值差異,它對(duì)在后續(xù)搜索過(guò)程中查找器件起關(guān)鍵作用。搜索算法指定在第一輪查詢中若出現(xiàn)差異(數(shù)據(jù)位/補(bǔ)碼 = 0/0), 則選用‘0’路徑。注意:這一點(diǎn)是由本文檔中介紹的特定算法決定的,其它算法中或許首先選用‘1’路徑。記錄最后一次值差異的位置以供下一次搜索使用,表3列出了出現(xiàn)值差異時(shí)路徑的選取情況。</p><p&
9、gt; 表4 搜索路徑方向</p><p> 搜索算法計(jì)算還對(duì)最初8位過(guò)程中出現(xiàn)的最后一次位差異保持跟蹤;64位注冊(cè)碼的前8位是家族碼,在器件的搜索過(guò)程中可以按照其家族碼進(jìn)行分類。記錄家族碼的最后一次差異可以用于有選擇性地跳過(guò)1-Wire器件的整個(gè)分組。如需進(jìn)行選擇性地搜索,可參考關(guān)于高級(jí)變量搜索的詳細(xì)解釋。64位ROM碼中包含8位循環(huán)冗余校驗(yàn)碼(CRC);CRC值用于驗(yàn)證是否搜索到正確的ROM碼注釋對(duì)實(shí)例
10、中出現(xiàn)的符號(hào)進(jìn)行了說(shuō)明;在本文檔的源代碼附錄中也將用到這些專用符號(hào)。</p><p><b> 注釋:</b></p><p> id_bit——在位搜索中第一次讀取的值,該位是搜索過(guò)程中所有應(yīng)答器件的id_bit_number 位的邏輯AND</p><p> cmp_id_bit——id_bit 位的補(bǔ)碼,該位是搜索過(guò)程中所有應(yīng)答器件
11、的id_bit_number位的補(bǔ)碼的邏輯AND</p><p> id_bit_number——記錄當(dāng)前搜索是1到64位ROM碼中哪一位的量</p><p> LastDeviceFlag——指明前一次搜索到的已是最后一個(gè)器件的標(biāo)志位</p><p> LastDiscrepancy ——位指針指明下次搜索從哪個(gè)值差異位開始</p><p
12、> LastFamilyDiscrepancy——位指針。用來(lái)指明LastDiscrepancy是否是在ROM碼中前8位家族碼內(nèi)和其位置</p><p> last_zero——上次被寫入0的值差異位的位置</p><p> ROM_NO——記錄當(dāng)前正在查找的ROM,注冊(cè)碼的8字節(jié)緩沖器</p><p> search_direction——位變量其值
13、用來(lái)指明搜索方向具有此數(shù)據(jù)位規(guī)定值的所有器件繼續(xù)響應(yīng)搜索操作其它器件轉(zhuǎn)入等待狀態(tài)直到下一次1-Wire復(fù)位搜</p><p> 索算法通過(guò)對(duì)LastDiscrepancy、LastFamilyDiscrepancy、LastDeviceFlag 和</p><p> ROM_NO 值(參見表4)的處理利用上述流程實(shí)現(xiàn)了兩個(gè)不同類型的搜索操作;這兩個(gè)操作是搜索1-Wire 器件ROM 碼
14、的基礎(chǔ)。</p><p><b> FIRST</b></p><p> ‘FIRST’操作是搜索1-Wire總線上的第一個(gè)從機(jī)器件。該操作是通過(guò)將LastDiscrepancy、</p><p> LastFamilyDiscrepancy和LastDeviceFlag置零,然后進(jìn)行搜索完成的。最后ROM碼從ROM_NO</p&g
15、t;<p> 寄存器中讀出。若1-Wire總線上沒(méi)有器件,復(fù)位序列就檢測(cè)不到應(yīng)答脈沖,搜索過(guò)程中止。</p><p><b> NEXT</b></p><p> ‘NEXT’操作是搜索1-Wire總線上的下一個(gè)從機(jī)器件;一般情況下此搜索操作是在‘FIRST’</p><p> 操作之后或上一次‘NEXT’操作之后進(jìn)行;保
16、持上次搜索后這些值的狀態(tài)不變、執(zhí)行又一次搜索即可實(shí)現(xiàn)‘NEXT’操作。之后從ROM_NO寄存器中來(lái)讀出新一個(gè)ROM碼。若前一次搜索到的是1-Wire上的最后一個(gè)器件,則返回一個(gè)無(wú)效標(biāo)記FALSE,并且把狀態(tài)設(shè)置成下一次調(diào)用搜索算法時(shí)將是‘FIRST’操作的狀態(tài)。</p><p> 以下例舉了三個(gè)器件的搜索過(guò)程,為便于說(shuō)明,設(shè)器件的ROM碼只有2位。</p><p><b>
17、搜索實(shí)例 </b></p><p> (為了簡(jiǎn)化本例中省去了家族碼值差異位的記錄和跟蹤)</p><p><b> FIRST</b></p><p> LastDiscrepancy = LastDeviceFlag = 0</p><p> 執(zhí)行1-Wire復(fù)位操作并等待在線應(yīng)答脈沖,若無(wú)在線應(yīng)答
18、脈沖則結(jié)束</p><p> id_bit_number = 1, last_zero = 0</p><p> 發(fā)送搜索命令, 0F0H</p><p> 讀第一個(gè)數(shù)據(jù)位id_bit: 1 (器件 A) AND 0 (器件 B) AND 1 (器件 C) = 0</p><p> 讀第一個(gè)數(shù)據(jù)位的補(bǔ)碼 cmp_id_bit: 0 (
19、器件 A) AND 1 (器件 B) AND 0 (器件 C) = 0</p><p> 由于id_bit_number > LastDiscrepancy,設(shè)置 search_direction = 0, last_zero = 1</p><p> 發(fā)送當(dāng)前值為0的search_direction 數(shù)據(jù)位, 使器件A與器件C轉(zhuǎn)換到等待狀態(tài)</p><p&g
20、t; id_bit_number 值增到2</p><p> 讀第二個(gè)數(shù)據(jù)位id_bit: 0 (器件 B) = 0</p><p> 讀第二個(gè)數(shù)據(jù)位的補(bǔ)碼cmp_id_bit: 1 (器件 B) = 1</p><p> 由于數(shù)據(jù)位與其補(bǔ)碼不同設(shè)置,search_direction = id_bit</p><p> 發(fā)送當(dāng)前值為
21、0的search_direction數(shù)據(jù)位,查找到器件B的ROM_NO值為‘00’、 并且是當(dāng)前選擇</p><p> LastDiscrepancy = last_zero</p><p><b> NEXT</b></p><p> 1-Wire主機(jī)執(zhí)行復(fù)位操作并等待在線應(yīng)答脈沖,若無(wú)在線應(yīng)答脈沖則結(jié)束</p>
22、;<p> id_bit_number = 1, last_zero = 0</p><p> 發(fā)送搜索命令,0F0H</p><p> 讀第一個(gè)數(shù)據(jù)位id_bit: 1 (器件 A) AND 0 (器件 B) AND 1 (器件 C) = 0</p><p> 讀第一個(gè)數(shù)據(jù)位的補(bǔ)碼cmp_id_bit: 0 (器件 A) AND 1 (器件
23、B) AND 0 (器件 C) = 0</p><p> 由于id_bit_number = LastDiscrepancy,設(shè)置search_direction = 1</p><p> 發(fā)送當(dāng)前值為1的search_direction 數(shù)據(jù)位, 使器件B轉(zhuǎn)換到等待狀態(tài)</p><p> id_bit_number值增值到2</p><p
24、> 讀第二個(gè)數(shù)據(jù)位id_bit: 0 (器件 A) AND 1 (器件 C) = 0</p><p> 讀第二個(gè)數(shù)據(jù)位的補(bǔ)碼cmp_id_bit: 1 (器件 A) AND 0 (器件 C) = 0</p><p> 由于id_bit_number > LastDiscrepancy,設(shè)置search_direction = 0, last_zero = 2</p&
25、gt;<p> 發(fā)送當(dāng)前值為0的search_direction 數(shù)據(jù)位, 使器件C轉(zhuǎn)換到等待狀態(tài)</p><p> 查找到器件A的ROM_NO 值為‘01’、并且是當(dāng)前選擇</p><p> LastDiscrepancy = last_zero</p><p><b> NEXT</b></p><
26、p> 執(zhí)行1-Wire復(fù)位操作并等待在線應(yīng)答脈沖,若無(wú)在線應(yīng)答脈沖則結(jié)束</p><p> id_bit_number = 1, last_zero = 0</p><p> 發(fā)送搜索命令,0F0H</p><p> 讀第一個(gè)數(shù)據(jù)位id_bit: 1 (器件 A) AND 0 (器件 B) AND 1 (器件 C) = 0</p><
27、;p> 讀第一個(gè)數(shù)據(jù)位的補(bǔ)碼cmp_id_bit: 0 (器件 A) AND 1 (器件 B) AND 0 (器件 C) = 0</p><p> 由于id_bit_number < LastDiscrepancy,設(shè)置search_direction = ROM_NO(第一位)= 1</p><p> 發(fā)送當(dāng)前值為1 的search_direction 數(shù)據(jù)位, 使器件
28、B轉(zhuǎn)換到等待狀態(tài)</p><p> id_bit_number值增值2</p><p> 讀第二個(gè)數(shù)據(jù)位id_bit: 0 (器件 A) AND 1 (器件 C) = 0</p><p> 讀第二個(gè)數(shù)據(jù)位的補(bǔ)碼cmp_id_bit: 1 (器件 A) AND 0 (器件 C) = 0</p><p> 由于id_bit_number
29、= LastDiscrepancy,設(shè)置search_direction = 1</p><p> 發(fā)送當(dāng)前值為1的search_direction 數(shù)據(jù)位,使器件A轉(zhuǎn)換到等待狀態(tài)</p><p> 查找到器件C的ROM_NO值為‘11’、并且是當(dāng)前選擇</p><p> LastDiscrepancy = last_zero 值為0,所以設(shè)置 LastDev
30、iceFlag = TRUE</p><p><b> NEXT</b></p><p> LastDeviceFlag值為TRUE,所以返回FALSE</p><p> LastDiscrepancy = LastDeviceFlag = 0</p><p><b> 高級(jí)變量搜索</b>
31、</p><p> 有3種利用同一組狀態(tài)變量LastDiscrepancy、LastFamilyDiscrepancy、LastDeviceFlag、 ROM_NO實(shí)現(xiàn)的高級(jí)變化搜索可以得到三種高級(jí)變量搜索算法,這幾種高級(jí)搜索算法允許來(lái)指定作為搜索目標(biāo)的器件的類型(家族碼)或者是指定需要跳過(guò)或驗(yàn)證某類型的器件是否在線(參見表4)。</p><p><b> VERIFY<
32、;/b></p><p> ‘VERIFY’ 操作用來(lái)檢驗(yàn)已知ROM碼的器件是否連接在1-Wire總線上,通過(guò)提供ROM碼并對(duì)</p><p> 該碼進(jìn)行目標(biāo)搜索就可確定此器件是否在線。首先將ROM_NO寄存器值設(shè)置為已知的ROM碼值,然后將LastDiscrepancy和LastDeviceFlag標(biāo)志位分別設(shè)置為64(40H)和0;進(jìn)行搜索操作,然后讀ROM_NO的輸出結(jié)果;
33、如果搜索成功并且ROM_NO中存儲(chǔ)的仍是要搜索器件的ROM碼值,那么此器件就在1-Wire總線上。</p><p> TARGET SETUP</p><p> ‘TARGET SETUP’操作就是用預(yù)置搜索狀態(tài)的方式首先查找一個(gè)特殊的家族類型,每個(gè)1-Wire器件都有一個(gè)字節(jié)的家族碼內(nèi)嵌在ROM碼中(參見圖1),主機(jī)可以通過(guò)家族碼來(lái)識(shí)別器件所具有的特性和功能。若1-Wire總線上有多
34、片器件時(shí),通常是將搜索目標(biāo)首先定位在需注意的器件類型上,為了將一個(gè)特殊的家族作為搜索目標(biāo),需要將所希望的家族碼字節(jié)放到ROM_NO寄存器的第一個(gè)字節(jié)中,并且將ROM_NO寄存器的復(fù)位狀態(tài)置零,然后將LastDiscrepancy設(shè)置為64(40H);把LastDeviceFlag和LastFamilyDiscrepancy設(shè)置為0。在執(zhí)行下一次搜索算法時(shí)就能找出所期望的產(chǎn)品類型的第一個(gè)器件;并將此值存入ROM_NO寄存器。需要注意的是如
35、果1-Wire總線上沒(méi)有掛接所期望的產(chǎn)品類型的器件,就會(huì)找出另一類型的器件,所以每次搜索完成后,都要對(duì)ROM_NO寄存器中存儲(chǔ)的結(jié)果進(jìn)行校驗(yàn)。</p><p> FAMILY SKIP SETUP</p><p> ‘FAMILY SKIP SETUP’操作用來(lái)設(shè)置搜索狀態(tài)以便跳過(guò)搜索到的指定家族中的所有器件,此操作只有在一個(gè)搜索過(guò)程結(jié)束后才能使用。通過(guò)把LastFamilyDiscr
36、epancy復(fù)制到LastDiscrepancy,并清除LastDeviceFlag即可實(shí)現(xiàn)該操作;在下一搜索過(guò)程就會(huì)找到指定家族中的下一個(gè)器件。如果當(dāng)前家族碼分組是搜索過(guò)程中的最后一組,那么搜索過(guò)程結(jié)束并將LastDeviceFlag 置位。</p><p> 表4 搜索變量狀態(tài)的設(shè)置 </p><p> 1-Wire Search Algorithm</p><
37、;p><b> Abstract</b></p><p> Dallas Semiconductor's 1-Wire® devices each have a 64-bit unique registration number in read-only-memory (ROM).That is used to address them individually
38、by a 1-Wire master in a 1-Wire network. If the ROM numbers of the slave devices on the 1-Wire network are not known, then using a search algorithm can discover them. This document explains the search algorithm in detail
39、and provides an example implementation for rapid integration. This algorithm is valid for all current and future devices that f</p><p> Table 1 Bit Unique ROM 'Registration' Number.</p><p
40、> Search Algorithm</p><p> The search algorithm is a binary tree search where branches are followed until a device ROM number, or leaf, is found. Subsequent searches then take the other branch paths unt
41、il all of the leaves present are discovered.</p><p> The search algorithm begins with the devices on the 1-Wire being reset using the reset and presence pulse sequence. If this is successful then the 1-byte
42、 search command is sent. The search command readies the 1-Wire devices to begin the search.</p><p> There are two types of search commands. The normal search command (0F0 hex) will perform a search with all
43、 devices participating. The alarm or conditional search command (0EC hex) will perform a search with only the devices that are in some sort of alarm state. This reduces the search pool to quickly respond to devices that
44、need attention.</p><p> Following the search command, the actual search begins with all of the participating devices simultaneously sending the first bit (least significant) in their ROM number (also called
45、 registration number). (See Figure 1.) As with all 1-Wire communication, the 1-Wire master starts every bit whether it is data to be read or written to the slave devices. Due to the characteristics of the 1-Wire, when al
46、l devices respond at the same time, the result will be a logical AND of the bits sent. After the d</p><p> Table 2 Bit Search Information</p><p> According to the search algorithm, the 1-Wire
47、 master must then send a bit back to the participating devices. If the participating device has that bit value, it continues participating. If it does not have the bit value, it goes into a wait state until the next 1-Wi
48、re reset is detected. This 'read two bits' and 'write one bit' pattern is then repeated for the remaining 63 bits of the ROM number (see Table 2). In this way the search algorithm forces all but one devic
49、e to go into this wait state. A</p><p> On examination of Table 1, it is obvious that if all of the participating devices have the same value in a bit position then there is only one choice for the branch p
50、ath to be taken. The condition where no devices are participating is an atypical situation that may arise if the device being discovered is removed from the 1- Wire during the search. If this situation arises then the se
51、arch should be terminated and a new search could be done starting with a 1-Wire reset. </p><p> Table 3 Wire Master and Slave Search Sequence</p><p> The condition where there are both 0s and
52、1s in the bit position is called a discrepancy and is the key to finding devices in the subsequent searches. The search algorithm specifies that on the first pass, when there is a discrepancy (bit/complement = 0/0), the
53、'0' path is taken. Note that this is arbitrary for this particular algorithm. Another algorithm could be devised to use the '1' path first. The bit position for the last discrepancy is recorded for use in
54、 the next search. Table 3 describe</p><p> Table 4 Search Path Direction</p><p> The search algorithm also keeps track of the last discrepancy that occurs within the first eight bits of the a
55、lgorithm. The first eight bits of the 64-bit registration number is a family code. As a result, the devices discovered during the search are grouped into family types. The last discrepancy within that family code can be
56、used to selectively skip whole groups of 1-Wire devices. See the description of ADVANCED SEARCH VARIATIONS for doing selective searches. The 64-bit ROM number also contai</p><p> Id_bit—the first bit read i
57、n a bit search sequence. This bit is the AND of all of the id_bit_number bits of the devices that are still participating in the search.</p><p> cmp_id_bit—the complement of the id_bit .This bit is the AND
58、of the complement of all of the id_bit_number bits of the devices that are still participating in the search.</p><p> Id_bit_number—the ROM bit number 1 to 64 currently being searched.</p><p>
59、 LastDeviceFlag—flag to indicate previous search was the last device.</p><p> LastDiscrepancy—bit index that identifies from which bit the (next) search discrepancy check should start.</p><p>
60、 LastFamilyDiscrepancy—bit index that identifies the LastDiscrepancy within the first 8-bit family code of ROM number.</p><p> last_zero—bit position of the last zero written where there was a discrepancy.&
61、lt;/p><p> ROM_NO—8-byte buffer that contains the current ROM registration number discovered.</p><p> search_direction—bit value indicating the direction of the search. All devices with this bit
62、stay in the search and the rest go into a wait state for a 1-Wire reset.</p><p> There are two basic types of operations that can be performed by using the search algorithm by manipulating the LastDiscrepan
63、cy, LastFamilyDiscrepancy, LastDeviceFlag, and ROM_NO register values (see Table 4). These operations concern basic discovery of the ROM numbers of 1-Wire devices.First</p><p> The 'FIRST' operation
64、 is to search on the 1-Wire for the first device. This is performed by setting LastDiscrepancy, LastFamilyDiscrepancy, and LastDeviceFlag to zero and then doing the search. The resulting ROM number can then be read from
65、the ROM_NO register. If no devices are present on the 1- Wire the reset sequence will not detect a presence and the search is aborted.Next</p><p> The 'NEXT' operation is to search on the 1-Wire for
66、 the next device. This search is usually performed after a 'FIRST' operation or another 'NEXT' operation. It is performed by leaving the state unchanged from the previous search and performing another sea
67、rch. The resulting ROM number can then be read from the ROM_NO register. If the previous search was the last device on the 1-Wire then the result will be FALSE and the condition will be set to execute a 'FIRST' w
68、ith the next call of the search a</p><p> The following goes through a simple search example with three devices. For illustration, this example assumes devices with a 2-bit ROM number only.</p><p
69、> Search Example</p><p> (for simplicity the family discrepancy register and tracking has been left out of this example)</p><p><b> FIRST</b></p><p> LastDiscrepa
70、ncy = LastDeviceFlag = 0</p><p> Do 1-Wire reset and wait for presence pulse ,if no presence pulse then done</p><p> ?id_bit_number = 1, last_zero = 0</p><p> Send search command
71、 ,0F0 hex</p><p> Read first bit id_bit : 1 (Device A) AND 0 (Device B) AND 1 (Device C) = 0</p><p> Read complement of first bit cmp_id_bit : 0 (Device A) AND 1 (Device B) AND 0 (Device C) =
72、0</p><p> Since id_bit_number > LastDiscrepancy,then search_direction = 0, last_zero = 1</p><p> Send search_direction bit of 0 , both Device A and C go into wait state</p><p>
73、 Increment id_bit_number to 2</p><p> Read second bit id_bit : 0(Device B) = 0</p><p> Read complement of second bit cmp_id_bit : 1 (Device B) = 1</p><p> Since bit and compleme
74、nt are different then search_direction = id_bit</p><p> Send search_direction bit of 0 ,Device B is discovered with ROM_NO of ‘00’ and is now selected</p><p> LastDiscrepancy = last_zero</p
75、><p><b> NEXT</b></p><p> Do 1-Wire reset and wait for presence pulse ,if no presence pulse then done</p><p> id_bit_number = 1, last_zero = 0</p><p> Send
76、 search command ,0F0 hex</p><p> Read first bit id_bit : 1 (Device A) AND 0 (Device B) AND 1 (Device C) = 0</p><p> Read complement of first bit cmp_id_bit : 0 (Device A) AND 1 (Device B) AND
77、0 (Device C) = 0</p><p> Since id_bit_number = LastDiscrepancy then search_direction = 1</p><p> Send search_direction bit of 1 , Device B goes into wait state</p><p> Increment
78、id_bit_number to 2</p><p> Read second bit id_bit : 0(Device A) AND 1(Device C) = 0</p><p> Read complement of second bit cmp_id_bit : 1(Device A) AND 0(Device C) = 0</p><p> Sin
79、ce id_bit_number > LastDiscrepancy,then search_direction = 0, last_zero = 2</p><p> Send search_direction bit of 0 , Device C goes into wait state</p><p> Device A is discovered with ROM_NO
80、 of ‘01’ and is now selected</p><p> LastDiscrepancy = last_zero</p><p><b> NEXT</b></p><p> Do 1-Wire reset and wait for presence pulse ,if no presence pulse then do
81、ne</p><p> id_bit_number = 1, last_zero = 0</p><p> Send search command ,0F0 hex</p><p> Read first bit id_bit : 1 (Device A) AND 0 (Device B) AND 1 (Device C) = 0</p><
82、;p> Read complement of first bit cmp_id_bit : 0 (Device A) AND 1 (Device B) AND 0 (Device C) = 0</p><p> Since id_bit_number < LastDiscrepancy then search_direction = ROM_NO (first bit) = 1</p>
83、<p> Send search_direction bit of 1 , Device B goes into wait state</p><p> Increment id_bit_number to 2</p><p> Read second bit id_bit : 0(Device A) AND 1(Device C) = 0</p><
84、;p> Read complement of second bit cmp_id_bit : 1(Device A) AND 0(Device C) = 0</p><p> Since id_bit_number = LastDiscrepancy,then search_direction = 1</p><p> Send search_direction bit of
85、1 , Device A goes into wait state</p><p> Device C is discovered with ROM_NO of ‘11’ and is now selected</p><p> LastDiscrepancy = last_zero which is 0 so LastDeviceFlag = TRUE</p><
86、p><b> NEXT</b></p><p> LastDeviceFlag is true so return FALSE</p><p> ?LastDiscrepancy = LastDeviceFlag = 0</p><p> Advanced Search Variations</p><p>
87、; There are three advanced search variations using the same state information, namely LastDiscrepancy, LastFamilyDiscrepancy, LastDeviceFlag, and ROM_NO. These variations allow specific family types to be targeted or sk
88、ipped and device present verification (see Table 4).</p><p><b> Verify</b></p><p> The 'VERIFY' operation verifies if a device with a known ROM number is currently connecte
89、d to the 1- Wire. It is accomplished by supplying the ROM number and doing a targeted search on that number to verify it is present. First, set the ROM_NO register to the known ROM number. Then set the LastDiscrepancy to
90、 64 (40 hex) and the LastDeviceFlag to 0. Perform the search operation and then read the ROM_NO result. If the search was successful and the ROM_NO remains the ROM number that was being searc</p><p> Target
91、 Setup</p><p> The 'TARGET SETUP' operation is a way to preset the search state to first find a particular family type. Each 1-Wire device has a one byte family code embedded within the ROM number (
92、see Figure 1). This family code allows the 1-Wire master to know what operations this device is capable of. If there are multiple devices on the 1-Wire it is common practice to target a search to only the family of devic
93、es that are of interest. To target a particular family, set the desired family code byte into the</p><p> Family Skip Setup</p><p> The 'FAMILY SKIP SETUP' operation sets the search st
94、ate to skip all of the devices that have the family code that was found in the previous search. This operation can only be performed after a search. It is accomplished by copying the LastFamilyDiscrepancy into the LastDi
95、screpancy and clearing out the LastDeviceFlag. The next search will then find devices that come after the current family code. If the current family code group was the last group in the search then the search will return
96、 with th</p><p> Table5 Search Variations State Setup</p><p> Conclusion</p><p> The supplied search algorithm allows the discovery of the individually unique ROM numbers from a
97、ny given group of 1-Wire devices. This is essential to any multidrop 1-Wire application. With the ROM numbers in hand, each 1-Wire device can be selected individually for operations. This document also discussed search v
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 眾賞文庫(kù)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
評(píng)論
0/150
提交評(píng)論