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

Overview

Shows IIC 10-bit addressing.

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

The XIic_MasterSend() API is used to transmit the data and XIic_MasterRecv() 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 do not support the 10-bit 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.

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. Made minor modifications as per coding guidelines. 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   0x270
 IIC slave address, 0x4E0 as a 10-bit number. More...
 
#define RECEIVE_COUNT   16
 IIC receive byte count. More...
 
#define SEND_COUNT   16
 IIC transmit byte count. More...
 
#define MAX_DELAY_CNT   10000
 Maximum delay count for timeout handling. More...
 

Functions

int IicTenBitAddrExample (void)
 Writes and reads the data as a slave. More...
 
int TenBitAddrWriteData (u16 ByteCount)
 Writes a buffer of bytes when the IIC master initiates a read. More...
 
int TenBitAddrReadData (u8 *BufferPtr, u16 ByteCount)
 Reads a buffer of bytes when the IIC master writes to the slave. More...
 
int main (void)
 Runs the IIC Slave 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
 Transmit done flag. More...
 
volatile u8 ReceiveComplete
 Receive done flag. More...
 
volatile u8 SlaveRead
 Slave read flag. More...
 
volatile u8 SlaveWrite
 Slave write flag. More...
 

Macro Definition Documentation

#define MAX_DELAY_CNT   10000

Maximum delay count for timeout handling.

Referenced by TenBitAddrReadData(), and TenBitAddrWriteData().

#define RECEIVE_COUNT   16

IIC receive byte count.

Referenced by IicTenBitAddrExample(), and TenBitAddrReadData().

#define SEND_COUNT   16

IIC transmit byte count.

Referenced by IicTenBitAddrExample(), and TenBitAddrWriteData().

#define SLAVE_ADDRESS   0x270

IIC slave address, 0x4E0 as a 10-bit number.

Referenced by IicTenBitAddrExample().

#define XIIC_BASEADDRESS   XPAR_XIIC_0_BASEADDR

IIC base address.

Referenced by IicTenBitAddrExample().

Function Documentation

int IicTenBitAddrExample ( void  )

Writes and reads the data as a slave.

This function writes and reads the data as a slave. The IIC master on the bus initiates the transfers.

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, TenBitAddrReadData(), TenBitAddrWriteData(), WriteBuffer, XII_ADDR_TO_RESPOND_TYPE, XII_SEND_10_BIT_OPTION, XIIC_BASEADDRESS, XIic_CfgInitialize(), XIic_InterruptHandler(), XIic_LookupConfig(), XIic_SetAddress(), XIic_SetOptions(), XIic_SetRecvHandler(), XIic_SetSendHandler(), XIic_SetStatusHandler(), and XIic_SlaveInclude().

Referenced by main().

int main ( void  )

Runs the IIC Slave example.

Main function to call the IIC Slave example.

Returns
  • XST_SUCCESS if successful.
  • XST_FAILURE otherwise.

References IicTenBitAddrExample().

int TenBitAddrReadData ( u8 *  BufferPtr,
u16  ByteCount 
)

Reads a buffer of bytes when the IIC master writes to the slave.

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

Parameters
[out]BufferPtrThe address of the data buffer to be filled.
[in]ByteCountThe number of bytes in the buffer to be read.
Returns
  • XST_SUCCESS if successful.
  • XST_FAILURE otherwise.

References XIic::BaseAddress, MAX_DELAY_CNT, ReadBuffer, RECEIVE_COUNT, ReceiveComplete, SlaveRead, XIic_IntrGlobalDisable, XIic_IntrGlobalEnable, XIic_SlaveRecv(), XIic_Start(), and XIic_Stop().

Referenced by IicTenBitAddrExample().

int TenBitAddrWriteData ( u16  ByteCount)

Writes a buffer of bytes when the IIC master initiates a read.

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

Parameters
[in]ByteCountThe number of bytes in the buffer to be written.
Returns
  • XST_SUCCESS if successful.
  • XST_FAILURE otherwise.

References XIic::BaseAddress, MAX_DELAY_CNT, SEND_COUNT, SlaveWrite, TransmitComplete, WriteBuffer, XIic_IntrGlobalDisable, XIic_IntrGlobalEnable, XIic_SlaveSend(), XIic_Start(), and XIic_Stop().

Referenced by IicTenBitAddrExample().

Variable Documentation

XIic IicInstance

The instance of the IIC device.

u8 ReadBuffer[RECEIVE_COUNT]

Read buffer for reading a page.

volatile u8 ReceiveComplete

Receive done flag.

volatile u8 SlaveRead

Slave read flag.

volatile u8 SlaveWrite

Slave write flag.

volatile u8 TransmitComplete

Transmit done flag.

u8 WriteBuffer[SEND_COUNT]

Write buffer for writing a page.