Package com.diozero.api
Class SpiDevice
java.lang.Object
com.diozero.api.SpiDevice
- All Implemented Interfaces:
SPIConstants
,java.io.Closeable
,java.lang.AutoCloseable
public class SpiDevice extends java.lang.Object implements java.io.Closeable, SPIConstants
https://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md
For modern Raspberry Pis:
2 SPI controllers, 0 (SPI-0) and 1 (SPI-1)
Controller 0 has 2 channels (CE-0 on physical pin 24, CE-1 on physical pin 26)
Controller 1 has 3 channels (CE-0 on physical pin 12, CE-1 on physical pin 11, CE-2 on physical pin 36)
SPI-1 is more limited that SPI-0 on the Raspberry Pi (https://www.raspberrypi.org/forums/viewtopic.php?t=81903&p=579154)
- The SPI-1 clock is derived from the system clock therefore you have to be careful when over/underclocking to set the right divisor
- Limited IRQ support, no thresholding on the FIFO except "TX empty" or "done".
- No DMA support (no peripheral DREQ)
On a RPi 3 you have to change the GPU core frequency to 250 MHz, otherwise the SPI clock has the wrong frequency.
Do this by adding the following line to /boot/config.txt and reboot.
core_freq=250
-
Field Summary
Fields inherited from interface com.diozero.api.SPIConstants
CE0, CE1, CE2, CE3, DEFAULT_LSB_FIRST, DEFAULT_SPI_CLOCK_FREQUENCY, DEFAULT_SPI_CLOCK_MODE, DEFAULT_SPI_CONTROLLER, DEFAULT_WORD_LENGTH
-
Constructor Summary
Constructors Constructor Description SpiDevice(int chipSelect)
SpiDevice(int controller, int chipSelect)
SpiDevice(int controller, int chipSelect, int frequency, SpiClockMode mode, boolean lsbFirst)
-
Method Summary
Modifier and Type Method Description void
close()
int
getChipSelect()
int
getController()
void
write(byte[] txBuffer)
void
write(byte[] txBuffer, int txOffset, int length)
byte[]
writeAndRead(byte[] out)
-
Constructor Details
-
SpiDevice
- Throws:
RuntimeIOException
-
SpiDevice
- Throws:
RuntimeIOException
-
SpiDevice
public SpiDevice(int controller, int chipSelect, int frequency, SpiClockMode mode, boolean lsbFirst) throws RuntimeIOException- Throws:
RuntimeIOException
-
-
Method Details
-
close
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
RuntimeIOException
-
getController
public int getController() -
getChipSelect
public int getChipSelect() -
write
- Throws:
RuntimeIOException
-
write
- Throws:
RuntimeIOException
-
writeAndRead
- Throws:
RuntimeIOException
-