stamp.peripheral.io
Class I2C

java.lang.Object
  |
  +--stamp.peripheral.io.I2C

public class I2C
extends Object

This class defines a physical bus and provides essential I2C protocol routines. The bus pins should be pulled up to Vdd through 4.7K resistors.

This class can be used as-is, but will usually be referenced by a specific device class that uses the I2C bus. Direct use of this class requires the programmer to have some understanding of the I2C bus and protocol. Consult Philips documentation for details:

http://www.semiconductors.philips.com/i2c/

Creating the bus requires two available pins: SDA (serial data) and SCL (serial clock).

I2C ioBus = new I2C(CPU.pin0, CPU.pin1); // SDA on pin 0; SCL on pin 1


Field Summary
static int ACK
           
static int NAK
           
protected  int sclPin
           
protected  int sdaPin
           
 
Constructor Summary
I2C(int sdaPin, int sclPin)
          Creates I2C bus object and intializes bus pins.
 
Method Summary
 int read(int ackBit)
          Read 8-bit value from I2C device.
 void start()
          Send I2C Start sequence.
 void stop()
          Send I2C Stop sequence.
 boolean write(int i2cData)
          Write 8-bit value to I2C device.
 
Methods inherited from class java.lang.Object
equals
 

Field Detail

ACK

public static final int ACK

NAK

public static final int NAK

sdaPin

protected int sdaPin

sclPin

protected int sclPin
Constructor Detail

I2C

public I2C(int sdaPin,
           int sclPin)
Creates I2C bus object and intializes bus pins.
Parameters:
sdaPin - I2C serial data pin (bi-directional)
sclPin - I2C serial clock pin
Method Detail

start

public void start()
Send I2C Start sequence.

write

public boolean write(int i2cData)
Write 8-bit value to I2C device.
Parameters:
i2cData - Value to write to I2C device
Returns:
True if device returned Ack; False if Nak

read

public int read(int ackBit)
Read 8-bit value from I2C device.
Parameters:
ackBit - 0 to send Ack; 1 to send Nak after receipt of data
Returns:
Value from I2C device

stop

public void stop()
Send I2C Stop sequence.