See: Description
| Interface | Description |
|---|---|
| SPIDevice |
The
SPIDevice interface provides methods for transmitting and receiving data to/from an SPI slave device. |
| Class | Description |
|---|---|
| SPIDeviceConfig |
The
SPIDeviceConfig class encapsulates the hardware addressing information, and static and dynamic
configuration parameters of an SPI slave device. |
| Exception | Description |
|---|---|
| InvalidWordLengthException |
Thrown by an instance of
SPIDevice in case of mismatch between the length of data to be exchanged and the
slave's word length as indicated by SPIDevice.getWordLength(). |
SPIDevice instance for the SPI slave device the application wants to exchange
data with, using its numerical ID, name, type (interface) and/or properties:
SPIDevice slave = (SPIDevice) PeripheralManager.open(3);
SPIDevice slave = (SPIDevice) PeripheralManager.open("RTC1", SPIDevice.class, null);
SPIDevice interface such as the
writeAndRead()
method. When the data exchange is over, the application should call theslave.writeAndRead(sndBuf, 0, 1, rcvBuf, 0, 1);
Peripheral.close() method to release SPI slave device. The following sample code gives an example of using the SPI API to communicate with SPI slaves:slave.close();
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.
com.oracle.deviceaccess.PeripheralManager.open methods. The "com.oracle.deviceaccess.spi" permission allows
access to be granted to SPI (slave) devices as a whole.Copyright (c) 1990, 2013, Oracle and/or its affiliates. All rights reserved.