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

Overview

This file contains an interrupt based design example which uses the Xilinx IIC device and driver to exercise the temperature sensor on the ML300 board.

This example only performs read operations (receive) from the IIC temperature sensor of the platform.

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

This example assumes that there is an interrupt controller in the hardware system and the IIC device is connected to the interrupt controller.

Note

7-bit addressing is used to access the tempsensor.

None

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 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.14 bkv 07/07/25 Fixed GCC Warnings. 3.15 vlt 12/12/25 Update Doxygen comments to include SDT flow details. 3.15 vlt 02/17/26 Added timeout handling to polled wait loops.

 
#include "xparameters.h"
#include "xiic.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 TEMP_SENSOR_ADDRESS   0x18 /* The actual address is 0x30 */
 The following constant defines the address of the IIC temperature sensor device on the IIC bus. More...
 
#define MAX_DELAY_CNT   10000
 Maximum delay count used for timeout handling. More...
 

Functions

int TempSensorExample (UINTPTR BaseAddress, u8 TempSensorAddress, u8 *TemperaturePtr)
 The function reads the temperature of the IIC temperature sensor on the IIC bus. More...
 
int main (void)
 The purpose of this function is to illustrate how to use the IIC driver to read the temperature. More...
 

Variables

struct {
HandlerInfo
 The instance of the IIC device. More...
 

Macro Definition Documentation

#define MAX_DELAY_CNT   10000

Maximum delay count used for timeout handling.

Referenced by TempSensorExample().

#define TEMP_SENSOR_ADDRESS   0x18 /* The actual address is 0x30 */

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

Note that since the address is only 7 bits, this constant is the address divided by 2.

Referenced by main().

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

Function Documentation

int main ( void  )

The purpose of this function is to illustrate how to use the IIC driver to read the temperature.

Returns
XST_SUCCESS if successful, XST_FAILURE if unsuccessful
Note
None

References TEMP_SENSOR_ADDRESS, TempSensorExample(), and XIIC_BASEADDRESS.

int TempSensorExample ( UINTPTR  BaseAddress,
u8  TempSensorAddress,
u8 *  TemperaturePtr 
)

The function reads the temperature of the IIC temperature sensor on the IIC bus.

It initializes the IIC device driver and sets it up to communicate with the temperature sensor. This function does contain a loop that polls for completion of the IIC processing such that it may not return if interrupts or the hardware are not working.

Parameters
BaseAddresscontains the base address of the device
TempSensorAddressis the address of the Temperature Sensor device on the IIC bus
TemperaturePtris the data byte read from the temperature sensor
Returns
XST_SUCCESS to indicate success, else XST_FAILURE to indicate a Failure.
Note
In XSCT/classic flow, DeviceId is used to look up the device configuration.

References XIic_Config::BaseAddress, HandlerInfo, XIic_Config::IntrId, XIic_Config::IntrParent, MAX_DELAY_CNT, XII_ADDR_TO_SEND_TYPE, XIic_CfgInitialize(), XIic_InterruptHandler(), XIic_LookupConfig(), XIic_MasterRecv(), XIic_SetAddress(), XIic_SetRecvHandler(), XIic_SetStatusHandler(), and XIic_Start().

Referenced by main().

Variable Documentation

struct { ... } HandlerInfo

The instance of the IIC device.

The following structure contains fields that are used with the callbacks (handlers) of the IIC driver. The driver asynchronously calls handlers when abnormal events occur or when data has been sent or received. This structure must be volatile to work when the code is optimized.

Referenced by TempSensorExample().