Difference between revisions of "Unit SPI"
Line 201: | Line 201: | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <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 SPIDeviceRead(SPI:PSPIDevice; ChipSelect:Word; Dest:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;</pre> | <pre style="border: 0; padding-bottom:0px;">function SPIDeviceRead(SPI:PSPIDevice; ChipSelect:Word; Dest:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;</pre> | ||
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Read data | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Read data from the specified SPI device</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
! '''SPI''' | ! '''SPI''' | ||
− | | The SPI device to read | + | | The SPI device to read from |
|- | |- | ||
! '''ChipSelect''' | ! '''ChipSelect''' | ||
− | | The chip select for the slave to read | + | | The chip select for the slave to read from (eg SPI_CS_0) |
|- | |- | ||
! '''Dest''' | ! '''Dest''' | ||
Line 267: | Line 267: | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <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 SPIDeviceWriteRead(SPI:PSPIDevice; ChipSelect:Word; Source,Dest:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;</pre> | <pre style="border: 0; padding-bottom:0px;">function SPIDeviceWriteRead(SPI:PSPIDevice; ChipSelect:Word; Source,Dest:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;</pre> | ||
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Write data to and Read data | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Write data to and Read data from the specified SPI device in one operation</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
! '''SPI''' | ! '''SPI''' | ||
− | | The SPI device to write to and read | + | | The SPI device to write to and read from |
|- | |- | ||
! '''ChipSelect''' | ! '''ChipSelect''' | ||
− | | The chip select for the slave to write to and read | + | | The chip select for the slave to write to and read from (eg SPI_CS_0) |
|- | |- | ||
! '''Source''' | ! '''Source''' | ||
Line 308: | Line 308: | ||
|- | |- | ||
! '''SPI''' | ! '''SPI''' | ||
− | | The SPI device to get device mode | + | | The SPI device to get device mode from |
|- | |- | ||
! '''Return''' | ! '''Return''' | ||
Line 341: | Line 341: | ||
|- | |- | ||
! '''SPI''' | ! '''SPI''' | ||
− | | The SPI device to get clock rate | + | | The SPI device to get clock rate from |
|- | |- | ||
! '''ChipSelect''' | ! '''ChipSelect''' | ||
− | | The chip select number to get clock rate | + | | The chip select number to get clock rate from (SPI_CS_NONE for default) |
|- | |- | ||
! '''Return''' | ! '''Return''' | ||
Line 380: | Line 380: | ||
|- | |- | ||
! '''SPI''' | ! '''SPI''' | ||
− | | The SPI device to get clock phase | + | | The SPI device to get clock phase from |
|- | |- | ||
! '''Return''' | ! '''Return''' | ||
Line 413: | Line 413: | ||
|- | |- | ||
! '''SPI''' | ! '''SPI''' | ||
− | | The SPI device to get clock polarity | + | | The SPI device to get clock polarity from |
|- | |- | ||
! '''Return''' | ! '''Return''' | ||
Line 446: | Line 446: | ||
|- | |- | ||
! '''SPI''' | ! '''SPI''' | ||
− | | The SPI device to get chip select polarity | + | | The SPI device to get chip select polarity from |
|- | |- | ||
! '''ChipSelect''' | ! '''ChipSelect''' | ||
− | | The chip select number to get polarity | + | | The chip select number to get polarity from (SPI_CS_NONE for default) |
|- | |- | ||
! '''Return''' | ! '''Return''' | ||
Line 485: | Line 485: | ||
|- | |- | ||
! '''SPI''' | ! '''SPI''' | ||
− | | The SPI device to get properties | + | | The SPI device to get properties from |
|- | |- | ||
! '''Properties''' | ! '''Properties''' | ||
Line 549: | Line 549: | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <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 SPIDeviceDeregister(SPI:PSPIDevice):LongWord;</pre> | <pre style="border: 0; padding-bottom:0px;">function SPIDeviceDeregister(SPI:PSPIDevice):LongWord;</pre> | ||
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Deregister a SPI | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Deregister a SPI from the SPI table</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 672: | Line 672: | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <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 SysSPIRead(ChipSelect:Word; Dest:Pointer; Size:LongWord; var Count:LongWord):LongWord;</pre> | <pre style="border: 0; padding-bottom:0px;">function SysSPIRead(ChipSelect:Word; Dest:Pointer; Size:LongWord; var Count:LongWord):LongWord;</pre> | ||
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Read data | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Read data from the default SPI device</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
! '''ChipSet''' | ! '''ChipSet''' | ||
− | | The chip select for the slave to read | + | | The chip select for the slave to read from (eg SPI_CS_0) |
|- | |- | ||
! '''Dest''' | ! '''Dest''' | ||
Line 726: | Line 726: | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <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 SysSPIWriteRead(ChipSelect:Word; Source,Dest:Pointer; Size:LongWord; var Count:LongWord):LongWord;</pre> | <pre style="border: 0; padding-bottom:0px;">function SysSPIWriteRead(ChipSelect:Word; Source,Dest:Pointer; Size:LongWord; var Count:LongWord):LongWord;</pre> | ||
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Write data to and Read data | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Write data to and Read data from the default SPI device in one operation</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
! '''ChipSet''' | ! '''ChipSet''' | ||
− | | The chip select for the slave to write to and read | + | | The chip select for the slave to write to and read from (eg SPI_CS_0) |
|- | |- | ||
! '''Source''' | ! '''Source''' | ||
Line 788: | Line 788: | ||
|- | |- | ||
! '''ChipSelect''' | ! '''ChipSelect''' | ||
− | | The chip select number to get clock rate | + | | The chip select number to get clock rate from (SPI_CS_NONE for default) |
|- | |- | ||
! '''Return''' | ! '''Return''' | ||
Line 875: | Line 875: | ||
|- | |- | ||
! '''ChipSet''' | ! '''ChipSet''' | ||
− | | The chip select number to get polarity | + | | The chip select number to get polarity from (SPI_CS_NONE for default) |
|- | |- | ||
! '''Return''' | ! '''Return''' |
Revision as of 04:26, 30 November 2016
Return to Unit Reference
Contents
[hide]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
SPI_*
SPI_TYPE_*
SPI_STATE_*
SPI_FLAG_*
SPI_TRANSFER_*
SPI_LOG_*
Type definitions
To be documented
Public variables
To be documented
Function declarations
Initialization functions
SPI functions
function SPIDeviceStart(SPI:PSPIDevice; Mode,ClockRate,ClockPhase,ClockPolarity:LongWord):LongWord;
function SPIDeviceStop(SPI:PSPIDevice):LongWord;
function SPIDeviceRead(SPI:PSPIDevice; ChipSelect:Word; Dest:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
function SPIDeviceWrite(SPI:PSPIDevice; ChipSelect:Word; Source:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
function SPIDeviceWriteRead(SPI:PSPIDevice; ChipSelect:Word; Source,Dest:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
function SPIDeviceGetMode(SPI:PSPIDevice):LongWord;
function SPIDeviceSetMode(SPI:PSPIDevice; Mode:LongWord):LongWord;
function SPIDeviceGetClockRate(SPI:PSPIDevice; ChipSelect:Word):LongWord;
function SPIDeviceSetClockRate(SPI:PSPIDevice; ChipSelect:Word; ClockRate:LongWord):LongWord;
function SPIDeviceGetClockPhase(SPI:PSPIDevice):LongWord;
function SPIDeviceSetClockPhase(SPI:PSPIDevice; ClockPhase:LongWord):LongWord;
function SPIDeviceGetClockPolarity(SPI:PSPIDevice):LongWord;
function SPIDeviceSetClockPolarity(SPI:PSPIDevice; ClockPolarity:LongWord):LongWord;
function SPIDeviceGetSelectPolarity(SPI:PSPIDevice; ChipSelect:Word):LongWord;
function SPIDeviceSetSelectPolarity(SPI:PSPIDevice; ChipSelect:Word; SelectPolarity:LongWord):LongWord;
function SPIDeviceProperties(SPI:PSPIDevice; Properties:PSPIProperties):LongWord;
function SPIDeviceDestroy(SPI:PSPIDevice):LongWord;
function SPIDeviceRegister(SPI:PSPIDevice):LongWord;
function SPIDeviceDeregister(SPI:PSPIDevice):LongWord;
function SPIDeviceFindByName(const Name:String):PSPIDevice; inline;
function SPIDeviceFindByDescription(const Description:String):PSPIDevice; inline;
function SPIDeviceEnumerate(Callback:TSPIEnumerate; Data:Pointer):LongWord;
function SPIDeviceNotification(SPI:PSPIDevice; Callback:TSPINotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
RTL SPI functions
function SysSPIStart(Mode,ClockRate,ClockPhase,ClockPolarity:LongWord):LongWord;
function SysSPIStop:LongWord;
function SysSPIRead(ChipSelect:Word; Dest:Pointer; Size:LongWord; var Count:LongWord):LongWord;
function SysSPIWrite(ChipSelect:Word; Source:Pointer; Size:LongWord; var Count:LongWord):LongWord;
function SysSPIWriteRead(ChipSelect:Word; Source,Dest:Pointer; Size:LongWord; var Count:LongWord):LongWord;
function SysSPIGetMode:LongWord;
function SysSPISetMode(Mode:LongWord):LongWord;
function SysSPIGetClockRate(ChipSelect:Word):LongWord;
function SysSPISetClockRate(ChipSelect:Word; ClockRate:LongWord):LongWord;
function SysSPIGetClockPhase:LongWord;
function SysSPISetClockPhase(ClockPhase:LongWord):LongWord;
function SysSPIGetClockPolarity:LongWord;
function SysSPISetClockPolarity(ClockPolarity:LongWord):LongWord;
function SysSPIGetSelectPolarity(ChipSelect:Word):LongWord;
</div></div>
function SysSPISetSelectPolarity(ChipSelect:Word; SelectPolarity:LongWord):LongWord;
SPI helper functions
function SPIDeviceGetDefault:PSPIDevice; inline;
function SPIDeviceSetDefault(SPI:PSPIDevice):LongWord;
function SPIDeviceCheck(SPI:PSPIDevice):PSPIDevice;
procedure SPILog(Level:LongWord; SPI:PSPIDevice; const AText:String);
procedure SPILogInfo(SPI:PSPIDevice; const AText:String); inline;
procedure SPILogError(SPI:PSPIDevice; const AText:String); inline;
procedure SPILogDebug(SPI:PSPIDevice; const AText:String); inline;
function SPISelectPolarityToString(Polarity:LongWord):String;
Return to Unit Reference