mraa  1.8.0
Low Level Skeleton Library for Communication on GNU/Linux platforms
Public Member Functions | List of all members
Spi Class Reference

Detailed Description

This file defines the SPI interface for libmraa

Spi spi = new Spi(0);
System.out.println("Hello, SPI initialised");
byte data[] = {0x00, 100};
for (int cnt = 100; cnt > 0; --cnt) {
for (int i = 90; i < 130; i++) {
data[1] = (byte) i;
byte[] recv = spi.write(data);
System.out.println(String.format("Writing - %d", i));
System.out.println(String.format("Received - %d - %d", recv[0], recv[1]));
Thread.sleep(100);
}
for (int i = 130; i > 90; i--) {
data[1] = (byte) i;
byte[] recv = spi.write(data);
System.out.println(String.format("Writing - %d", i));
System.out.println(String.format("Received - %d - %d", recv[0], recv[1]));
Thread.sleep(100);
}
}

Public Member Functions

synchronized void delete ()
 
 Spi (int bus)
 
 Spi (int bus, int cs)
 
Result mode (Spi_Mode mode)
 
Result frequency (int hz)
 
int writeByte (short data)
 
int writeWord (int data)
 
byte[] write (byte[] txBuf)
 
Result lsbmode (boolean lsb)
 
Result bitPerWord (long bits)
 

Constructor & Destructor Documentation

Spi ( int  bus)

Initialise SPI object using the board mapping to set muxes

Parameters
busto use, as listed in the platform definition, normally 0
Spi ( int  bus,
int  cs 
)

Initialise SPI object using 'raw' mode. Mraa will go and grab the spidev device lablled /dev/spidev[bus].[cs]

Parameters
busto use
csto use

Member Function Documentation

Result bitPerWord ( long  bits)

Set bits per mode on transaction, default is 8

Parameters
bitsbits per word
Returns
Result of operation
Result frequency ( int  hz)

Set the SPI device operating clock frequency

Parameters
hzthe frequency to set in hz
Returns
Result of operation
Result lsbmode ( boolean  lsb)

Change the SPI lsb mode

Parameters
lsbUse least significant bit transmission - 0 for msbi
Returns
Result of operation
Result mode ( Spi_Mode  mode)

Set the SPI device mode. see spidev0-3

Parameters
modethe mode. See Linux spidev doc
Returns
Result of operation
int writeByte ( short  data)

Write single byte to the SPI device

Parameters
datathe byte to send
Returns
data received on the miso line or -1 in case of error
int writeWord ( int  data)

Write single byte to the SPI device

Parameters
datathe byte to send
Returns
data received on the miso line or -1 in case of error

The documentation for this class was generated from the following file: