SunSPOT API V5.0


com.sun.spot.peripheral
Interface II2C

All Known Implementing Classes:
AT91_I2C, ATmega_I2C

public interface II2C

Interface for communicating with devices using the I2C protocol.

Author:
Ron Goldman

Method Summary
 void close()
          Release any resources associated with the I2C hardware.
 boolean isBusy()
          Check if an I2C data transfer is currently in process.
 void open()
          Initialize the I2C hardware.
 boolean probe(int slaveAddress, int probeData)
          Check if a slave device is present at the given address.
 void read(int slaveAddress, byte[] data, int off, int len)
          Read data from the specified I2C slave device.
 void read(int slaveAddress, int internalAddress, int internalAddressSize, byte[] data, int off, int len)
          Read data from the specified I2C slave device.
 void setClockSpeed(int clockSpeed)
          Set the clock speed to use for I2C data transfers.
 void write(int slaveAddress, byte[] data, int off, int len)
          Write data to the specified I2C slave device.
 void write(int slaveAddress, int internalAddress, int internalAddressSize, byte[] data, int off, int len)
          Write data to the specified I2C slave device.
 

Method Detail

open

void open()
          throws IOException
Initialize the I2C hardware.

Throws:
IOException

close

void close()
           throws IOException
Release any resources associated with the I2C hardware.

Throws:
IOException

setClockSpeed

void setClockSpeed(int clockSpeed)
Set the clock speed to use for I2C data transfers.

Parameters:
clockSpeed - I2C bus clock in Hertz

write

void write(int slaveAddress,
           byte[] data,
           int off,
           int len)
           throws IOException
Write data to the specified I2C slave device.

Parameters:
slaveAddress - 7-bit slave address, shifted left one bit so LSB is not used
data - Array of bytes to write
off - Offset from which to start writing data
len - How many bytes of data to write. Note: some implementations may limit the number of bytes that can be written in a single call, e.g. the eDemo board firmware has a fixed buffer that can only hold 40 bytes.
Throws:
IOException

write

void write(int slaveAddress,
           int internalAddress,
           int internalAddressSize,
           byte[] data,
           int off,
           int len)
           throws IOException
Write data to the specified I2C slave device.

Parameters:
slaveAddress - 7-bit slave address, shifted left one bit so LSB is not used
internalAddress - 0-4 bytes of internal address information sent to the slave device before any data; Note: some implementations may not support sending a full 4 bytes of data, e.g. the ARM9 can only send 0-3 bytes
internalAddressSize - how many bytes of internal address information are to be sent
data - Array of bytes to write
off - Offset from which to start writing data
len - How many bytes of data to write. Note: some implementations may limit the number of bytes that can be written in a single call, e.g. the eDemo board firmware has a fixed buffer that can only hold 40 bytes.
Throws:
IOException

read

void read(int slaveAddress,
          byte[] data,
          int off,
          int len)
          throws IOException
Read data from the specified I2C slave device.

Parameters:
slaveAddress - 7-bit slave address, shifted left one bit so LSB is not used
data - Array of bytes to read into
off - Offset from which to start reading data
len - How many bytes of data to read. Note: some implementations may limit the number of bytes that can be written in a single call, e.g. the eDemo board firmware has a fixed buffer that can only hold 40 bytes.
Throws:
IOException

read

void read(int slaveAddress,
          int internalAddress,
          int internalAddressSize,
          byte[] data,
          int off,
          int len)
          throws IOException
Read data from the specified I2C slave device.

Parameters:
slaveAddress - 7-bit slave address, shifted left one bit so LSB is not used
internalAddress - 0-4 bytes of internal address information sent to the slave device before any data; Note: some implementations may not support sending a full 4 bytes of data, e.g. the ARM9 can only send 0-3 bytes
internalAddressSize - how many bytes of internal address information are to be sent
data - Array of bytes to read into
off - Offset from which to start reading data
len - How many bytes of data to read. Note: some implementations may limit the number of bytes that can be written in a single call, e.g. the eDemo board firmware has a fixed buffer that can only hold 40 bytes.
Throws:
IOException

isBusy

boolean isBusy()
Check if an I2C data transfer is currently in process.

Returns:
true if a data transfer is currently in process

probe

boolean probe(int slaveAddress,
              int probeData)
Check if a slave device is present at the given address. Tries to write a byte to the device and sees if it gets a NACK.

Parameters:
slaveAddress - 7-bit slave address, shifted left one bit so LSB is not used
probeData - - byte value to try writing to device
Returns:
false if no device is present

SunSPOT API V5.0


Copyright � 2006-2008 Sun Microsystems, Inc. All Rights Reserved.