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

Overview

Shows interrupt-mode PMBus transfers over IIC.

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.

MODIFICATION HISTORY:
Ver   Who  Date        Changes


3.15 vlt 02/18/26 Initial version 3.16 tb 09/22/26 Align Doxygen comments with AMD documentation standards

#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
 Base address of the IIC device. More...
 
#define IIC_MUX_ADDRESS   0x75
 7-bit IIC MUX address. More...
 
#define IIC_PMBUS_CHANNEL   0x04
 IIC MUX channel for PMBus. More...
 
#define PMBUS_SLAVE_ADDR   0x0A
 7-bit PMBus slave address. More...
 
#define IIC_MUX_ENABLE
 Enables the IIC MUX. More...
 
#define PMBUS_CMD_READ_VOUT   0x8B
 Command to read output voltage (VOUT). More...
 
#define PMBUS_CMD_READ_TEMP   0x8D
 Command to read temperature (TEMP). More...
 
#define PMBUS_VOUT_EXPONENT   (-12)
 VOUT_MODE exponent for LINEAR16 conversion. More...
 
#define MAX_DELAY_CNT   1000
 Maximum delay count for timeout handling. More...
 
#define EventMask   0xFF
 Internal IIC event mask. More...
 
#define Event_Value   1
 Internal event value 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)
 Demonstrates PMBus access in interrupt mode. More...
 
int main (void)
 Runs the PMBus interrupt example. More...
 

Variables

XIic IicInstance
 The instance of the IIC device. More...
 
volatile u8 TransmitComplete
 Flag to check completion of Transmission. More...
 
volatile u8 ReceiveComplete
 Flag to check completion of Reception. More...
 
volatile u8 ErrorEvent
 Error event flag set by the IIC interrupt handler. More...
 
u8 WriteBuffer [1]
 Write buffer used for IIC data transmission. More...
 

Macro Definition Documentation

#define Event_Value   1

Internal event value 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

7-bit IIC MUX address.

#define IIC_MUX_ENABLE

Enables the IIC MUX.

#define IIC_PMBUS_CHANNEL   0x04

IIC MUX channel for PMBus.

#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 for timeout handling.

#define PMBUS_CMD_READ_TEMP   0x8D

Command to read temperature (TEMP).

Referenced by IicPmbusInterruptSdtExample().

#define PMBUS_CMD_READ_VOUT   0x8B

Command to read output voltage (VOUT).

Referenced by IicPmbusInterruptSdtExample().

#define PMBUS_SLAVE_ADDR   0x0A

7-bit PMBus slave address.

Referenced by IicPmbusInterruptSdtExample().

#define PMBUS_VOUT_EXPONENT   (-12)

VOUT_MODE exponent for LINEAR16 conversion.

Referenced by IicPmbusInterruptSdtExample().

#define XIIC_BASEADDRESS   XPAR_XIIC_0_BASEADDR

Base address of the IIC device.

Referenced by IicPmbusInterruptSdtExample().

Function Documentation

int IicPmbusInterruptSdtExample ( void  )

Demonstrates PMBus access in interrupt mode.

It initializes IIC, sets up interrupts, selects the MUX (if enabled), reads voltage and temperature from the PMBus device, and prints the results.

Returns
  • XST_SUCCESS if successful.
  • XST_FAILURE otherwise.

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_TEMP, PMBUS_CMD_READ_VOUT, PMBUS_SLAVE_ADDR, PMBUS_VOUT_EXPONENT, ReadBuffer, 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  )

Runs the PMBus interrupt example.

Returns
  • XST_SUCCESS if successful.
  • XST_FAILURE otherwise.

Run the PMBus example.

References IicPmbusInterruptSdtExample().

Variable Documentation

volatile u8 ErrorEvent

Error event flag set by the IIC interrupt handler.

XIic IicInstance

The instance of the IIC device.

volatile u8 ReceiveComplete

Flag to check completion of Reception.

volatile u8 TransmitComplete

Flag to check completion of Transmission.

u8 WriteBuffer[1]

Write buffer used for IIC data transmission.