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

Overview

This file consists of an interrupt mode design example which uses the Xilinx IIC device and low-level driver to communicate with a PMBus device.

The example demonstrates how to read voltage and temperature from a PMBus-compliant device using the IIC interface. It includes conversion routines for PMBus Linear11 and Linear16 formats.

The XIic_MasterSend() API is used to transmit the data and XIic_MasterRecv() API is used to receive the data. Interrupt handlers are used for send, receive, and status events.

The define PMBUS_SLAVE_ADDR in this file needs to be changed depending on the PMBus device and board configuration on which this example is to be run.

This code assumes that no Operating System is being used.

Note
None.
MODIFICATION HISTORY:
Ver   Who  Date        Changes


3.15 vlt 02/18/26 Initial version

#include "xparameters.h"
#include "xiic.h"
#include "xil_printf.h"
#include "xiic_l.h"
#include "xil_util.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 IIC_MUX_ADDRESS   0x75
 The ZCU102 and ZCU106 boards use a PMBus MUX address of 0x75 with channel address 0x05 and PMBus slave address 0x13. More...
 
#define PMBUS_SLAVE_ADDR   0x0A
 The following constant defines the address of the PMBus device on the IIC bus. More...
 
#define IIC_MUX_ENABLE   /** Enables the IIC MUX */
 This define should be uncommented if there is an IIC MUX on the board to which the PMBus device is connected. More...
 
#define PMBUS_VOUT_EXPONENT   (-12)
 PMBus READ_VOUT uses LINEAR16 format. More...
 
#define MAX_DELAY_CNT   1000
 Maximum delay count used for timeout handling. More...
 
#define EventMask   0xFF
 Internal IIC event mask. More...
 
#define Event_Value   1
 Internal event value used for IIC event checking. More...
 
#define EXPONENT_SHIFT   11
 Shift to get exponent bits. More...
 
#define EXPONENT_MASK   0x1F
 Mask for 5-bit exponent. More...
 
#define MANTISSA_MASK   0x7FF
 Mask for 11-bit mantissa. More...
 
#define EXP_SIGN_BIT   0x10
 Exponent sign bit. More...
 
#define MANT_SIGN_BIT   0x400
 Mantissa sign bit. More...
 

Functions

int IicPmbusInterruptSdtExample (void)
 This function demonstrates PMBus interrupt access: initializes IIC, sets up interrupts, selects MUX (if enabled), and read voltage and temperature from the PMBus device, printing results. More...
 
int main (void)
 Write buffer used for IIC data transmission. More...
 

Variables

volatile u8 TransmitComplete
 The instance of the IIC device. More...
 
volatile u8 ReceiveComplete
 Flag to check completion of Transmission. More...
 
volatile u8 ErrorEvent
 Flag to check completion of Reception. More...
 
u8 WriteBuffer [1]
 Error event flag set by the IIC interrupt handler. More...
 

Macro Definition Documentation

#define Event_Value   1

Internal event value used for IIC event checking.

#define EventMask   0xFF

Internal IIC event mask.

#define EXP_SIGN_BIT   0x10

Exponent sign bit.

#define EXPONENT_MASK   0x1F

Mask for 5-bit exponent.

#define EXPONENT_SHIFT   11

Shift to get exponent bits.

#define IIC_MUX_ADDRESS   0x75

The ZCU102 and ZCU106 boards use a PMBus MUX address of 0x75 with channel address 0x05 and PMBus slave address 0x13.

The ZC702 and ZC706 boards use a PMBus MUX address of 0x74 with channel address 0x80 and PMBus slave address 0x52.

The KCU105 board uses a PMBus MUX address of 0x74 or 0x75 with channel address 0x04 and PMBus slave address 0x0A. Please refer to the User Guide of the respective board and the PMBus device datasheet for further information about the correct addresses and channel to use for PMBus communication. The defines below must be updated to match the board in use.

#define IIC_MUX_ENABLE   /** Enables the IIC MUX */

This define should be uncommented if there is an IIC MUX on the board to which the PMBus device is connected.

For example, the KCU105 board uses an IIC MUX to access PMBus devices.

#define MANT_SIGN_BIT   0x400

Mantissa sign bit.

#define MANTISSA_MASK   0x7FF

Mask for 11-bit mantissa.

#define MAX_DELAY_CNT   1000

Maximum delay count used for timeout handling.

#define PMBUS_SLAVE_ADDR   0x0A

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

Note that this is a 7-bit address. The PMBus slave address may vary depending on the board and the PMBus device used. For example, the KCU105 board uses 0x0A as the PMBus slave address for its power controller. Please refer to the User Guide of the respective board and the PMBus device datasheet for further information about the correct slave address to use.

Referenced by IicPmbusInterruptSdtExample().

#define PMBUS_VOUT_EXPONENT   (-12)

PMBus READ_VOUT uses LINEAR16 format.

As per PMBus specification, the exponent is defined by VOUT_MODE. For the PMBus device used in this example, VOUT_MODE exponent is fixed at -12 (device/board specific).

Referenced by IicPmbusInterruptSdtExample().

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

Function Documentation

int IicPmbusInterruptSdtExample ( void  )

This function demonstrates PMBus interrupt access: initializes IIC, sets up interrupts, selects MUX (if enabled), and read voltage and temperature from the PMBus device, printing results.

Returns
XST_SUCCESS if successful, else XST_FAILURE.
Note
None.

Initialize the IIC driver so that it is ready to use.

Setup the Interrupt System.

Set the Handlers for transmit and reception.

Start the IIC device.

Set the Global Interrupt Enable.

Initialize the IIC MUX on boards where the PMBus devices are connected through the MUX.

Set the Slave address.

Read the output voltage (VOUT) from the PMBus device

Combine the two bytes into a 16-bit raw value, convert it to voltage using Linear16 format, scale it to centivolts, and print the result.

Read the output temperature from the PMBus device

Convert raw PMBus temperature data (Linear11) to centi-degrees Celsius and print

References XIic_Config::BaseAddress, XIic::BaseAddress, XIic_Config::IntrId, XIic_Config::IntrParent, PMBUS_CMD_READ_VOUT, PMBUS_SLAVE_ADDR, PMBUS_VOUT_EXPONENT, XII_ADDR_TO_SEND_TYPE, XIIC_BASEADDRESS, XIic_CfgInitialize(), XIic_InterruptHandler(), XIic_IntrGlobalEnable, XIic_LookupConfig(), XIic_SetAddress(), XIic_SetRecvHandler(), XIic_SetSendHandler(), XIic_SetStatusHandler(), and XIic_Start().

Referenced by main().

int main ( void  )

Write buffer used for IIC data transmission.

Main function to call the PMBus interrupt example.

Returns
XST_SUCCESS if successful, else XST_FAILURE.
Note
None.

Run the PMBus example.

References IicPmbusInterruptSdtExample().

Variable Documentation

volatile u8 ErrorEvent

Flag to check completion of Reception.

volatile u8 ReceiveComplete

Flag to check completion of Transmission.

volatile u8 TransmitComplete

The instance of the IIC device.

u8 WriteBuffer[1]

Error event flag set by the IIC interrupt handler.