1、 外文资料 1-Wire Search Algorithm Abstract Dallas Semiconductors 1-Wire devices each have a 64-bit unique registration number in read-only-memory (ROM).That is used to address them individually 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
2、known, then 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 1-Wire interface. Table 1 Bit Unique ROM Registration
3、Number. MSB 64-Bit Registration ROM Number LSB 8-Bit CRC MSB LSB 48-Bit Serial Number MSB LSB 8-Bit Family Code MSB LSB Search Algorithm 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 bran
4、ch paths until all of the leaves present are discovered. 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 search command is sent. The search command readies the 1-Wire devices to begin the search
5、. There are two types of search commands. The normal search command (0F0 hex) will perform a search with all 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 quic
6、kly respond to devices that need attention. 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 registration number). (See Figure 1.) As with all 1-Wire communication, t
7、he 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 all devices respond at the same time, the result will be a logical AND of the bits sent. After the devices send the first bit of their ROM number, the maste
8、r initiates the next bit and the devices then send the complement of the first bit. From these two bits, information can be derived about the first bit in the ROM numbers of the participating devices. (See Table 1.) Table 2 Bit Search Information Bit (true) Bit (complement) Information Known 0 0 The
9、re are both 0s and 1s in the current bit position of the participating ROM numbers. This is a discrepancy. 0 1 There are only 0s in the bit of the participating ROM numbers. 1 0 There are only 1s in the bit of the participating ROM numbers. 1 1 No devices participating in search. According to the se
10、arch algorithm, the 1-Wire 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-Wire reset is detected. This read two bits and write one
11、 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 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 (o
12、r 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
13、 to 0 for later comparisons. 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
14、 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 1-Wire reset. Table 3 Wire Master and Slave Search Sequence Master Slave 1-Wire reset stimulus Produce presence
15、pulse. Write search command (normal or alarm) Each slave readies for search. Read AND of bit 1 Each slave sends bit 1 of its ROM number. Read AND of complement bit 1 Each slave sends complement bit 1 of its ROM number. Write bit 1 direction (according to algorithm) Each slave receives the bit writte
16、n by Master, if bit read is not the same as bit 1 of its ROM number then go into a wait state. Read AND of bit 64 Each slave sends bit 64 of its ROM number. Read AND of complement bit 64 Each slave sends complement bit 64 of its ROM number. Write bit 64 direction (according to algorithm) Each slave
17、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
18、 that on the first pass, when there is a discrepancy (bit/complement = 0/0), the 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 the next search. T
19、able 3 describes the paths that are taken on subsequent searches when a discrepancy occurs. Table 4 Search Path Direction Search Bit Position vs Last Discrepancy Path Taken = take the 1 path take the 0 path The search algorithm also keeps track of the last discrepancy that occurs within the first ei
20、ght bits of the algorithm. 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 used to selectively skip whole groups of 1-Wire devices. See the description of ADVANCED