spips: xspips_slave_polled_example.c File Reference

| spips Xilinx SDK Drivers API Documentation

- Overview
- Data Structures
- APIs
- File List
- Examples

Functions
xspips_slave_polled_example.c File Reference

## Overview

This file contains a design example using the SPI controller in slave mode.

This examples performs transfers in polled mode and has been tested with Aardvark Analyzer as Master. This example echoes data which it receives from the master. The slave controller expects MAX_DATA bytes of data from the master to transmit onto the SPI bus which the slave will receive into its Rx buffer. It will poll until the Rx FIFO is filled with the Threshold limit of data which is set to MAX_DATA. On sending data, the master will receive dummy bytes in response. Master has to send MAX_DATA dummy bytes to read back the echoed data.

Note

The slave mode test needs an external master to send data to the Spi device. This example has been tested with Aardvark Analyzer as Master. The Clock Polarity and Phase should match between master and the slave.

     MODIFICATION HISTORY:

     Ver   Who Date     Changes

     2.0   sb  08/22/14  First release
           ms   04/05/17 Modified Comment lines in functions to
                         recognize it as documentation block for doxygen
                         generation.

## Functions
void | SpiSlaveRead (int ByteCount)
| This function reads from the Rx buffer. More...
void | SpiSlaveWrite (u8 *Sendbuffer, int ByteCount)
| This function writes Data into the Tx buffer. More...
int | SpiPsSlavePolledExample (u16 SpiDeviceId)
| The purpose of this function is to illustrate how to use the XSpiPs device driver in Slave mode. More...
int | main (void)
| Main function to call the SPI Slave Example. More...

## Function Documentation

int main | ( | void |  | ) |

Main function to call the SPI Slave Example.

Parameters

  None |

Returns
  - XST_SUCCESS if successful
  - XST_FAILURE if not successful

Note
  None

References SpiPsSlavePolledExample().

int SpiPsSlavePolledExample | ( | u16 | SpiDeviceId | ) |

The purpose of this function is to illustrate how to use the XSpiPs device driver in Slave mode.

This function reads data from a SPI Master and will echo it back to the Master.

Parameters

  SpiDeviceId | is the Instance Id of SPI in the system.

Returns
  - XST_SUCCESS if successful
  - XST_FAILURE if not successful

Note
  None

References XSpiPs_Config::BaseAddress, SpiSlaveRead(), SpiSlaveWrite(), XSpiPs_CfgInitialize(), XSPIPS_CR_CPHA_MASK, XSPIPS_CR_CPOL_MASK, XSpiPs_Disable, XSpiPs_Enable, XSpiPs_LookupConfig(), XSpiPs_SetOptions(), and XSpiPs_SetRXWatermark.

Referenced by main().

void SpiSlaveRead | ( | int | ByteCount | ) |

This function reads from the Rx buffer.

Parameters

  ByteCount | is the number of bytes to be read from Rx buffer.

Returns
  None.

Note
  None.

References XSpiPs_Config::BaseAddress, XSpiPs::Config, XSPIPS_IXR_RXNEMPTY_MASK, XSpiPs_ReadReg, and XSPIPS_SR_OFFSET.

Referenced by SpiPsSlavePolledExample().

void SpiSlaveWrite | ( | u8 * | Sendbuffer,
|  | int | ByteCount
| ) |  |

This function writes Data into the Tx buffer.

Parameters

  Sendbuffer | is the buffer whose data is to be sent onto the Tx FIFO.
  ByteCount | is the number of bytes to be read from Rx buffer.

Returns
  None.

Note
  None.

References XSpiPs_Config::BaseAddress, XSpiPs::Config, XSPIPS_FIFO_DEPTH, XSPIPS_IXR_TXOW_MASK, XSpiPs_ReadReg, and XSPIPS_SR_OFFSET.

Referenced by SpiPsSlavePolledExample().