3.21 SPI Client Driver

Overview

The Serial Peripheral Interface (SPI) module is a synchronous serial interface useful for communicating with other peripheral or microcontroller devices. These peripheral devices can be serial EEPROMs, Shift registers, display drivers, Analog-to-Digital Converters and so on.

Features

  • Allows to setup multiple Client Configurations to interact with multiple hosts having different configurations. SPIx_Open and SPIx_Close are the APIs to be used for selecting/switching between different Client configurations at run time.
  • SPI Mode is configurable for each Client Configuration table entry.
  • User can provide Custom Name for each Client Configuration table entry.
  • Supports Enhanced Buffer mode with communication width of 8 bit only.
  • Currently, only polling mode is supported.

3.21.1 Module Documentation

3.21.1.1 SPI Client Driver

Serial Peripheral Interface (SPI) CLIENT Driver using dsPIC MCUs.

3.21.1.1.1 Module description

Serial Peripheral Interface (SPI) CLIENT Driver using dsPIC MCUs.

Data structures
Functions
  • void SPI1_Initialize (void)

    Initializes SPI1 module, using the given initialization data. This function must be called before any other SPI1 function is called.

  • void SPI1_Deinitialize (void)

    Deinitializes the SPI1 to POR values.

  • void SPI1_Close (void)

    Disables the SPI1 module.

  • bool SPI1_Open (uint8_t spiConfigIndex)

    Configures SPI1 module with user defined unique configuration.

  • uint8_t SPI1_ByteExchange (uint8_t byteData)

    Exchanges one byte of data. This is a blocking function.

  • void SPI1_ByteWrite (uint8_t byteData)

    Writes one byte of data.

  • uint8_t SPI1_ByteRead (void)

    Reads one byte of data from SPI1.

  • bool SPI1_IsRxReady (void)

    Returns a boolean value if data is available to read.

  • bool SPI1_IsTxReady (void)

    Returns a boolean value if data can be written.

Variables
  • const struct SPI_CLIENT_INTERFACE SPI1_Client

    Structure object of type SPI_CLIENT_INTERFACE assigned with name displayed in the Melody Driver User interface. A structure pointer can be used to achieve portability across the SPI CLIENT having same interface structure.

3.21.1.1.2 Function Documentation

SPI1_ByteExchange()

uint8_t SPI1_ByteExchange (uint8_t byteData)

Exchanges one byte of data. This is a blocking function.

Precondition:

The SPI1_IsTxReady function must be called before calling this function.

Parameters:
in data-

Data byte to be exchanged.  

Returns:

none  

SPI1_ByteRead()

uint8_t SPI1_ByteRead (void )

Reads one byte of data from SPI1.

Precondition:

The SPI1_IsRxReady function must be called before calling this function. Also note that byte read must be after byte write sequence.

Parameters:
none
Returns:

Data read from SPI1.  

SPI1_ByteWrite()

void SPI1_ByteWrite (uint8_t byteData)

Writes one byte of data.

Precondition:

The SPI1_IsTxReady function must be called before calling this function. Also note that every byte write has to be followed by a byte read.

Parameters:
in byteData

- Data to be written.  

Returns:

none  

SPI1_Close()

void SPI1_Close (void )

Disables the SPI1 module.

Precondition:

The SPI1_Open function must be called before calling this function.

Parameters:
none
Returns:

none  

SPI1_Deinitialize()

void SPI1_Deinitialize (void )

Deinitializes the SPI1 to POR values.

Parameters:
none
Returns:

none  

SPI1_Initialize()

void SPI1_Initialize (void )

Initializes SPI1 module, using the given initialization data. This function must be called before any other SPI1 function is called.

Parameters:
none
Returns:

none  

SPI1_IsRxReady()

bool SPI1_IsRxReady (void )

Returns a boolean value if data is available to read.

Precondition:

The SPI1_Open function must be called before calling this function.

Parameters:
none
Returns:

true - Data available to read

false - Data not available to read  

SPI1_IsTxReady()

bool SPI1_IsTxReady (void )

Returns a boolean value if data can be written.

Precondition:

The SPI1_Open function must be called before calling this function.

Parameters:
none
Returns:

true - Data can be written

false - Data buffer is full  

SPI1_Open()

bool SPI1_Open (uint8_t spiConfigIndex)

Configures SPI1 module with user defined unique configuration.

Parameters:
in spiConfigIndex

- SPI1_USER_CONFIG Enum value

Returns:

bool true - SPI1 is configured successfully.

bool false - SPI1 is not configured successfully.  

3.21.1.1.3 Enumeration Type Documentation

SPI1_CLIENT_USER_CONFIG

enum SPI1_CLIENT_USER_CONFIG

Enum list is the Custom names for the SPI1 CLIENT multiple configuration, configured by user in MCC Melody user interface.

Note:

The enum list in the Help document might be just a reference to illustrate multiple configuration. Generated enum list is based on the configuration done by user in the MCC Melody user interface

CLIENT_CONFIG

Custom name for configuration setting: SPI Mode : Mode 1

Custom name for configuration setting: SPI Mode : Mode 3

Custom name for configuration setting: SPI Mode : Mode 2

CLIENT_CONFIG

Custom name for configuration setting: SPI Mode : Mode 1

Custom name for configuration setting: SPI Mode : Mode 3

Custom name for configuration setting: SPI Mode : Mode 2

CLIENT_CONFIG

