Manual

146 Functions
touch_next( ) Built-in Function
The touch_next( ) function executes the ROM Search algorithm as described in
application note 937,
Book of iButton Standards
, from Maxim Integrated
Products. Both functions make use of a search_data_s data structure for
intermediate storage of a bit marker and the current ROM data. This data
structure is automatically defined in Neuron C, regardless of whether a program
references the touch I/O functions.
A return value of TRUE indicates whether a device was found, and if so, that the
data stored at rom_data[ ] is valid. A FALSE return value indicates no device
found. The search_done flag is set to TRUE when there are no more devices on
the 1-Wire bus. The last_discrepancy variable is used internally, and should not
be modified.
To start a new search, first call touch_first( ). Then, as long as the search_done
flag is not set, call touch_next( ) as many times as are required. For a Series
3100 device, each call to touch_first( ) or touch_next( ) takes 41 ms to execute at
10 MHz (63 ms at 5 MHz) when a device is being read. For a Series 5000 device,
each call to touch_first( ) or touch_next( ) takes 14 ms to execute at 80 MHz (29
ms at 10 MHz) when a device is being read.
Syntax
int
touch_next(
io-object-name
, search_data *
sd
);
Example
typedef struct search_data_s {
int search_done;
int last_discrepancy;
unsigned rom_data[8];
} search_data;
search_data sd;
void f(void)
{
sd.rom_data[0] = ...;
sd.rom_data[1] = ...;
...
sd.rom_data[7] = ...;
if (touch_first(ioObj, &sd)) {
// Found ...
while (!(sd.search_done)) {
if (touch_next(ioObj, &sd)) {
// Found another ...
}
}
}
}