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

The XIic driver uses the complete FIFO functionality to transmit/receive data.

This example writes/reads from the lower 256 bytes of the IIC EEPROMS. Please refer to the datasheets of the IIC EEPROM's for details about the internal addressing and page size of these devices.

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

This example is tested on ML300/ML310/ML410/ML403/ML501/ML507/ML510/ML605/ SP601, SP605, KC705 , ZC702 and ZC706 Xilinx boards.

The ML310/ML510/ML410/SCU35 boards have a on-board 64 Kb serial IIC EEPROM (Microchip 24LC64A). The WP pin of the IIC EEPROM is hardwired to ground on this board.

The ML300 board has an on-board 32 Kb serial IIC EEPROM(Microchip 24LC32A). The WP pin of the IIC EEPROM has to be connected to ground for this example. The WP is connected to pin Y3 of the FPGA.

The ML403 board has an on-board 4 Kb serial IIC EEPROM(Microchip 24LC04A). The WP pin of the IIC EEPROM is hardwired to ground on this board.

The ML501/ML505/ML507/ML605/SP601/SP605/KC705/ZC702/ZC706 boards have an on-board 8 Kb serial IIC EEPROM(STM M24C08). The WP pin of the IIC EEPROM is hardwired to ground on these boards.

The AddressType for ML300/ML310/ML410/ML510/SCU200/SCU35 boards should be u16 as the address pointer in the on board EEPROM is 2 bytes.

The AddressType for ML403/ML501/ML505/ML507/ML605/SP601/SP605/KC705/ZC702/ ZC706 boards should be u8 as the address pointer for the on board EEPROM is 1 byte.

The 7 bit IIC Slave address of the IIC EEPROM on the ML300/ML310/ML403/ML410/ ML501/ML505/ML507/ML510/SCU200 boards is 0x50. The 7 bit IIC Slave address of the IIC EEPROM on the ML605/SP601/SP605/KC705 /ZC702/ZC706 boards is 0x54. Refer to the User Guide's of the respective boards for further information about the IIC slave address of IIC EEPROM's.

The define EEPROM_ADDRESS in this file needs to be changed depending on the board on which this example is to be run. This is the IIC address of the EEPROM.

The define IIC_MUX_ADDRESS in this file needs to be changed depending on the board on which this example is to be run. This is the IIC address of the the MUX.

The define IIC_MUX_ENABLE should be defined so that the IIC Mux initialization is done for the boards on the which the EEPROM is connected to an IIC Mux. The boards with a MUX are a KC705/ZC702/ZC706.

The define IIC_EEPROM_CHANNEL needs to be changed depending on the Channel number of EEPROM for IIC Mux. On KC705 it is 0x08 and ZC702 is 0x04. Please refer the User Guide's of the respective boards for further information about the Channel number to use EEPROM.

This code assumes that no Operating System is being used.

Note

None.

MODIFICATION HISTORY:
Ver   Who  Date  Changes


1.00a mta 02/24/06 Created. 1.00a mta 04/05/07 Added support for microblaze. 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. 2.01a ktn 03/17/10 Updated the information about the EEPROM's used on ML605/SP601/SP605 boards. Updated the example so that it can be used to access the entire IIC EEPROM for devices like M24C04/M24C08 that use LSB bits of the IIC device select code (IIC slave address) to specify the higher address bits of the EEPROM internal address. 2.02a bss 01/30/13 Updated for using the GIC in case of Zynq 2.06a bss 02/14/13 Added MuxInit API to support Zynq and KC705 boards and modified to use ScuGic in case of Zynq CR# 683509 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 12/04/25 Add XIic_SetClk API for dynamic clock configuration. 3.15 vlt 02/17/26 Added timeout handling to polled wait loops. 3.15 vlt 03/20/26 Updated comments lines for SCU200 and SCU35 EEPROM address, page size, and address type.

#include "xparameters.h"
#include "xiic.h"
#include "xil_exception.h"
#include "xil_printf.h"
#include "xil_sutil.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 EEPROM_ADDRESS   0x54 /* 0xA0 as an 8 bit number. */
 The following constant defines the address of the IIC Slave device on the IIC bus. More...
 
#define IIC_MUX_ADDRESS   0x74
 The IIC_MUX_ADDRESS defines the address of the IIC MUX device on the IIC bus. More...
 
#define IIC_MUX_ENABLE
 This define should be uncommented if there is IIC MUX on the board to which this EEPROM is connected. More...
 
#define PAGE_SIZE   16
 The page size determines how much data should be written at a time. More...
 
#define EEPROM_TEST_START_ADDRESS   128
 The Starting address in the IIC EEPROM on which this test is performed. More...
 
#define MAX_DELAY_CNT   10000
 Maximum delay count used for timeout handling. More...
 
#define EventMask   0xFF
 Internal IIC event mask. More...
 
#define Event_Value   0
 Internal event value used for IIC event checking. More...
 

Typedefs

typedef u8 AddressType
 The AddressType for ML300/ML310/ML410/ML510/SCU200/SCU35 boards should be u16 as the address pointer in the on board EEPROM is 2 bytes. More...
 

Functions

int IicEepromExample (void)
 This function writes, reads, and verifies the data to the IIC EEPROM. More...
 
int EepromWriteData (u16 ByteCount)
 This function writes a buffer of data to the IIC serial EEPROM. More...
 
int EepromReadData (u8 *BufferPtr, u16 ByteCount)
 This function reads data from the IIC serial EEPROM into a specified buffer. More...
 
