DolphinV4 API  1.6.1.0
SPI functions
Collaboration diagram for SPI functions:

Functions

void spi_init (uint8 *pu8Param)
void spi_setCS (bit1 u1Val)
RETURN_TYPE spi_getSendBuffer (uint8 *u8SendBuff, uint8 *u8GetBuff, uint8 u8NoBytes, SPI_PACKETSIZE u8PacketSize, DPLX_MODES u8Dplx)

Detailed Description

The SPI module is used for communication between the DOLPHIN IC and a HOST using the SPI protocol. The SPI module supports communication where the DOLPHIN acts as SPI-Master and the HOST acts SPI-Slave.

The SPI module supports packet transmission. The size of one packet can be 1,2,3 or 4 bytes. The CS can't be modified during packet transmission. The maximum speed of one packet transmission is 2Mbit. Between two packets a certain processing delay is needed called interpacket delay. size of the interpacket delay depends on the following factors:

The interpacket delay + the packet transmission speed gives the real SPI communication speed. The following table shows the real SPI speed for different packet size @ 2MHz packet clock speed.
spispeed.PNG
SPI Tx speed @ 2MHz SPI clock and different packet size and duplex mode and worst case interrupt calculation


The initialization of the SPI module is done through Dolphin APIConfigurator. The generated settings are saved to the file EO3100I_CFG.h.

The SPI interfaces uses the following pins:



There are two possibilities how control CS (configured with spi_init with the parameters).

To manualy controll the CS the function spi_setCS is used. In automatic CS the CS raised and lowered between each packet automaticly.
spi_arch.PNG
SPI initialization between DOLPHIN and HOST
Note:
In order to determine the real SPI communication speed, be sure to measure the interpacket delay for data that is larger than 4 byte and also calculate with the duration of interrupts that can make the interpacket delay larger.
Be sure when using both SPI and UART module that the UART module is not configured for pins WSDADIO2, RSDADIO3.


Function Documentation

void spi_init ( uint8 *  pu8Param)

Initialises the SPI module.

Parameters:
[in]*pu8ParamPointer to parameter array
Returns:
-
Note:
To generate the parameters for spi_init use DolphinV4 API Configurator (set the GPIO to SPI in the DolphinV4 API Configurator).
See also:
spi_setCS, spi_getSendBuffer
void spi_setCS ( bit1  u1Val)

Sets the CS bit to the given value

Parameters:
[in]u1ValTRUE, the CS line will be HIGH, FALSE, the CS line will be LOW
Returns:
-

Example 1:
This function is for controlling the CS line in SPI interface

spi_init(spi_param);
spi_setCS(FALSE);
spi_getSendBuffer(u8SendBuff, u8NoSend, u8GetBuff, u8NoGet);
spi_setCS(TRUE);
See also:
spi_init, spi_getSendBuffer
RETURN_TYPE spi_getSendBuffer ( uint8 *  u8SendBuff,
uint8 *  u8GetBuff,
uint8  u8NoBytes,
SPI_PACKETSIZE  u8PacketSize,
DPLX_MODES  u8Dplx 
)

Sends and gets data to/from SPI interface.

Parameters:
[in]*pu8SendBuffPointer to character buffer to send, NULL if no characters to send
[out]*pu8GetBuffPointer to character buffer to receive, NULL if no characters to get
[in]u8NoBytesNumber of characters to send/receive, note that this value has to be aligned to u8PacketSize
[in]u8PacketSizeOne transmitted packet size which is transmitted at once (can be 1 - 4 bytes)
[in]u8DplxDuplex mode, full duplex, half duplex rx or half duplex tx can be selected
Returns:
INVALID_PARAM If the u8NoBytes is not aligned to u8PacketSize
OK If there was no problem with SPI

Example 1:
Make a full duplex SPI communication, send/receive 12 characters with manual CS and packet size 4

spi_init(spi_param);
spi_setCS(FALSE);
spi_getSendBuffer(u8SendBuffer, u8GetBuffer, 12, BYTE_4, FULL);
spi_setCS(TRUE);

Example 2:
Make a half duplex Tx SPI communication, send/receive 12 characters with auto CS and packet size 1

//the auto CS has to be configured in the spi_param with DolphinV4 API Configurator
spi_init(spi_param);
spi_getSendBuffer(u8SendBuffer, NULL, 12, BYTE_1, HALF_TX);
Note:
To generate the parameters for spi_init use DolphinV4 API Configurator (set the GPIO to SPI in the DolphinV4 API Configurator) and copy generated spi_param to EO3100I_CFG.h. Do not forget to copy io_param too.
You are responsable for resetting and setting CS pin in manual CS mode.
If using half duplex communication set puffer pointer not used to NULL.
Interrupts in the system (i.e. system tick) can cause a gap between the SPI bytes transmission. This gap can be in worst case around 1.3ms.
See also:
spi_init, spi_setCS