oSPI Object
An Object that provides SPI serial input and output.
Description:
 

An Object that provides SPI serial input and output.

Operation:
 The oSPI Object uses the I/O line specified by the IOLineO property to send and the IOLineI property to receive an 8-Bit serial data transmission at the rate specified by the Rate property.

When a value is written to the oSPI Object's Value property, the oSPI Object will clock out SPI data.

When the value property is read, the oSPI will clock in SPI data.

An optional Enable line is provided that is activated when the SPI data is clocked in or out.  This line is deactivated when the data transfer is complete.

Storage size & Availability:
 

The following table lists the size and availability of the oSPI Object and its variations

ObjectSizeVersion
oSPI6 BytesB.2.0
Properties:
 

The following table lists the Properties of the oSPI Object

PropertyDescription
Address

Returns a pointer to the address of the oSPI Object instance.

Data-Type: Address, Read-Only

Data-Range: 0 - 127

Direction

A value that specifies the direction of the bit order.

Data-Type: Bit, Flag

Data-Range: 0 - 1

The following table lists the possible values of Direction

DirectionConstantDescription
0 Data shifted out lsb first.
1 Data shifted out msb first.
InvertE

A value that specifies if the Enable output is inverted.

Data-Type: Bit, Flag

Data-Range: 0 - 1

IOLineC

A value that specifies the physical I/O Line to use for the Clock signal.

Data-Type: Byte

Data-Range: 0 - 31

IOLineE

A value that specifies the physical I/O Line to use for the Enable output.

Data-Type: Nibble

Data-Range: 0 - 15

IOLineI

A value that specifies the physical I/O Line to use for in-coming data

Note: if this is set to 0, then the oSPI Object will use the I/O Line that that IOLineO property is set to for the IOLineI value.

Data-Type: Byte

Data-Range: 0 - 31

IOLineO

A value that specifies the physical I/O Line to use for out-going data

Data-Type: Byte

Data-Range: 0 - 31

Mode

A value that specifies when the data is to be read.

Data-Type: Bit

Data-Range: 0 - 1

The following table lists the possible values of Mode.

DirectionConstantDescription
0 Data is samples before clock pulse.
1 Data is samples after clock pulse.
Operate

A value that specifies whether or not the data is updated.

Data-Type: Bit, Flag

Data-Range: 0 - 1

Rate

A value that specifies the clock rate.

Data-Type: Bit

Data-Range: 0 - 1

Value

A value that indicates the current 16 or 8 bit SPI reading

Data-Type: Word, Default

Data-Range: 0 - 65535

Width

A value that specifies the width of the data.

Data-Type: Bit

Data-Range: 0 - 1

The following table lists the possible values of Width.

WidthConstantDescription
0 8-Bits of data are clocked in or out.
1 16-Bits of data are clocked in or out.
Example:
 In the following example, the oSPI Object is used to
'This program uses the oSPI Object to read an 
'Al Williams PAK-VII Pulse-In co-processor 
'An oServoX Object is used to provide The 
'PAK-VII with a pulse to measure and the 
'servo reading is displayed on a oLCDSE

Dim PAKVII As New oSPI
Dim LCD As New oLCDSE
Dim PulseLen As New oWord
Dim Pulse As New oServoX
Dim Tone As New oFreq
Dim Char As New oByte

Const Servo0 = &b10001000 'Channel 0 On PAK VII
Const Servo1 = &b10001001 'Channel 1 On PAK VII
Const Servo2 = &b10001010 'Channel 2 On PAK VII 
Const Servo3 = &b10001011 'Channel 3 On PAK VII 

'===============================================================================
Sub Main()
 Setup 
 Do
  Call ResetPAKVII
  PAKVII=Servo1
  ' Note that the 16 bit data is clocked in LSB first
  ' so two bytes are read and then assembled.
  PulseLen = PAKVII + (PAKVII * 256)
  LCD.Locate(1,1)
  LCD.String = Str$(PulseLen)
  Pulse=Pulse+2
 Loop
End Sub

'===============================================================================
Sub Setup()

  Pulse.ioline = 17 
  Pulse.operate = 1
  Pulse = -64

  PAKVII.IOLineC = 14
  PAKVII.IOLineO = 13
  PAKVII.IOLineI = 13
  PAKVII.width = cv8bit
  PAKVII.direction = cvMSBFirst

  Tone.Beep(5000,100) ' Give the LCD time to power up
  LCD.IOLine = 16
  LCD.Clear
  LCD.String = "Setup Complete"
  Tone.Beep(64000,50)
  LCD.Clear
  LCD.String = "Servo Reading:"

End Sub

'===============================================================================
Sub ResetPAKVII() 
  PAKVII.IOLineC.Low
  PAKVII.IOLineO.Low
  PAKVII.IOLineC.High
  PAKVII.IOLineO.High
  PAKVII.IOLineC.Low
  PAKVII.IOLineO.Low
  Tone.Beep(15000,15) ' Give the PAK time to reset
End Sub
                          
See Also:
 

oSerialX - A Hardware Object that sends and receives serial transmissions on any pin.