Example – Echelon I/O Model Reference for Smart Transceivers and Neuron Chips User Manual

Page 60

Advertising
background image

50

Direct I/O Models

Example

// In this example, a leveldetect input is used on the
// 1-Wire interface to detect the 'presence' signal
// when a Touch Memory device appears on the bus.

#include <stdlib.h>

#define DS_READ_ROM 0x33
unsigned int data[8];
IO_3 input leveldetect ioPresence;
IO_3 touch ioTouchWire;
. . .

when (io_in(ioPresence) == 1) {
unsigned int i, crc;

// Reset the device using touch_reset().
// Skip if there is no device sensed.
if (touch_reset(ioTouchWire)) {
// Send a single READ_ROM command byte:
id_data[0] = DS_READ_ROM;
io_out(ioTouchWire, data, 1);

// Read the 8 byte I.D.:
io_in(ioTouchWire, data, 8);

// check the crc of the I.D.:
crc = 0;
for (i=0; i<7; i++)
crc = crc8(crc, data[i]);

if (crc == id_data[7]) {
// Valid crc: process I.D. data here.
}
}
// Clear leveldetect input.
(void)io_in(ioPresence);
}




Advertising