iic
Vitis Drivers API Documentation
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
xiic_tenbitaddr_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 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.

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. 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.

#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
 The following constants map to the XPAR parameters created in the xparameters.h file. More...
 
#define SLAVE_ADDRESS   0x270 /* 0x4E0 as an 10 bit number. */
 The following constant defines the address of the IIC device on the IIC bus. More...
 
#define MAX_DELAY_CNT   10000
 Maximum delay count used for timeout handling. More...
 

Functions

int IicTenBitAddrExample (void)
 This function writes and reads the data as a slave. More...
 
int TenBitAddrWriteData (u16 ByteCount)
 This function writes a buffer of bytes to the IIC bus when the IIC master initiates a read operation. More...
 
int TenBitAddrReadData (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)
 Slave write flag. More...
 

Variables

u8 WriteBuffer [SEND_COUNT]
 The instance of the IIC device. More...
 
u8 ReadBuffer [RECEIVE_COUNT]
 Write buffer for writing a page. More...
 
volatile u8 TransmitComplete
 Read buffer for reading a page. More...
 
volatile u8 ReceiveComplete
 Transmit done flag. More...
 
volatile u8 SlaveRead
 Receive done flag. More...
 
volatile u8 SlaveWrite
 Slave read flag. More...
 

Macro Definition Documentation

#define MAX_DELAY_CNT   10000

Maximum delay count used for timeout handling.

Referenced by TenBitAddrReadData(), and TenBitAddrWriteData().

#define SLAVE_ADDRESS   0x270 /* 0x4E0 as an 10 bit number. */

The following constant defines the address of the IIC device on the IIC bus.

Since the address is 10 bits, this constant is the address divided by 2.

Referenced by IicTenBitAddrExample().

#define XIIC_BASEADDRESS   XPAR_XIIC_0_BASEADDR

The following constants map to the XPAR parameters created in the xparameters.h file.

They are defined here such that a user can easily change all the needed parameters in one place.

Referenced by IicTenBitAddrExample().

Function Documentation

int IicTenBitAddrExample ( void  )
int main ( void  )

Slave write flag.

Main function to call the IIC Slave example.

Returns
XST_SUCCESS if successful else XST_FAILURE.
Note
None.

References IicTenBitAddrExample().

int TenBitAddrReadData ( 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
BufferPtrcontains the address of the data buffer to be filled.
ByteCountcontains the number of bytes in the buffer to be read.
Returns
XST_SUCCESS if successful else XST_FAILURE.
Note
None

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

Referenced by IicTenBitAddrExample().

int TenBitAddrWriteData ( u16  ByteCount)

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

Parameters
ByteCountcontains the number of bytes in the buffer to be written.
Returns
XST_SUCCESS if successful else XST_FAILURE.
Note
None.

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

Referenced by IicTenBitAddrExample().

Variable Documentation

u8 ReadBuffer[RECEIVE_COUNT]

Write buffer for writing a page.

volatile u8 ReceiveComplete

Transmit done flag.

volatile u8 SlaveRead

Receive done flag.

volatile u8 SlaveWrite

Slave read flag.

volatile u8 TransmitComplete

Read buffer for reading a page.

u8 WriteBuffer[SEND_COUNT]

The instance of the IIC device.