![]() |
iic
Vitis Drivers API Documentation
|
This file consists of a Interrupt mode design example which uses the Xilinx IIC device and XIic driver to exercise the slave functionality of the IIC device.
The XIic_SlaveSend() API is used to transmit the data and XIic_SlaveRecv() 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 Master 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.
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. Some of the macros have been renamed in the IIC driver and some renamed macros are used in this example. 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 0x70 /* 0xE0 as an 8 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 | IicSlaveExample (void) |
| This function writes and reads the data as a slave. More... | |
| int | SlaveWriteData (u16 ByteCount) |
| This function writes a buffer of bytes to the IIC bus when the IIC master initiates a read operation. More... | |
| int | SlaveReadData (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... | |
| #define MAX_DELAY_CNT 10000 |
Maximum delay count used for timeout handling.
Referenced by SlaveReadData(), and SlaveWriteData().
| #define SLAVE_ADDRESS 0x70 /* 0xE0 as an 8 bit number. */ |
The following constant defines the address of the IIC device on the IIC bus.
Since the address is only 7 bits, this constant is the address divided by 2.
Referenced by IicSlaveExample().
| #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 IicSlaveExample().
| int IicSlaveExample | ( | void | ) |
This function writes and reads the data as a slave.
The IIC master on the bus initiates the transfers.
References XIic_Config::BaseAddress, XIic_Config::IntrId, XIic_Config::IntrParent, SLAVE_ADDRESS, SlaveReadData(), SlaveWriteData(), WriteBuffer, XII_ADDR_TO_RESPOND_TYPE, XIIC_BASEADDRESS, XIic_CfgInitialize(), XIic_InterruptHandler(), XIic_LookupConfig(), XIic_SetAddress(), XIic_SetRecvHandler(), XIic_SetSendHandler(), XIic_SetStatusHandler(), and XIic_SlaveInclude().
Referenced by main().
| int main | ( | void | ) |
Slave write flag.
Main function to call the IIC Slave example.
References IicSlaveExample().
| int SlaveReadData | ( | u8 * | BufferPtr, |
| u16 | ByteCount | ||
| ) |
This function reads a buffer of bytes when the IIC Master on the bus writes data to the slave device.
| BufferPtr | contains the address of the data buffer to be filled. |
| ByteCount | contains the number of bytes in the buffer to be read. |
References XIic::BaseAddress, MAX_DELAY_CNT, ReceiveComplete, SlaveRead, XIic_IntrGlobalDisable, XIic_IntrGlobalEnable, XIic_SlaveRecv(), XIic_Start(), and XIic_Stop().
Referenced by IicSlaveExample().
| int SlaveWriteData | ( | u16 | ByteCount | ) |
This function writes a buffer of bytes to the IIC bus when the IIC master initiates a read operation.
| ByteCount | contains the number of bytes in the buffer to be written. |
References XIic::BaseAddress, MAX_DELAY_CNT, SlaveWrite, TransmitComplete, WriteBuffer, XIic_IntrGlobalDisable, XIic_IntrGlobalEnable, XIic_SlaveSend(), XIic_Start(), and XIic_Stop().
Referenced by IicSlaveExample().
| u8 ReadBuffer[RECEIVE_COUNT] |
Write buffer for writing a page.
| volatile u8 ReceiveComplete |
Transmit done flag.
| volatile u8 SlaveRead |
Receive done flag.
Referenced by SlaveReadData(), and TenBitAddrReadData().
| volatile u8 SlaveWrite |
Slave read flag.
Referenced by SlaveWriteData(), and TenBitAddrWriteData().
| volatile u8 TransmitComplete |
Read buffer for reading a page.
| u8 WriteBuffer[SEND_COUNT] |
The instance of the IIC device.