Difference between revisions of "Unit SPI"

From Ultibo.org
Jump to: navigation, search
Line 42: Line 42:
 
! '''Note'''
 
! '''Note'''
 
| Called only during system startup
 
| Called only during system startup
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
 +
'''SPI functions'''
 +
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SPIDeviceStart(SPI:PSPIDevice; Mode,ClockRate,ClockPhase,ClockPolarity:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Start the specified SPI device ready for writing and reading</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! '''SPI'''
 +
| The SPI device to start
 +
|-
 +
! '''Mode'''
 +
| The device mode to set (eg SPI_MODE_4WIRE)
 +
|-
 +
! '''ClockRate'''
 +
| The clock rate to set for the device
 +
|-
 +
! '''ClockPhase'''
 +
| The clock phase to set (eg SPI_CLOCK_PHASE_LOW)
 +
|-
 +
! '''ClockPolarity'''
 +
| The clock polarity to set (eg SPI_CLOCK_POLARITY_LOW)
 +
|-
 +
! '''Return'''
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SPIDeviceStop(SPI:PSPIDevice):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Stop the specified SPI device and terminate writing and reading</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! '''SPI'''
 +
| The SPI device to stop
 +
|-
 +
! '''Return'''
 +
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
 
|}
 
|}

Revision as of 04:50, 2 September 2016

Return to Unit Reference


Description


SPI (Serial Peripheral Interface) is a synchronous serial bus for communication with peripheral components.

The SPI protocol is not defined by any actual standard but some psuedo standards exist with all of the available devices. SPI is a master-slave protocol where the master asserts the chip selectline (CS) to select the slave device before sending data one byte at a time. For every byte written to the bus by the master the selected slave returns a byte as well so for every write there is an equivalent read. SPI can also operate in either 4 wire (standard) or 3 wire(bidirectional) modes.

Due to the lack of formal standards and the range of devices that exist various options are provided to allow setting clock phase and polarity as well chip select polarity.

For the purpose of this interface a device is the SPI controller attached to the local system and may be either a master or a slave. Since the protocol does not include any form of enumeration or identification the interface does not attempt to represent the devices connected to the bus, any driver written to communicate with a connected SPI device should know (or allow configuration of) the chip select for the for the device and the specific message format required for that device.

Constants


To be documented

Type definitions


To be documented

Public variables


To be documented

Function declarations



Initialization functions

procedure SPIInit;
Description: Initialize the SPI unit and SPI device table
Note Called only during system startup


SPI functions

function SPIDeviceStart(SPI:PSPIDevice; Mode,ClockRate,ClockPhase,ClockPolarity:LongWord):LongWord;
Description: Start the specified SPI device ready for writing and reading
SPI The SPI device to start
Mode The device mode to set (eg SPI_MODE_4WIRE)
ClockRate The clock rate to set for the device
ClockPhase The clock phase to set (eg SPI_CLOCK_PHASE_LOW)
ClockPolarity The clock polarity to set (eg SPI_CLOCK_POLARITY_LOW)
Return ERROR_SUCCESS if completed or another error code on failure


function SPIDeviceStop(SPI:PSPIDevice):LongWord;
Description: Stop the specified SPI device and terminate writing and reading
SPI The SPI device to stop
Return ERROR_SUCCESS if completed or another error code on failure


Return to Unit Reference