【正文】
t_number = 1, last_zero = 0 Send search mand ,0F0 hex Read first bit id_bit : 1 (Device A) AND 0 (Device B) AND 1 (Device C) = 0 Read plement of first bit cmp_id_bit : 0 (Device A) AND 1 (Device B) AND 0 (Device C) = 0 Since id_bit_number = LastDiscrepancy then search_direction = 1 Send search_direction bit of 1 , Device B goes into wait state Increment id_bit_number to 2 Read second bit id_bit : 0(Device A) AND 1(Device C) = 0 Read plement of second bit cmp_id_bit : 1(Device A) AND 0(Device C) = 0 Since id_bit_number LastDiscrepancy, then search_direction = 0, last_zero = 2 Send search_direction bit of 0 , Device C goes into wait state Device A is discovered with ROM_NO of ‘01’ and is now selected LastDiscrepancy = last_zero NEXT Do 1Wire reset and wait for presence pulse ,if no presence pulse then done id_bit_number = 1, last_zero = 0 Send search mand ,0F0 hex Read first bit id_bit : 1 (Device A) AND 0 (Device B) AND 1 (Device C) = 0 Read plement of first bit cmp_id_bit : 0 (Device A) AND 1 (Device B) AND 0 (Device C) = 0 Since id_bit_number LastDiscrepancy then search_direction = ROM_NO (first bit) = 1 Send search_direction bit of 1 , Device B goes into wait state Increment id_bit_number to 2 Read second bit id_bit : 0(Device A) AND 1(Device C) = 0 Read plement of second bit cmp_id_bit : 1(Device A) AND 0(Device C) = 0 Since id_bit_number = LastDiscrepancy, then search_direction = 1 Send search_direction bit of 1 , Device A goes into wait state Device C is discovered with ROM_NO of ‘11’ and is now selected LastDiscrepancy = last_zero which is 0 so LastDeviceFlag = TRUE NEXT LastDeviceFlag is true so return FALSE Advanced Search Variations 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 skipped and device present verification (see Table 4). Verify The 39。 code example implementation of the search and all of the search variations. 中文譯文 1Wire 搜索算法 緒論 Dallas Semiconductor的每片 1Wire174。 搜索命令發(fā)出之后,開始實際的搜索過程。 1 1 總線上沒有從機器件響應(yīng)。 寫第 1 位指定位 (依照算法 ) 從機接收主機的指定位若所讀的位與 ROM碼的第 1 位不匹配,則進入等待狀態(tài)。記錄最后一次值差異的位置以供下一次搜索使用,表 3列出了出現(xiàn)值差異時路徑的選取情況。該操作是通過將LastDiscrepancy、 LastFamilyDiscrepancy和 LastDeviceFlag置零,然后進行搜索完成的。 VERIFY ‘ VERIFY’ 操作用來檢驗已知 ROM碼的器件是否連接在 1Wire總線上,通過提供ROM碼并對 該碼進行目標搜索就可確定此器件是否在線。如果當前家族碼分組是搜索過程中的最后一組,那么搜索過程結(jié)束并將 LastDeviceFlag 置位。 FAMILY SKIP SETUP ‘ FAMILY SKIP SETUP’操作用來設(shè)置搜索狀態(tài) 以便跳過搜索到的指定家族中的所有器件,此操作只有在一個搜索過程結(jié)束后才能使用。 以下例舉了三個器件的搜索過程,為便于說明,設(shè)器件的 ROM碼只有 2位。用來指明 LastDiscrepancy是否是在ROM碼中前 8位家族碼內(nèi)和其位置 last_zero—— 上次被寫入 0的值差異位的位置 ROM_NO—— 記錄當前正在查找的 ROM,注冊碼的 8字節(jié)緩沖器 search_direction—— 位變量其值用來指明搜索方向具有此數(shù)據(jù)位規(guī)定值的所有器件繼續(xù)響應(yīng)搜索操作其它器件轉(zhuǎn)入等待狀態(tài)直到下一次 1Wire復(fù)位搜 索算法通過對 LastDiscrepancy、 LastFamilyDiscrepancy、 LastDeviceFlag 和 ROM_NO 值 (參見表 4)的處理利用上述流程實現(xiàn)了兩個不同類型的搜索操作;這兩個操作是搜索 1Wire 器件 ROM 碼的基礎(chǔ)。搜索算法指定在第一輪查詢中若出現(xiàn)差異 (數(shù)據(jù)位 /補碼 = 0/0), 則選用‘ 0’路徑。 讀第 1 位的 AND 從機發(fā)送 ROM 碼的第 1 位。 表 2 檢索信息位 位 (實際值 ) 位 (補碼 ) 結(jié)論 0 0 從機 ROM碼 中的當前位既有 0,也有 1;即存在差異 0 1 從機 ROM碼中的當前位均為 0。 搜索算法首先通過復(fù)位 (Reset)和在線應(yīng)答脈沖 (Presence Pulse)時隙將1Wire總線上的所有器件復(fù)位;成功地執(zhí)行該操作后,發(fā)送 1個字節(jié)的搜索命令;搜索命令使 1Wire器件準備、就緒開始進行搜索操作。 operation sets the search state 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 acplished by copying the LastFamilyDiscrepancy into the LastDiscrepancy and clearing out the LastDeviceFlag. The next search will then find devices that e after the current family code. If the current family code group was the last group in the search then the search will retur n with the LastDeviceFlag set. Table5 Search Variations State Setup LastDiscrepancy LastFamily LastDeviceFlag ROM_NO Discrepancy FIRST 0 0 0 result NEXT leave unchanged leave unchanged leave unchanged result VERIFY 64 random 0 set with ROM to verify, check if same after search TARGET SETUP 64 0 0 set first byte to family code, set rest to zeros FAMILY SKIP SETUP copy from LastFamilyDiscrepancy leave unchanged 0 leave unchanged Conclusion The supplied search algorithm allows the discovery of the individually unique ROM numbers from any given group of 1Wire devices. This is essential to any multidrop 1Wire application. With the ROM numbers in hand, each 1Wire device can be selected individually