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. |
SPIPermission |
The
SPIPermission class defines permissions for SPI slave device access. |
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 = 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 close the SPI slave device. The following sample code gives an example of using the SPI API to communicate with SPI slaves:slave.close();
Note that the preceding example is using a try-with-resources statement and that thetry (SPIDevice slave = PeripheralManager.open("SPI1", SPIDevice.class, null)) { ByteBuffer sndBuf1 = ByteBuffer.wrap(new byte[] {0x01}); ByteBuffer sndBuf2 = ByteBuffer.wrap(new byte[] {0x02}); ByteBuffer rcvBuf = ByteBuffer.wrap(new byte[3]); slave.writeAndRead(sndBuf1, rcvBuf); //received data will be stored in rcvBuf[0] slave.writeAndRead(sndBuf2, rcvBuf); //received data will be stored in rcvBuf[1] and rcvBuf[2] } catch (IOException ioe) { // handle exception }
SPIDevice.close
method is automatically invoked by the
platform at the end of the statement.
Information about the SPI-bus specification can be found at http://www.freescale.com/files/microcontrollers/doc/ref_manual/M68HC11RM.pdf.
Unless otherwise noted, passing a null
argument to a constructor or method in any class
or interface in this package will cause a NullPointerException
to be thrown.Copyright © 2012, 2014, Oracle and/or its affiliates. All rights reserved.
Legal Notices