DAAPI B (b02)
- Java ME Embedded 3.3 Release

Package com.oracle.deviceaccess.spibus

Interfaces and classes for SPI (Serial Peripheral Interface Bus) device access.

See: Description

Package com.oracle.deviceaccess.spibus Description

Interfaces and classes for SPI (Serial Peripheral Interface Bus) device access.

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

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

Using its ID
 SPIDevice slave = (SPIDevice) PeripheralManager.open(3);
 
Using its name and interface
 SPIDevice slave = (SPIDevice) PeripheralManager.open("RTC1", SPIDevice.class, null);
 
Once the peripheral opened, the application can exchange data with the SPI slave device using methods of the SPIDevice interface such as the writeAndRead() method.
 slave.writeAndRead(sndBuf, 0, 1, rcvBuf, 0, 1);
 
When the data exchange is over, the application should call the Peripheral.close() method to release SPI slave device.
 slave.close();
 
The following sample code gives an example of using the SPI API to communicate with SPI slaves:
 SPIDevice slave = null;
 try {
     slave = (SPIDevice) PeripheralManager.open("SPI1", SPIDevice.class, (String[]) null);
     byte[] sndBuf1 = { 0x01 };
     byte[] sndBuf2 = { 0x02 };
     byte[] rcvBuf = new byte[3];
     slave.writeAndRead(sndBuf1, 0, sndBuf1.length, rcvBuf, 0, 1); // received data will be stored in rcvBuf[0]
     slave.writeAndRead(sndBuf2, 0, sndBuf2.length, rcvBuf, 1, 2); // received data will be stored in rcvBuf[1] and
     // rcvBuf[2]
 } catch (PeripheralException pe) {
     // Handle exception
 } catch (IOException ioe) {
     // Handle exception
 } finally {
     if (slave != null) {
         try {
             slave.close();
         } catch (IOException ex) {
         }
     }
 }
 

Information about the SPI-bus specification can be found at http://www.freescale.com/files/microcontrollers/doc/ref_manual/M68HC11RM.pdf.

Security

SPI (slave) devices are opened by invoking one of the com.oracle.deviceaccess.PeripheralManager.open methods. The "com.oracle.deviceaccess.spi" permission allows access to be granted to SPI (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.