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

Overview

This file consists of a polled 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_Send() API is used to transmit the data and XIic_Recv() API is used to receive the data.

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 "xiic_l.h"
#include "xil_printf.h"
#include "xil_types.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
 This define should be uncommented if there is an IIC MUX on the board to which the PMBus device is connected. More...
 
#define PMBUS_CMD_READ_VOUT   0x8B /** Command to read output voltage (VOUT) */
 PMBus command definitions: More...
 
#define PMBUS_VOUT_EXPONENT   (-12) /** Exponent used in the calculation of vout voltage.*/
 PMBus READ_VOUT uses LINEAR16 format. 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 IicPmbusPolledExample (void)
 This function demonstrates PMBus polled access: initializes IIC, selects MUX (if enabled), and reads VOUT, TEMP, from the PMBus device, printing results. More...
 
int main (void)
 Buffer used to store data read from the PMBus device. More...
 

Variables

u8 ReadBuffer [2]
 The instance of the IIC device. More...
 

Macro Definition Documentation

#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

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 PMBUS_CMD_READ_VOUT   0x8B /** Command to read output voltage (VOUT) */

PMBus command definitions:

  • READ_VOUT uses the Linear16 data format as defined by the PMBus specification.
  • All other read commands (current, temperature, and frequency) use the Linear11 data format.

Referenced by IicPmbusInterruptSdtExample(), and IicPmbusPolledExample().

#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.

#define PMBUS_VOUT_EXPONENT   (-12) /** Exponent used in the calculation of vout voltage.*/

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 IicPmbusPolledExample().

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

Function Documentation

int IicPmbusPolledExample ( void  )

This function demonstrates PMBus polled access: initializes IIC, selects MUX (if enabled), and reads VOUT, TEMP, 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.

Start the IIC device.

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

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.

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

References XIic_Config::BaseAddress, PMBUS_CMD_READ_VOUT, PMBUS_VOUT_EXPONENT, XIIC_BASEADDRESS, XIic_CfgInitialize(), XIic_LookupConfig(), and XIic_Start().

Referenced by main().

int main ( void  )

Buffer used to store data read from the PMBus device.

Main function to call the PMBus polled example.

Returns
XST_SUCCESS if successful, else XST_FAILURE.
Note
None.

Run the PMBus example.

References IicPmbusPolledExample().

Variable Documentation

u8 ReadBuffer[2]

The instance of the IIC device.