【正文】
types. The last discrepancy within that family code can be used to selectively skip whole groups of 1Wire devices. See the description of ADVANCED SEARCH VARIATIONS for doing selective searches. The 64bit ROM number also contains an 8bit cyclicredundancycheck (CRC). This CRC value is verified to ensure that only correct ROM numbers are discovered. See Figure 1 for the layout of the ROM 2 shows a flow chart of the search sequence. Note the Reference that explains the terms used in the flow chart. These terms are also used in the source code appendix to this Id_bit— the first bit read in 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. cmp_id_bit— the plement of the id_bit .This bit is the AND of the plement of all of the id_bit_number bits of the devices that are still participating in the search. Id_bit_number— the ROM bit number 1 to 64 currently being searched. LastDeviceFlag— flag to indicate previous search was the last device. LastDiscrepancy— bit index that identifies from which bit the (next) search discrepancy check should start. LastFamilyDiscrepancy— bit index that identifies the LastDiscrepancy within the first 8bit family code of ROM number. last_zero— bit position of the last zero written where there was a discrepancy. ROM_NO— 8byte buffer that contains the current ROM registration number discovered. search_direction— bit value indicating the direction of the search. All devices with this bit stay in the search and the rest go into a wait state for a 1Wire reset. There are two basic types of operations that can be performed by using the search algorithm by manipulating the LastDiscrepancy, LastFamilyDiscrepancy, LastDeviceFlag, and ROM_NO register values (see Table 4). These operations concern basic discovery of the ROM numbers of 1Wire The 39。 operation is to search on the 1Wire 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 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 The 39。 operation is to search on the 1Wire for the next device. This search is usually performed after a 39。 operation or another 39。 operation. It is performed by leaving the state unchanged from the previous search and performing another search. The resulting ROM number can then be read from the ROM_NO register. If the previous search was the last device on the 1Wire then the result will be FALSE and the condition will be set to execute a 39。 with the next call of the search algorithm. The following goes through a simple search example with three devices. For illustration, this example assumes devices with a 2bit ROM number only. Search Example (for simplicity the family discrepancy register and tracking has been left out of this example) FIRST LastDiscrepancy = LastDeviceFlag = 0 Do 1Wire reset and wait for presence pulse ,if no presence pulse then done 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 = 0, last_zero = 1 Send search_direction bit of 0 , both Device A and C go into wait state Increment id_bit_number to 2 Read second bit id_bit : 0(Device B) = 0 Read plement of second bit cmp_id_bit : 1 (Device B) = 1 Since bit and plement are different then search_direction = id_bit Send search_direction bit of 0 ,Device B is discovered with ROM_NO of ‘00’ 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 = 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