iic
Vitis Drivers API Documentation
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
xiic_repeated_start_example.c File Reference

Overview

Shows IIC repeated-start transfers.

This file consists of a interrupt mode design example to demonstrate the use of repeated start using the XIic driver.

The XIic_MasterSend() API is used to transmit the data and XIic_MasterRecv() API is used to receive the data.

The IIC devices that are present on the Xilinx boards do not support the repeated start option. These examples have been tested with an IIC device external to the boards.

This code assumes that no Operating System is being used.

MODIFICATION HISTORY:
Ver   Who  Date  Changes


1.00a mta 02/20/06 Created. 2.00a sdm 09/22/09 Updated to use the HAL APIs, replaced call to XIic_Initialize API with XIic_LookupConfig and XIic_CfgInitialize. Updated the example with a fix for CR539763 where XIic_Start was being called instead of XIic_Stop. Added code for setting up the StatusHandler callback. 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. 3.10 gm 07/09/23 Added SDT support 3.15 vlt 01/27/26 Fixed codespell issues 3.15 vlt 02/17/26 Added timeout handling to polled wait loops. 3.16 tb 09/22/26 Align Doxygen comments with AMD documentation standards

 
#include "xparameters.h"
#include "xiic.h"
#include "xil_sutil.h"
#include "xil_exception.h"
#include "xil_printf.h"
#include "xinterrupt_wrap.h"

Macros

#define XIIC_BASEADDRESS   XPAR_XIIC_0_BASEADDR
 IIC base address. More...
 
#define SLAVE_ADDRESS   0x70
 IIC slave address. More...
 
#define SEND_COUNT   16
 Number of bytes to send. More...
 
#define RECEIVE_COUNT   16
 Number of bytes to receive. More...
 
#define MAX_DELAY_CNT   10000
 Maximum delay count for timeout handling. More...
 
#define EventMask   0xFF
 Internal IIC event mask. More...
 
#define Event_Value   0
 Internal event value for IIC event checking. More...
 

Functions

int IicRepeatedStartExample (void)
 Writes and reads the data to the IIC Slave. More...
 
int main (void)
 Runs the Repeated Start example. More...
 

Variables

XIic IicInstance
 The instance of the IIC device. More...
 
u8 WriteBuffer [SEND_COUNT]
 Write buffer for writing a page. More...
 
u8 ReadBuffer [RECEIVE_COUNT]
 Read buffer for reading a page. More...
 
volatile u8 TransmitComplete
 Flag to check completion of Transmission. More...
 
volatile u8 ReceiveComplete
 Flag to check completion of Reception. More...
 

Macro Definition Documentation

#define Event_Value   0

Internal event value for IIC event checking.

#define EventMask   0xFF

Internal IIC event mask.

#define MAX_DELAY_CNT   10000

Maximum delay count for timeout handling.

#define RECEIVE_COUNT   16

Number of bytes to receive.

Referenced by IicRepeatedStartExample().

#define SEND_COUNT   16

Number of bytes to send.

Referenced by IicRepeatedStartExample().

#define SLAVE_ADDRESS   0x70

IIC slave address.

Referenced by IicRepeatedStartExample().

#define XIIC_BASEADDRESS   XPAR_XIIC_0_BASEADDR

IIC base address.

Referenced by IicRepeatedStartExample().

Function Documentation

int IicRepeatedStartExample ( void  )

Writes and reads the data to the IIC Slave.

This function writes and reads the data to the IIC Slave.

Returns
  • XST_SUCCESS if successful.
  • XST_FAILURE otherwise.

References XIic_Config::BaseAddress, XIic_Config::IntrId, XIic_Config::IntrParent, ReadBuffer, RECEIVE_COUNT, SEND_COUNT, SLAVE_ADDRESS, WriteBuffer, XII_ADDR_TO_SEND_TYPE, XIIC_BASEADDRESS, XIic_CfgInitialize(), XIic_InterruptHandler(), XIic_LookupConfig(), XIic_SetAddress(), XIic_SetRecvHandler(), XIic_SetSendHandler(), and XIic_SetStatusHandler().

Referenced by main().

int main ( void  )

Runs the Repeated Start example.

Main function to call the Repeated Start example.

Returns
  • XST_SUCCESS if successful.
  • XST_FAILURE otherwise.

References IicRepeatedStartExample().

Variable Documentation

XIic IicInstance

The instance of the IIC device.

u8 ReadBuffer[RECEIVE_COUNT]

Read buffer for reading a page.

volatile u8 ReceiveComplete

Flag to check completion of Reception.

volatile u8 TransmitComplete

Flag to check completion of Transmission.

u8 WriteBuffer[SEND_COUNT]

Write buffer for writing a page.