![]() |
iic
Vitis Drivers API Documentation
|
This file consists of a polled mode design example which uses the Xilinx IIC device and low-level driver to exercise the EEPROM.
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_Send() API is used to transmit the data and XIic_Recv() API is used to receive the data.
This example is tested on ML300/ML310/ML403/ML501/ML507/ML510/ML605/SP601 and SP605 Xilinx boards.
The ML310/ML410/ML510/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 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 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 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 code assumes that no Operating System is being used.
MODIFICATION HISTORY:
Ver Who Date Changes
1.00a jhl 09/10/03 Created 1.00a sv 05/09/05 Minor changes to comply to Doxygen and coding guidelines 1.00a mta 03/09/06 Minor updates due to changes in the low level driver for supporting repeated start functionality. 2.00a sdm 09/22/09 Converted all register accesses to 32 bit access and minor modifications as per coding guidelines. 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.01a sdm 06/13/11 Updated the example to flush the Tx FIFO when waiting for the previous command to be completed for CR612546. 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.5 sd 08/29/18 Update the fifo flush. 3.10 gm 07/09/23 Added SDT support. 3.15 vlt 03/20/26 Updated comments lines for SCU200 and SCU35 EEPROM address, page size, and address type.
Macros | |
| #define | IIC_BASE_ADDRESS XPAR_AXI_IIC_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 | 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... | |
Typedefs | |
| typedef u8 | AddressType |
| The AddressType for ML300/ML310/ML510/SCU200/SCU35 boards should be u16 as the address pointer in the on board EEPROM is 2 bytes. More... | |
Functions | |
| int | IicLowLevelEeprom (void) |
| The function uses the low level driver of IIC to read and write to the IIC EEPROM board. More... | |
| int | ReadWriteVerify (AddressType Address) |
| This function writes, reads, and verifies the read to the IIC EEPROM. More... | |
| unsigned | EepromWriteByte (AddressType Address, u8 *BufferPtr, u16 ByteCount) |
| This function writes a buffer of bytes to the IIC serial EEPROM. More... | |
| unsigned | EepromReadByte (AddressType Address, u8 *BufferPtr, u16 ByteCount) |
| This function reads a number of bytes from the IIC serial EEPROM into a specified buffer. More... | |
| int | main (void) |
| Variable for storing Eeprom IIC address. More... | |
Variables | |
| u8 | WriteBuffer [PAGE_SIZE] |
| The Error Count. More... | |
| u8 | ReadBuffer [PAGE_SIZE] |
| Write buffer for writing a page. More... | |
| u8 | ReadBufferAll [PAGE_SIZE *4] |
| Read buffer for reading a page. More... | |
| u8 | EepromIicAddr |
| Buffer used for reading all the data. 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.
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 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 IicLowLevelEeprom().
| #define EEPROM_TEST_START_ADDRESS 128 |
The Starting address in the IIC EEPROM on which this test is performed.
Referenced by EepromWriteByte(), and IicLowLevelEeprom().
| #define IIC_BASE_ADDRESS XPAR_AXI_IIC_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 EepromReadByte(), and EepromWriteByte().
| #define MAX_DELAY_CNT 10000 |
Maximum delay count used for timeout handling.
Referenced by EepromReadByte(), and EepromWriteByte().
| #define PAGE_SIZE 16 |
The page size determines how much data should be written at a time.
The ML300 board supports a page size of 32 and 16 The write function should be called with this as a maximum byte count.
Referenced by EepromWriteByte(), IicLowLevelEeprom(), and ReadWriteVerify().
| typedef u8 AddressType |
The AddressType for ML300/ML310/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 boards should be u8 as the address pointer in the on board EEPROM is 1 bytes.
| unsigned EepromReadByte | ( | AddressType | Address, |
| u8 * | BufferPtr, | ||
| u16 | ByteCount | ||
| ) |
This function reads a number of bytes from the IIC serial EEPROM into a specified buffer.
| Address | contains the address in the EEPROM to read from. |
| BufferPtr | contains the address of the data buffer to be filled. |
| ByteCount | contains the number of bytes in the buffer to be read. This value is not constrained by the page size of the device such that up to 64K may be read in one call. |
References EepromIicAddr, IIC_BASE_ADDRESS, MAX_DELAY_CNT, XIIC_CR_ENABLE_DEVICE_MASK, XIIC_CR_REG_OFFSET, XIIC_CR_TX_FIFO_RESET_MASK, XIic_ReadReg, XIic_Recv(), XIic_Send(), XIIC_SR_BUS_BUSY_MASK, XIIC_SR_REG_OFFSET, XIIC_STOP, and XIic_WriteReg.
| unsigned EepromWriteByte | ( | AddressType | Address, |
| u8 * | BufferPtr, | ||
| u16 | ByteCount | ||
| ) |
This function writes a buffer of bytes to the IIC serial EEPROM.
| Address | contains the address in the EEPROM to write to. |
| BufferPtr | contains the address of the data to write. |
| ByteCount | contains the number of bytes in the buffer to be written. Note that this should not exceed the page size of the EEPROM as noted by the constant PAGE_SIZE. |
References EEPROM_TEST_START_ADDRESS, EepromIicAddr, IIC_BASE_ADDRESS, MAX_DELAY_CNT, PAGE_SIZE, WriteBuffer, XIIC_CR_ENABLE_DEVICE_MASK, XIIC_CR_REG_OFFSET, XIIC_CR_TX_FIFO_RESET_MASK, XIic_ReadReg, XIic_Send(), XIIC_STOP, and XIic_WriteReg.
| int IicLowLevelEeprom | ( | void | ) |
The function uses the low level driver of IIC to read and write to the IIC EEPROM board.
The addresses tested are from 128 to 192.
References EEPROM_ADDRESS, EEPROM_TEST_START_ADDRESS, EepromIicAddr, EepromReadByte(), PAGE_SIZE, ReadBufferAll, and ReadWriteVerify().
Referenced by main().
| int main | ( | void | ) |
Variable for storing Eeprom IIC address.
Main function to call the low level EEPROM example.
References IicLowLevelEeprom().
| int ReadWriteVerify | ( | AddressType | Address | ) |
This function writes, reads, and verifies the read to the IIC EEPROM.
It does the write as a single page write, performs a buffered read, and also performs byte reads.
| Address | is the starting address of the page in the EEPROM device to which the data is to be written. |
References EepromReadByte(), EepromWriteByte(), PAGE_SIZE, and WriteBuffer.
Referenced by IicLowLevelEeprom().
| u8 EepromIicAddr |
Buffer used for reading all the data.
| u8 ReadBuffer[PAGE_SIZE] |
Write buffer for writing a page.
| u8 ReadBufferAll[PAGE_SIZE *4] |
Read buffer for reading a page.
Referenced by IicLowLevelEeprom().
| u8 WriteBuffer[PAGE_SIZE] |
The Error Count.