Package com.motorola.oem.i2c

I2C (Inter Integrated Circuit) API.

See:
          Description

Interface Summary
I2CDatagramConnection This interface defines an I2C serial datagram connection.
 

Class Summary
I2CDatagram Holder of data to be sent or received from I2CdatagramConnection.
 

Package com.motorola.oem.i2c Description

 I2C (Inter Integrated Circuit) API.
 Provides standard GCF (Generic Connection Framework) API to communicate with I2C driven peripherals. 
 I2C API is defined according to I2C BUS SPECIFICATION  version 2.1, which is located at 
I2C-BUS SPECIFICATION

Basic Concept

The proposed I2C-bus connection consists of two main parts:
  • I2CDatagramConnection
  • I2CDatagram
  • The I2CDatagramConnection is the top level manager of the device's I2C bus. Applications use Connector.open() to create a new I2C-bus connection.

    The I2CDatagram encapsulates data and header. Application can obtain a new I2CDatagram by calling newDatagram() from an I2CdatagramConnection object. Once I2CDatagram has been created, application will be able to send and receive data using I2CDatagramConnection relevant methods.

    I2C API concept illustration



    Note:
    See device's USER GUIDE to understand I2C supported configuration.

    General Scenario

      The Following paragraph details a general procedure of using the I2C-bus.

      • Open I2CDatagram connection by calling Connector.open(...).
      • Create a new datagram.
      • Set address (in case address wasn't initialized by the new datagram).
      • Configure the datagram header (to a different configuration than the initial values).
      • Set a datagram data buffer.
      • Send/receive the datagram.

    Example:

    Common open and output operation.

    
           // open I2C in single master mode - 
           I2CDatagramConnection I2CBusOne = (I2CDatagramConnection)Connector.open("i2c://BUS1:"); 
           byte[] buf = new String("data_to_eeprom").getBytes(); // create data to send to slave 
           I2CDatagram eepromDatagram = (I2CDatagram)I2CBusOne.newDatagram(buf,buf.length,"i2c://0x22:0x56");
           I2CBusOne.send(eepromDatagram);
    
             

    Update a data buffer and send it to remote device.

    
    
    
           buf = new String("new_data_to_eeprom").getBytes(); // create more data to send 
           eepromDatagram.setData(buf);
           eepromDatagram.setAddress("i2c://0x22:0x78"); // change the register memory location to write to
           I2CBusOne.send(eepromDatagram);
    
               

    Create a new datagram and send it to another remote device..

    
    
           buf = new String("data to sensor").getBytes(); // create data to send to other slave
           I2CDatagram sensorDatagram = (I2CDatagram)I2CBusOne.newDatagram(buf,buf.length,"i2c://0x33:0x56");
           I2CBusOne.send(sensorDatagram);
    
                   

    Create a new datagram and receive data from remote device.

    
           //request to receive data from remote device
           buf = new byte[64]; //Init the buffer for receiving new data
           eepromDatagram = (I2CDatagram)I2CBusOne.newDatagram(buf,buf.length,"i2c://0x33:0x56");
           I2CBusOne.receive(eepromDatagram);
    
                        

    Close bus.

    
           I2CBusOne.close();