DAAPI B (b02)
- Java ME Embedded 3.3 Release

Package com.oracle.deviceaccess.i2cbus

Interfaces and classes for I2C (Inter-Integrated Circuit Bus) device access.

See: Description

Package com.oracle.deviceaccess.i2cbus Description

Interfaces and classes for I2C (Inter-Integrated Circuit Bus) device access.

The functionalities supported by this API are those of an I2C master.

In order to communicate with a specific slave device, an application should first open and obtain an I2CDevice instance for the I2C slave device the application wants to exchange data with, using its numerical ID, name, type (interface) and/or properties:

Using its ID
 I2CDevice slave = (I2CDevice) PeripheralManager.open(3);
 
Using its name and interface
 I2CDevice slave = (I2CDevice) PeripheralManager.open("ADC1", I2CDevice.class, null);
 
Once the peripheral opened, the application can exchange data with the I2C slave device using methods of the I2CDevice interface such as the write() method.
 slave.write(sndBuf, 0, 1);
 
When the data exchange is over, the application should call the Peripheral.close() method to release I2C slave device.
 slave.close();
 
The following samples code give 2 examples of using the I2C API to communicate with an I2C slave device:
 public static final String LED_SLAVE_NAME = "LED_CONTROLLER";
 public static final byte[] LED_STOP_COMMAND = null;
 public static final byte[] LED_OFF_COMMAND = null;
 public static final byte[] LED_ON_COMMAND = null;
 public static int LED_LOOP_COUNT = 10;
 public static long LED_BLINK_TIME = 1500;
 
 I2CDevice slave = null;
 try {
     slave = (I2CDevice) PeripheralManager.open(LED_SLAVE_NAME, I2CDevice.class, (String[]) null);
     // Clear all status of the 'LED' slave device
     slave.write(LED_STOP_COMMAND, 0, LED_STOP_COMMAND.length);
     slave.write(LED_OFF_COMMAND, 0, LED_OFF_COMMAND.length);
 
     for (int i = 0; i < LED_LOOP_COUNT; i++) {
         // turning 'LED' on and keeping it on for 1500ms
         slave.write(LED_ON_COMMAND, 0, LED_ON_COMMAND.length);
         try {
             Thread.sleep(LED_BLINK_TIME);
         } catch (InterruptedException ex) {
         }
 
         // turning 'LED' off keeping it off for 1500ms
         slave.write(LED_OFF_COMMAND, 0, LED_OFF_COMMAND.length);
         try {
             Thread.sleep(LED_BLINK_TIME);
         } catch (InterruptedException ex) {
         }
     }
 } catch (IOException ex) {
     // Handle exception
 } catch (PeripheralException ex) {
     // Handle exception
 } finally {
     if (slave != null) {
         try {
             slave.close();
         } catch (IOException ex) {
         }
     }
 }
 
Or,
 I2CDevice slave = null;
 try {
     slave = (I2CDevice) PeripheralManager.open("EEPROM", I2CDevice.class, (String[]) null);
     byte[] addr = new byte[]{/ * Somme address * /};
     byte[] data = new byte[4];
     try {
         slave.begin();
         slave.write(addr, 0, 2); // Writes the address
         int count = slave.read(data, 0, 1); // Read the data at that EEPROM address
     } finally {
         slave.end();
     }
 } finally {
     if (slave != null) {
         slave.close();
     }
 }
 

Information about the I2C-bus specification can be found at http://www.nxp.com/documents/user_manual/UM10204.pdf.

Security

I2C (slave) devices are opened by invoking one of the com.oracle.deviceaccess.PeripheralManager.open methods. The "com.oracle.deviceaccess.i2c" permission allows access to be granted to I2C (slave) devices as a whole.
DAAPI B (b02)
5-February-2013 04:40

Copyright (c) 2012, Oracle and/or its affiliates. All Rights Reserved. Use of this specification is subject to license terms.