RoboJDETM v2.0

com.ridgesoft.io
Interface I2CMaster


public interface I2CMaster

Interface to a class that provides master control of an I2C bus.


Method Summary
 void setFrequency(int frequency)
          Sets the frequency of the I2C bus clock.
 void transfer(int deviceAddress, byte[] writeBuffer, byte[] readBuffer)
          Transfer data between the master and a slave device at the specified address.
 

Method Detail

setFrequency

void setFrequency(int frequency)
                  throws IOException
Sets the frequency of the I2C bus clock.

The allowable frequencies are determined by the underlying hardware.

The standard frequencies are 100 kHz (100000) and 400 kHz (400000); however, mostI2C devices will work at a large range of frequencies.

Typically the I2C bus fequency should only set once, during system initialization.

The default frequency is 100 kHz.

Parameters:
frequency - frequency of the I2C clock (SCL) in Hertz.
Throws:
IOException

transfer

void transfer(int deviceAddress,
              byte[] writeBuffer,
              byte[] readBuffer)
              throws IOException
Transfer data between the master and a slave device at the specified address.

This method may be used to write-only, read-only or write-then-read. Each of these operations is performed as a single transaction on the I2C bus. The write-then-read operation issues a repeated-start command between the write and the read. The calling thread will block until the entire transfer is complete or fails.

Implementing classes must synchronize access to ensure only one thread can have a transfer pending at a time.

Users of this method do not need to be concerned about synchronizing threads; that is the responsibility of the class implementing this interface.

Parameters:
deviceAddress - I2C address of the slave device.
  • Bits 1-7 are the 7 bit address transferred on the I2C bus.
  • All other bits are ignored, including bit 0, the read/write bit.
writeBuffer - A buffer of bytes to be written to the slave device.
  • The master transfers all the bytes in the buffer.
  • If null, the write operation is omitted from the transfer.
readBuffer - A buffer to receive bytes from a slave device.
  • The master reads from the slave device until the buffer is filled.
  • If null, the read operation is omitted from the transfer.
Throws:
IOException

RoboJDETM v2.0

Copyright (c) 2003-2009 RidgeSoft, LLC. All rights reserved.
www.ridgesoft.com