Main Content

Using Properties on the SPI Object

Use the properties function on the spi object to see the available properties. In the preceding example, the syntax would be:

properties(S)

The following shows the output of the properties from the preceding example, Transmitting Data over the SPI Interface.

>> properties(S)

Properties for class instrument.interface.spi.aardvark.Spi:

    BitRate
    ClockPhase
    ClockPolarity
    ChipSelect
    Port
    BoardIndex
    VendorName
    BoardSerial
    ConnectionStatus
    TransferStatus

You can use these interface-specific properties with the spi object.

PropertyDescription
BitRateSPI clock speed. Must be a positive, nonzero value specified in Hz. The default is 1000000 Hz for both the Aardvark and NI-845x adaptors. To change from the default:

S.BitRate = 400000

ClockPhaseSPI clock phase. Can be specified as 'FirstEdge' or 'SecondEdge'. The default of 'FirstEdge' is used if you do not specify a phase.

ClockPhase indicates when the data is sampled. If set to 'FirstEdge', the first edge of the clock is used to sample the first data byte. The first edge may be the rising edge (if ClockPolarity is set to 'IdleLow'), or the falling edge (if ClockPolarity is set to 'IdleHigh'). If set to 'SecondEdge', the second edge of the clock is used to sample the first data byte. The second edge may be the falling edge (if ClockPolarity is set to 'IdleLow'), or the rising edge (if ClockPolarity is set to 'IdleHigh').

To change from the default:

S.ClockPhase = 'SecondEdge'

ClockPolaritySPI clock polarity. Can be specified as 'IdleLow' or 'IdleHigh'. The default of 'IdleLow' is used if you do not specify a phase.

ClockPolarity indicates the level of the clock signal when idle. 'IdleLow' means the clock idle state is low, and 'IdleHigh' means the clock idle state is high.

To change from the default:

S.Polarity = 'IdleHigh'

ChipSelectSPI chip select line. The Aardvark adaptor uses 0 as the chip select line since it has only one line, so that is the default and only valid value.
PortUse to create spi object. Port number of your hardware, specified as the number 0. The Aardvark adaptor uses 0 as the port number when there is one adaptor board connected. If there are multiple boards connected, they could use ports 0 and 1. Specify port number as the third argument when you create the spi object:

S = spi('aardvark', 0, 0);

BoardSerialUnique identifier of the SPI communication device.
VendorNameUse to create spi object. Adaptor board vendor, must be set to 'aardvark', for use with Total Phase Aardvark adaptor or 'ni845x' for use with the NI-845x adaptor. Specify the vendor as the first argument when you create the spi object:

S = spi('aardvark', 0, 0);

BoardIndexUse to create spi object. Specifies the board index of the hardware. Usually set to 0. Specify board index as the second argument when you create the spi object:

S = spi('aardvark', 0, 0);

ConnectionStatusReturns the connection status of the SPI object. Possible values are Disconnected (default) and Connected.
TransferStatusReturns the read/write operation status of the SPI object. Possible values:

Idle (default) – The device is not transferring any data.

Read – The device is reading data.

Write – The device is writing data.

ReadWrite – The device is reading and writing data.

The properties all have defaults, as indicated in the table. You do not need to set a property unless you want to change it to a different value from the default. Aside from the three properties required to construct the object – VendorName, BoardIndex, and Port – any other property is set using the .dot notation syntax:

<object_name>.<property_name> = <value>

Here are a few examples of using this syntax.

Change the BitRate from the default of 1000000 to 500000 kHz

S.BitRate = 500000

Change the ClockPhase from the default of 'FirstEdge' to 'SecondEdge'

S.ClockPhase = 'SecondEdge' 

where S is the name of the object used in the examples.

Note

To get a list of options you can use on a function, press the Tab key after entering a function on the MATLAB® command line. The list expands, and you can scroll to choose a property or value. For information about using this advanced tab completion feature, see Using Tab Completion for Functions.