【正文】
using a search algorithm can discover them. This document explains the search algorithm in detail and provides an example implementation for rapid integration. This algorithm is valid for all current and future devices that feature a 1Wire interface. Table 1 Bit Unique ROM 39。 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 device to go into this wait state. At the end of one pass, the ROM number of this last device is known. On subsequent passes of the search, a different path (or branch) is taken to find the other device ROM numbers. Note that this document refers to the bit position in the ROM number as bit 1 (least significant) to bit 64 (most significant). This convention was used instead of bit 0 to bit 63 for convenience to allow initialization of discrepancy counters to 0 for later parisons. 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 path 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 search should be terminated and a new search could be done starting with a 1Wire reset. Table 3 Wire Master and Slave Search Sequence Master Slave 1Wire reset stimulus Produce presence pulse. Write search mand (normal or alarm) Each slave readies for search. Read 39。 of plement bit 64 Each slave sends plement bit 64 of its ROM number. Write bit 64 direction (according to algorithm) Each slave receives the bit written by master, if bit read is not the same as bit 64 of its ROM number then go into a wait state. The condition where there are both 0s and 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/plement = 0/0), the 39。 path The search algorithm also keeps track of the last discrepancy that occurs within the first eight bits of the algorithm. The first eight bits of the 64bit 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 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. 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 previo