int main (void)
 Variable for storing Eeprom IIC address. More...
 

Variables

u8 WriteBuffer [sizeof(AddressType)+PAGE_SIZE]
 The instance of the IIC device. More...
 
volatile u8 TransmitComplete
 Read buffer for reading a page. More...
 
volatile u8 ReceiveComplete
 Flag to check completion of Transmission. More...
 
u8 EepromIicAddr
 Flag to check completion of Reception. More...
 

Macro Definition Documentation

#define EEPROM_ADDRESS   0x54 /* 0xA0 as an 8 bit number. */

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

Note that since the address is only 7 bits, this constant is the address divided by 2. The 7 bit IIC Slave address of the IIC EEPROM on the ML300/ML310/ML403/ML410/ ML501/ML505/ML507/ML510/SCU200 boards is 0x50. The 7 bit IIC Slave address of the IIC EEPROM on the ML605/SP601/SP605/KC705/ZC702/ZC706/ZCU102/KCU105 boards is 0x54. Please refer the User Guide's of the respective boards for further information about the IIC slave address of IIC EEPROM's.

Referenced by IicEepromExample().

#define EEPROM_TEST_START_ADDRESS   128

The Starting address in the IIC EEPROM on which this test is performed.

Referenced by EepromReadData(), and IicEepromExample().

#define Event_Value   0

Internal event value used for IIC event checking.

Referenced by EepromReadData().

#define EventMask   0xFF

Internal IIC event mask.

Referenced by EepromReadData().

#define IIC_MUX_ADDRESS   0x74

The IIC_MUX_ADDRESS defines the address of the IIC MUX device on the IIC bus.

Note that since the address is only 7 bits, this constant is the address divided by 2. The IIC Slaves on the KC705/ZC702/ZC706 boards are connected to an IIC MUX. IIC_EEPROM_CHANNEL is the Channel number of EEPROM for IIC Mux. On ZC702 is 0x04. The ZCU102 board uses Mux Address 0x74 with EEPROM channel 0x01,the KCU105 board uses Mux Address 0x75 with EEPROM channel 0x07,and the KC705 board uses Mux Address 0x74 with EEPROM channel 0x08. Please refer the User Guide's of the respective boards for further information about the Channel number to use EEPROM.

#define IIC_MUX_ENABLE

This define should be uncommented if there is IIC MUX on the board to which this EEPROM is connected.

The boards that have IIC MUX are KC705/ZC702/ZC706.

#define MAX_DELAY_CNT   10000

Maximum delay count used for timeout handling.

Referenced by EepromReadData(), and EepromWriteData().

#define PAGE_SIZE   16

The page size determines how much data should be written at a time.

The ML310/ML300/SCU200/SCU35 board supports a page size of 32 and 16. The write function should be called with this as a maximum byte count.

Referenced by IicEepromExample().

#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 IicEepromExample().

Typedef Documentation

typedef u8 AddressType

The AddressType for ML300/ML310/ML410/ML510/SCU200/SCU35 boards should be u16 as the address pointer in the on board EEPROM is 2 bytes.

The AddressType for ML403/ML501/ML505/ML507/ML605/SP601/SP605/KC705/ZC702 /ZC706 boards should be u8 as the address pointer in the on board EEPROM is 1 bytes.

Function Documentation

int EepromReadData ( u8 *  BufferPtr,
u16  ByteCount 
)

This function reads data from the IIC serial EEPROM into a specified buffer.

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 EEPROM_TEST_START_ADDRESS, EepromWriteData(), Event_Value, EventMask, MAX_DELAY_CNT, ReceiveComplete, WriteBuffer, XIic_MasterRecv(), XIic_Start(), and XIic_Stop().

Referenced by IicEepromExample().

int EepromWriteData ( u16  ByteCount)

This function writes a buffer of data to the IIC serial EEPROM.

Parameters
ByteCountcontains the number of bytes in the buffer to be written.
Returns
XST_SUCCESS if successful else XST_FAILURE.
Note
The Byte count should not exceed the page size of the EEPROM as noted by the constant PAGE_SIZE.

References MAX_DELAY_CNT, XIic::Stats, TransmitComplete, XIicStats::TxErrors, WriteBuffer, XIic_MasterSend(), XIic_Start(), and XIic_Stop().

Referenced by EepromReadData(), and IicEepromExample().

int IicEepromExample ( void  )

This function writes, reads, and verifies the data to the IIC EEPROM.

It does the write as a single page write, performs a buffered read.

Returns
XST_SUCCESS if successful else XST_FAILURE.
Note
None.

Pointer to configuration data

References XIic_Config::BaseAddress, EEPROM_ADDRESS, EEPROM_TEST_START_ADDRESS, EepromIicAddr, EepromReadData(), EepromWriteData(), XIic_Config::IntrId, XIic_Config::IntrParent, PAGE_SIZE, 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  )

Variable for storing Eeprom IIC address.

Main function to call the High level EEPROM example.

Returns
XST_SUCCESS if successful else XST_FAILURE.
Note
None.

References IicEepromExample().

Variable Documentation

u8 EepromIicAddr

Flag to check completion of Reception.

volatile u8 ReceiveComplete

Flag to check completion of Transmission.

volatile u8 TransmitComplete

Read buffer for reading a page.

u8 WriteBuffer[sizeof(AddressType)+PAGE_SIZE]

The instance of the IIC device.

Write buffer for writing a page.