SunSPOT API V5.0


com.sun.spot.sensorboard.io
Class ATmega_I2C

java.lang.Object
  extended by com.sun.spot.sensorboard.io.ATmega_I2C
All Implemented Interfaces:
II2C

public class ATmega_I2C
extends Object
implements II2C

Class for communicating with devices using the I2C protocol using the ATmega processor on the eDemo board. Uses the D2 and D3 pins for SDA and SCK of the TWI interface.

Author:
Ron Goldman

Constructor Summary
ATmega_I2C(EDemoController ctlr)
           
 
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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ATmega_I2C

public ATmega_I2C(EDemoController ctlr)
Method Detail

open

public void open()
          throws IOException
Initialize the I2C hardware.

Specified by:
open in interface II2C
Throws:
IOException

close

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

Specified by:
close in interface II2C
Throws:
IOException

setClockSpeed

public void setClockSpeed(int clockSpeed)
Set the clock speed to use for I2C data transfers. The initial clock speed is set to 100KHz.

Specified by:
setClockSpeed in interface II2C
Parameters:
clockSpeed - I2C bus clock in Hertz

write

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

Specified by:
write in interface II2C
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
Throws:
IOException - if no slave device responds.

write

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

Specified by:
write in interface II2C
Parameters:
slaveAddress - 7-bit slave address, shifted left one bit so LSB is not used
internalAddress - 0-3 bytes of internal address information sent to the slave device before any data.
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
Throws:
IOException - if no slave device responds.

read

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

Specified by:
read in interface II2C
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
Throws:
IOException - if no slave device responds.

read

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

Specified by:
read in interface II2C
Parameters:
slaveAddress - 7-bit slave address, shifted left one bit so LSB is not used
internalAddress - 0-3 bytes of internal address information sent to the slave device before any data
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
Throws:
IOException - if no slave device responds.

isBusy

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

Specified by:
isBusy in interface II2C
Returns:
true if a data transfer is currently in process

probe

public 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.

Specified by:
probe in interface II2C
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.