iic: xiic_slave_example.c File Reference

| iic Xilinx SDK Drivers API Documentation

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

Functions
xiic_slave_example.c File Reference

## Overview

This file consists of a Interrupt mode design example which uses the Xilinx IIC device and XIic driver to exercise the slave functionality of the IIC device.

The XIic_SlaveSend() API is used to transmit the data and XIic_SlaveRecv() API is used to receive the data.

The example is tested on ML300/ML310/ML403/ML501 Xilinx boards.

The IIC devices that are present on the Xilinx boards donot support the Master functionality. This example has been tested with an off board external IIC Master device and the IIC device configured as a Slave.

This code assumes that no Operating System is being used.

Note

None.

    MODIFICATION HISTORY:

    Ver   Who  Date  Changes

    1.00a mta  03/01/06 Created.
    2.00a ktn  11/17/09 Updated to use the HAL APIs and replaced call to
                  XIic_Initialize API with XIic_LookupConfig and
                  XIic_CfgInitialize. Some of the macros have been
                  renamed in the IIC driver and some renamed macros are
                  used in this example.
    3.4   ms   01/23/17 Added xil_printf statement in main function to
                        ensure that "Successfully ran" and "Failed" strings
                        are available in all examples. This is a fix for
                        CR-965028.

## Functions
int | IicSlaveExample ()
| This function writes and reads the data as a slave. More...
int | SlaveWriteData (u16 ByteCount)
| This function writes a buffer of bytes to the IIC bus when the IIC master initiates a read operation. More...
int | SlaveReadData (u8 *BufferPtr, u16 ByteCount)
| This function reads a buffer of bytes when the IIC Master on the bus writes data to the slave device. More...
int | main (void)
| Main function to call the IIC Slave example. More...

## Function Documentation

int IicSlaveExample | ( |  | ) |

This function writes and reads the data as a slave.

The IIC master on the bus initiates the transfers.

Parameters

  None. |

Returns
  XST_SUCCESS if successful else XST_FAILURE.

Note
  None.

References XIic_Config::BaseAddress, SlaveReadData(), SlaveWriteData(), XII_ADDR_TO_RESPOND_TYPE, XIic_CfgInitialize(), XIic_LookupConfig(), XIic_SetAddress(), XIic_SetRecvHandler(), XIic_SetSendHandler(), XIic_SetStatusHandler(), and XIic_SlaveInclude().

Referenced by main().

int main | ( | void |  | ) |

Main function to call the IIC Slave example.

Parameters

  None. |

Returns
  XST_SUCCESS if successful else XST_FAILURE.

Note
  None.

References IicSlaveExample().

int SlaveReadData | ( | u8 * | BufferPtr,
|  | u16 | ByteCount
| ) |  |

This function reads a buffer of bytes when the IIC Master on the bus writes data to the slave device.

Parameters

  BufferPtr | contains the address of the data buffer to be filled.
  ByteCount | contains the number of bytes in the buffer to be read.

Returns
  XST_SUCCESS if successful else XST_FAILURE.

Note
  None

References XIic::BaseAddress, XIic_IntrGlobalDisable, XIic_IntrGlobalEnable, XIic_SlaveRecv(), XIic_Start(), and XIic_Stop().

Referenced by IicSlaveExample().

int SlaveWriteData | ( | u16 | ByteCount | ) |

This function writes a buffer of bytes to the IIC bus when the IIC master initiates a read operation.

Parameters

  ByteCount | contains the number of bytes in the buffer to be written.

Returns
  XST_SUCCESS if successful else XST_FAILURE.

Note
  None.

References XIic::BaseAddress, XIic_IntrGlobalDisable, XIic_IntrGlobalEnable, XIic_SlaveSend(), XIic_Start(), and XIic_Stop().

Referenced by IicSlaveExample().