Custom name for configuration setting: SPI Mode : Mode 1

Custom name for configuration setting: SPI Mode : Mode 3

Custom name for configuration setting: SPI Mode : Mode 2

3.21.1.1.4 Variable Documentation

SPI1_Client

const struct SPI_CLIENT_INTERFACE SPI1_Client

Structure object of type SPI_CLIENT_INTERFACE assigned with name displayed in the Melody Driver User interface. A structure pointer can be used to achieve portability across the SPI CLIENT having same interface structure.

3.21.2 Data Structure Documentation

3.21.2.1 SPI_CLIENT_INTERFACE Struct Reference

Structure containing the function pointers of SPI CLIENT driver.

3.21.2.1.1 Detailed Description

Structure containing the function pointers of SPI CLIENT driver.

#include <spi_client_interface.h>

Data Fields

3.21.2.1.2 Field Documentation

The documentation for this struct was generated from the following file:

source/

spi_client_interface.h

ByteExchange

uint8_t(* ByteExchange) (uint8_t byteData)

Pointer to SPIx_ByteExchange e.g. SPI1_ByteExchange.

ByteRead

uint8_t(* ByteRead) (void)

Pointer to SPIx_ByteRead e.g. SPI1_ByteRead.

ByteWrite

void(* ByteWrite) (uint8_t byteData)

Pointer to SPIx_ByteWrite e.g. SPI1_ByteWrite.

Close

void(* Close) (void)

Pointer to SPIx_Close e.g. SPI1_Close.

Deinitialize

void(* Deinitialize) (void)

Pointer to SPIx_Deinitialize e.g. SPI1_Deinitialize.

Initialize

void(* Initialize) (void)

Pointer to SPIx_Initialize e.g. SPI1_Initialize.

IsRxReady

bool(* IsRxReady) (void)

Pointer to SPIx_IsRxReady e.g. SPI1_IsRxReady.

IsTxReady

bool(* IsTxReady) (void)

Pointer to SPIx_IsTxReady e.g. SPI1_IsTxReady.

Open

bool(* Open) (uint8_t spiConfigIndex)

Pointer to SPIx_Open e.g. SPI1_Open.

3.21.3 File Documentation

3.21.3.1 source/spi1.h File Reference

This is the generated driver header file for the SPI1 driver.

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include "spi_client_interface.h"

3.21.3.1.1 Functions

  • void SPI1_Initialize (void)

    Initializes SPI1 module, using the given initialization data. This function must be called before any other SPI1 function is called.

  • void SPI1_Deinitialize (void)

    Deinitializes the SPI1 to POR values.

  • void SPI1_Close (void)

    Disables the SPI1 module.

  • bool SPI1_Open (uint8_t spiConfigIndex)

    Configures SPI1 module with user defined unique configuration.

  • uint8_t SPI1_ByteExchange (uint8_t byteData)

    Exchanges one byte of data. This is a blocking function.

  • void SPI1_ByteWrite (uint8_t byteData)

    Writes one byte of data.

  • uint8_t SPI1_ByteRead (void)

    Reads one byte of data from SPI1.

  • bool SPI1_IsRxReady (void)

    Returns a boolean value if data is available to read.

  • bool SPI1_IsTxReady (void)

    Returns a boolean value if data can be written.

3.21.3.1.2 Macros

3.21.3.1.4 Variables

  • const struct SPI_CLIENT_INTERFACE SPI1_Client

    Structure object of type SPI_CLIENT_INTERFACE assigned with name displayed in the Melody Driver User interface. A structure pointer can be used to achieve portability across the SPI CLIENT having same interface structure.

3.21.3.1.5 Detailed Description

This is the generated driver header file for the SPI1 driver.

SPI1 Generated Driver Header File

3.21.3.1.6 Macro Definition Documentation

SPI1_Client_ByteExchange

#define SPI1_Client_ByteExchange SPI1_ByteExchange

This macro defines the Custom Name for SPI1_ByteExchange API.

SPI1_Client_ByteRead

#define SPI1_Client_ByteRead SPI1_ByteRead

This macro defines the Custom Name for SPI1_ByteRead API.

SPI1_Client_ByteWrite

#define SPI1_Client_ByteWrite SPI1_ByteWrite

This macro defines the Custom Name for SPI1_ByteWrite API.

SPI1_Client_Close

#define SPI1_Client_Close SPI1_Close

This macro defines the Custom Name for SPI1_Close API.

SPI1_Client_Deinitialize

#define SPI1_Client_Deinitialize SPI1_Deinitialize

This macro defines the Custom Name for SPI1_Deinitialize API.

SPI1_Client_Initialize

#define SPI1_Client_Initialize SPI1_Initialize

This macro defines the Custom Name for SPI1_Initialize API.

SPI1_Client_IsRxReady

#define SPI1_Client_IsRxReady SPI1_IsRxReady

This macro defines the Custom Name for SPI1_IsRxReady API.

SPI1_Client_IsTxReady

#define SPI1_Client_IsTxReady SPI1_IsTxReady

This macro defines the Custom Name for SPI1_IsTxReady API.

SPI1_Client_Open

#define SPI1_Client_Open SPI1_Open

This macro defines the Custom Name for SPI1_Open API.

3.21.3.2 source/spi_client_interface.h File Reference

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>

3.21.3.2.1 Data structures

3.21.3.2.2 Detailed Description

SPI Generated Driver Interface Header File