Device I/O API 1.1

Package jdk.dio.spibus

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

See: Description

Package jdk.dio.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 numeric ID, name, type (interface) and/or properties:

Using its ID
 SPIDevice slave = (SPIDevice);
Using its name and interface
 SPIDevice slave ="RTC1", SPIDevice.class, null);

Once the device 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 Device.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:

 try (SPIDevice slave ="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

The preceding example is using a try-with-resources statement; the 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

Unless otherwise noted, permission and security checks that may cause a SecurityException to be thrown must be performed in priority to any other checks or operations once performed the checking of the input parameters from which the permission target names and action lists are retrieved and assembled.

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.

Device I/O API 1.1