3.9 SPI

3.9.1 @octave_spi/fclose

Function File: res = fclose (obj)

Closes SPI connection obj

3.9.2 @octave_spi/fopen

Function File: res = fopen (obj) (dummy)

Opens SPI connection obj

This currently is a dummy function to improve compatibility to MATLAB

3.9.3 @octave_spi/fread

Function File: data = fread (obj)
Function File: data = fread (obj, size)
Function File: data = fread (obj, size, precision)
Function File: [data,count] = fread (obj, ...)
Function File: [data,count,errmsg] = fread (obj, ...)

Reads data from a SPI instrument

Inputs

obj is a SPI object.
size Number of values to read. (Default: 10).
precision precision of data.

Outputs

data data values.
count number of values read.
errmsg read operation error message.

3.9.4 @octave_spi/fwrite

Function File: numbytes = fwrite (obj, data)
Function File: numbytes = fwrite (obj, data, precision)

Writes data to SPI instrument

Inputs

obj is a SPI object.
data data to write.
precision precision of data.

Outputs

returns number of bytes written.

3.9.5 @octave_spi/get

Function File: struct = get (spi)
Function File: field = get (spi, property)

Get the properties of spi object.

Inputs

spi - instance of octave_spi class.

property - name of property.

Properties

’name’

Name for the spi socket.

’bitrate’

The bitrate for the spi object.

’clockpolarity’

The clock polarity for the spi object of ’idlehigh’ or ’idlelow’.

’clockphase’

The clock phase for the spi object of ’firstedge’ or ’secondedge’.

’port’

The device port name.

’status’

The device status of ’open’ or ’closed’

Outputs

When property was specified, return the value of that property.
otherwise return the values of all properties as a structure.

See also: @octave_spi/set.

3.9.6 @octave_spi/read

Function File: data = read (obj)
Function File: data = read (obj, size)

Reads data from SPI instrument

Inputs

obj is a SPI object.
size Number of values to read. (Default: 10).

Outputs

data data values.

3.9.7 @octave_spi/set

Function File: set (obj, property,value)
Function File: set (obj, property,value,…)

Set the properties of spi object.

Inputs

obj - instance of octave_spi class.
property - name of property.

If property is a cell so must be value, it sets the values of all matching properties.

The function also accepts property-value pairs.

Properties

’name’

Set the name for the spi socket.

’bitrate’

Set the bitrate for the spi object.

’clockpolarity’

Set the clock polarity for the spi object of ’idlehigh’ or ’idlelow’.

’clockphase’

Set the clock phase for the spi object of ’firstedge’ or ’secondedge’.

Outputs

None

See also: @octave_spi/get.

3.9.8 @octave_spi/write

Function File: numbytes = fwrite (obj, data)

Writes data to SPI instrument

Inputs

obj is a SPI object.
data data to write.

Outputs

returns number of bytes written.

3.9.9 @octave_spi/writeAndRead

Function File: data = writeAndRead (obj, wrdata)

Writes and reads data from SPI instrument

Inputs

obj is a SPI object.
wrdata Data to write.

Outputs

data data values read.

3.9.10 spi

Loadable Function: spi = spi ([port_path])
Loadable Function: spi = spi ([port_path], [propname, propvalue])

Open a spi interface.

Inputs

port_path - the interface device port/path of type String. If omitted defaults to ’/dev/spi-0’.
propname,propvalue - property name/value pairs.

Known input properties:

name

Name of the object

bitrate

Numeric bitrate value

clockpolarity

Clock polarity: idlehigh or idlelow.

clockphase

Clock phase value: firstedge or secondedge

Outputs

spi - An instance of octave_spi class.

Properties

The spi object has the following properties:

name

Name of the object

status

Open or closed status of object (readonly).

bitrate

Numeric bitrate value

clockpolarity

Clock polarity: idlehigh or idlelow.

clockphase

Clock phase value: firstedge or secondedge

port

The interface driver port (readonly)

3.9.11 spi_close

Loadable Function: spi_close (spi)

Close the interface and release a file descriptor.

Inputs

spi - instance of octave_spi class.

Outputs

None

3.9.12 spi_read

Loadable Function: [data, count] = spi_read (spi, n)

Read from spi slave device.

Inputs

spi - instance of octave_spi class.
n - number of bytes to attempt to read of type Integer.

Outputs

The spi_read() shall return number of bytes successfully read in count as Integer and the bytes themselves in data as uint8 array.

3.9.13 spi_write

Loadable Function: n = spi_write (spi, data)

Write data to a spi slave device.

Inputs

spi - instance of octave_spi class.
data - data, of type uint8, to be written to the slave device.

Outputs

Upon successful completion, spi_write() shall return the number of bytes written as the result n.

3.9.14 spi_writeAndRead

Loadable Function: rddata = spi_writeAndRead (spi, wrdata)

Write data to a spi slave device and then read same number of values.

Inputs

spi - instance of octave_spi class.
wrdata - data, of type uint8, to be written to the slave device.

Outputs

Upon successful completion, spi_writeAndRead() shall return the bytes read.