DIODES AP33772 USB PD Sink Controller Raspberry Pi I2C Interface User Guide

June 10, 2024
DIODES

DIODES AP33772 USB PD Sink Controller Raspberry Pi I2C Interface

DIODES-AP33772-USB-PD-Sink-Controller-Raspberry-Pi-I2C-Interface-
PRODUCT

Introduction

  • AP33772 Sink Controller, working as the protocol device of USB PD3.0 Type C Connector-equipped Device (TCD, Energy Sink), is intended to request proper Power Data Object (PDO) from the USB PD3.0 Type C Connector-equipped PD3.0 compliance Charger (PDC, Energy Source).
  • Figure 1 illustrates a TCD, embedded with PD3.0 Sink controller IC (AP33772), is physically connected to PDC, embedded with USB PD3.0 decoder (AP43771), through a
  • Type C-to-Type C cable. Based on built-in USB PD3.0 compliant firmware, The AP33772 and AP43771 pair would go through the USB PD3.0 standard attachment procedure to establish suitable PD3.0 charging state.
  • AP33772 Sink Controller EVB provides ease of use and great versatility for system designer to request PDOs from USB Power Delivery Charger by sending AP33772 built-in commands through I2C interface. Typical system design requires MCU programming which needs specific software (e.g. IDE) setup and can be a time-consuming development process.
  • In contrast, Raspberry Pi (RPI), a single board computer (SBC) running on a user-friendly Linux OS and equipped with flexible GPIO pins, provides a straightforward way to validate AP33772 Sink EVB working with a PD Charger. The goal of this guide is to provide system designers an effective platform to quickly complete software validation on RPI and then port the development to any desirable MCU to meet rapid turnaround market requirements.
  • As a supplemental document to the AP33772 EVB User Guide, this User Guide illustrates an easy way to control AP33772 EVB with a RPI SBC through I2C Interface.
  • The role of MCU block depicted in Figure 1 to interface with AP33772 is played by an RPI. This User Guide covers a lot of register definition and usage information as examples, However, for complete and most updated information, please refer to AP33772 EVB User’ Guide. (See Reference 2)
  • Figure 1 – A typical TCD uses AP33772 PD Sink Controller with I2C Interface to request power from an USB Type-C PD3.0/PPS Compliance Source Adapter

Validation Platform Setup

AP33772 Sink Controller EVB
Figure 2 shows the picture of the Sink Controller EVB. It features Type-C Connector, I2C pins, GPIO3 pin for Interrupt, NTC Thermistor for OTP, LED indicators to show the charging status, and Vout connector to the load .DIODES-AP33772-USB-PD-Sink-Controller-Raspberry-Pi-I2C-Interface-
FIG-2

Raspberry Pi Zero 2W

  • Any latest version of RPI is capable of controlling AP33772 Sink Controller EVB through I2C pins. A Raspberry Pi Zero 2 W (RPI Z2W) is used in this User Guide for its cost effectiveness and versatility. It has the smallest formfactor among all RPIs and is integrated with WiFi and Bluetooth that makes the wireless connection without additional component. It servers the purpose as the AP33772 Sink Controller EVB Validation Platform perfectly.
  • User may check the Raspberry Pi official website for additional information ( https://www.raspberrypi.com/products/raspberry-pi-zero-2-w/)

Validation Platform Connection and Power up

Figure 5 shows a complete connection and setup of the Validation Platform. User should follow these steps:

  1. Connect SCL, SDA, and GND pins between RPI and AP33772 EVB
  2. Connect 65W PD Charger and AP33772 EVB with Type-C cable
  3. Power up RPI and PD Charger.DIODES-AP33772-USB-PD-Sink-Controller-Raspberry-Pi-I2C-Interface-FIG-5

Raspberry Pi Software Setup

Raspberry Pi OS

  • There are many different operating systems that support RPI. Among these, Raspberry Pi OS is chosen because it is the most used and recommended by RPI official site.

Download OS Image and Prepare SD Card

Raspberry PI OS Installation

  • Insert the Micro-SD card loaded with imager earlier into RPI’s Micro-SD slot. Connect the power adapter, mouse/keyboard, and HDMI monitor. Power on the RPI and follow the instruction to complete OS installation and basic setup. Make sure the latest updates are included on the OS.

Setup of Required Features

  • In order to run I2C interface on RPI successfully, we must configure or install the SSH, VNC, and I2C features.

Raspberry Pi Config – SSH, VNC, I2C

  • After RPI boot-up, open “Raspberry Pi Configure” utility and turn on SSH, VNC, and I2C features.DIODES-AP33772-USB-PD-Sink-Controller-Raspberry-Pi-I2C-Interface-FIG-7

I2C Baud Rate Configuration

  • Replace the lines regarding dtparam and dtoverlay in /boot/config.txt file with:
  • dtoverlay=i2c-bcm2708
  • dtparam=i2c_arm=on,i2c_arm_baudrate=640000

I2C-Tools Installation

  • I2C-Tools is a toolset that provides simple commands running on command line under Raspberry Pi OS. Install I2C-Tools on the OS by running: sudo apt install i2c-tools

SMBus2 Installation

  • SMBus2 is a Python module that provides convenient functions for user to control I2C interface under Python environment. Install SMBus2 module for Python on the OS by running: sudo pip3 install smbus2

Basic Command Examples

  • This User Guide demonstrate two different methods to work with I2C interface on RPI. They are I2C-Tools Utility and Python SMBus2 Module. The basic commands of both methods are introduced in this section.

I2C-Tools Command Examples

  • I2C-Tools utility package provides i2cdetect, i2cget, and i2cset commands. Simplified usages are described in the examples under this section. For complete information about I2C-Tools utility, please refer to https://linuxhint.com/i2c-linux-utilities/.
  • Table 1 shows the AP33772 register summary for user’s convenience to digest the command usage in this section. For complete register information, please refer to AP33772 Sink Controller EVB User Guide.
Register Command Length Attribute Power-on Description

SRCPDO

|

0x00

|

28

|

RO

|

All 00h

| Power Data Object (PDO) used to expose PD Source (SRC) power capabilities.

Total length is 28 bytes

PDONUM| 0x1C| 1| RO| 00h| Valid source PDO number
STATUS| 0x1D| 1| RC| 00h| AP33772 status
MASK| 0x1E| 1| RW| 01h| Interrupt enable mask
VOLTAGE| 0x20| 1| RO| 00h| LSB 80mV
CURRENT| 0x21| 1| RO| 00h| LSB 24mA
TEMP| 0x22| 1| RO| 19h| Temperature, Unit: °C
OCPTHR| 0x23| 1| RW| 00h| OCP threshold, LSB 50mA
OTPTHR| 0x24| 1| RW| 78h| OTP threshold, Unit: °C
DRTHR| 0x25| 1| RW| 78h| De-rating threshold, Unit: °C
TR25| 0x28| 2| RW| 2710h| Thermal Resistance @25°C, Unit: Ω
TR50| 0x2A| 2| RW| 1041h| Thermal Resistance @50°C, Unit: Ω
TR75| 0x2C| 2| RW| 0788h| Thermal Resistance @75°C, Unit: Ω
TR100| 0x2E| 2| RW| 03CEh| Thermal Resistance @100°C, Unit: Ω
RDO| 0x30| 4| WO| 00000000h| Request Data Object (RDO) is use to request power capabilities.
VID| 0x34| 2| RW| 0000h| Vendor ID, Reserved for future applications
PID| 0x36| 2| RW| 0000h| Product ID, Reserved for future applications
RESERVED| 0x38| 4| –| –| Reserved for future applications

Table 1 – AP33772 Register Summary

Detect all devices attached to I2C – i2cdetect

  • To display all i2c devices currently attached to I2C-1 bus, type the following under command prompt:  i2cdetect -y 1
  • If AP33772 Sink Controller EVB is attached, user should see device is attached at 0x51 address

Read SRCPDO (0x00~0x1B)

  • i2cget command doesn’t support block read longer than 2 bytes. User needs to use “for loop” to display all 28-byte long PDO data. To display all PDO data, type the following under bash command prompt for i in {0..27}; do i2cget -y 1 0x51 $i b; done
  • 28-byte data representing 7 PDOs will be displayed

Read PDONUM (0x1C)

  • To display total number of valid PDOs, type the following under command prompt: i2cget -y 1 0x51 0x1c b

Read STATUS (0x1D)

  • This command reports the Sink Controller’s status including de-rating, OTP, OCP, OVP, Request Rejected, Request Completed, and Ready. To display the status information, type the following under command prompt: i2cget -y 1 0x51 0x1d b
  • User should use this command after each RDO request to ensure successful RDO request by reading the COMPLETE bit. 4.1.5 Write MASK (0x1E)
  • This command enables the interrupts that signal the host through GPIO3 pin of AP33772. The interrupts include Derating , OTP, OCP, OVP, Request Rejected, Request Completed, and Ready. To enable a specific interrupt, set the corresponding bit to one. For example, to enable OCP interrupt, set bit 4 of MASK register to one by typing the following under command prompt: i2cset -y 1 0x51 0x1e 0x10 b
  • GPIO3 pin of AP33772 will go high when the OCP protection is trigger.

Read VOLTAGE (0x20)

  • This command reports the voltage measured by the AP33772 Sink Controller. To report the voltage, type the following under command prompt: i2cget -y 1 0x51 0x20 b
  • One unit of the reported value represents 80mV.

Read CURRENT (0x21)

  • This command reports the current measured by the AP33772 Sink Controller. To report the current, type the following under command prompt: i2cget -y 1 0x51 0x21 b
  • One unit of the reported value represents 24mA.

Read TEMP (0x22)

  • This command reports the temperature measured by the AP33772 Sink Controller. To report the temperature, type the following under command prompt:
    i2cget -y 1 0x51 0x22 b

  • One unit of the reported value represents 1°C.

  • Read and Write OCPTHR (0x23), OTPTHR (0x24), and DRTHR (0x25)

  • OCP, OTP, and Derating thresholds can be changed to user desirable values by writing the values to OCPTHR, OTPTHR, and DRTHR registers. As an example, to change OCP threshold to 3.1A, user should write 0x3E (=3100/50=62=0x3E) to OCPTHR by typing the following under command prompt: i2cset -y 1 0x51 0x23 0x3e b

  • To change OTP threshold to 110°C, user should write 0x6E (=110) to OTPTHR by typing the following under command prompt:

  • To read the values out of OCPTHR, OTPTHR, and DRTHR, type the following under command prompt:

  • i2cget -y 1 0x51 0x23 b i2cget -y 1 0x51 0x24 b i2cget -y 1 0x51 0x25 b

  • Read and Write TR25 (0x28~0x29), TR50 (0x2A~0x2B), TR75 (0x2C~0x2D), and TR100 (0x2E~0x2F)

  • A Murata 10KΩ Negative Temperature Coefficient (NTC) Thermistor NCP03XH103 is populated on the AP33772 EVB. It is user’s preference to change the thermistor to a different one in the final design. User should update TR25, TR50, TR75, and TR100 register values according to specifications of the thermistor used. For example,

  • Murata’s 6.8KΩ NCP03XH682 is used in the design. The resistance values at 25°C, 50°C, 75°C, and 100°C are 6800Ω (0x1A90), 2774Ω (0x0AD6), 1287Ω (0x0507), and 662Ω (0x0296) respectively. To write the corresponding values to these registers, type the following under command prompt:

  • i2cset -y 1 0x51 0x28 0x1a90 w i2cset -y 1 0x51 0x2a 0x0ad6 w i2cset -y 1 0x51 0x2c 0x0507 w i2cset -y 1 0x51 0x2e 0x0296 w

  • To read the values out, type the following under command prompt:  i2cget -y 1 0x51 0x28 w i2cget -y 1 0x51 0x2a w i2cget -y 1 0x51 0x2c w i2cget -y 1 0x51 0x2e w

  • The output values are 2-byte words. Since the commands handle 2-byte word directly, users don’t need to worry about little endian byte order here.

Write RDO (0x30~0x33)

  • To initiate a PDO request negotiation procedure, 4-byte data is written to RDO (Request Data Object) register in little-endian byte order. As example, to request PDO3 with 15V and 3A, 0x3004B12C will be written to RDO register. Type the following under command prompt: i2cset -y 1 0x51 0x30 0x2c 0xb1 0x04 0x30 i
  • The least significant byte (0x2C) should be written in first to fit little endian byte order notation. Please refer to Table 9 and Table 10 of AP33772 Sink Controller EVB User
  • Guide for detailed RDO content information.
  • User can issue a hard reset by writing RDO register with all-zero data: i2cset -y 1 0x51 0x30 0x00 0x00 0x00 0x00 i
  • The AP33772 Sink Controller will be reset to its initial state and output will be turned off.

Python SMBus2 Command Examples

  • Python is getting more popular for its great varieties of supported modules. SMBus2 is among of those and capable of handling I2C read and write commands. SMBus2 provides read_byte_data, read_word_data, read_i2c_block_data, write_byte_data, write_word_data, write_i2c_block_data commands. Simplified usages are described in the examples under this section. For complete information about SMBus2 module, please refer to https://smbus2.readthedocs.io/en/latest/.

Read SRCPDO (0x00~0x1B)

  • SMBus.read_i2c_block_data is an effective command to support up to 32-byte block data read. To read all 28-byte PDO data, use the following under python3 environment:
  • SMBus.read_i2c_block_data(0x51, 0x00, 28)
  • 28 one-byte data representing 7 PDOs will be returned in list data structure.

Read PDONUM (0x1C)

  • To read total number of valid PDOs, use the following under python3 environment:
  • SMBus.read_byte_data(0x51, 0x1c)
  • One byte data representing valid PDO count will be returned.

Read STATUS (0x1D)

  • This command reports the Sink Controller’s status including Derating , OTP, OCP, OVP, Request Rejected, Request Completed, and Ready. To read the status information, use the following under python3 environment:
  • SMBus.read_byte_data(0x51, 0x1d)
  • User may use this command after each RDO request to ensure successful RDO request by reading the COMPLETE bit.

Write MASK (0x1E)

  • This command enables the interrupts that signal the host through GPIO3 pin of AP33772. The interrupts include Derating , OTP, OCP, OVP, Request Rejected, Request
  • Completed, and Ready. To enable a specific interrupt, set the corresponding bit to one. For example, to enable OCP interrupt, set bit 4 of MASK register to one by using the following under python3 environment:
  • SMBus.write_byte_data(0x51, 0x1e, 0x10)
  • GPIO3 pin of AP33772 will go high when the OCP protection is trigger.

Read VOLTAGE (0x20)

  • This command reports the voltage measured by the AP33772 Sink Controller. To report the voltage, use the following under python3 environment:
  • SMBus.read_byte_data(0x51, 0x20)
  • One unit of the reported value represents 80mV.

Read CURRENT (0x21)

  • This command reports the current measured by the AP33772 Sink Controller. To report the current, use the following under python3 environment
  • SMBus.read_byte_data(0x51, 0x21)
  • One unit of the reported value represents 24mA.

Read TEMP (0x22)

  • This command reports the temperature measured by the AP33772 Sink Controller. To report the temperature, use the following under python3 environment:
  • SMBus.read_byte_data(0x51, 0x22)
  • One unit of the reported value represents 1°C.

Read and Write OCPTHR (0x23), OTPTHR (0x24), and DRTHR (0x25)

  • OCP, OTP, and Derating thresholds can be changed to user desirable values by writing the values to OCPTHR, OTPTHR, and DRTHR registers. As an example, to change OCP threshold to 3.1A, user should write 0x3E (=3100/50=62=0x3E) to OCPTHR by using the following under python3 environment: SMBus.write_byte_data(0x51, 0x23, 0x3e)
  • To change OTP threshold to 110°C, user should write 0x6E (=110) to OTPTHR by using the following under python3 environment: SMBus.write_byte_data(0x51, 0x24, 0x6e)
  • To change Derating threshold to 100°C, user should write 0x64 (=100) to DRTHR by using the following under python3 environment: SMBus.write_byte_data(0x51, 0x25, 0x64)
  • To read the values out of OCPTHR, OTPTHR, and DRTHR, use the following under python3 environment: SMBus.read_byte_data(0x51, 0x23) SMBus.read_byte_data(0x51, 0x24) SMBus.read_byte_data(0x51, 0x25) .
  • Read and Write TR25 (0x28~0x29), TR50 (0x2A~0x2B), TR75 (0x2C~0x2D), and TR100 (0x2E~0x2F)
  • A Murata 10KΩ Negative Temperature Coefficient (NTC) Thermistor NCP03XH103 is populated on the AP33772 EVB. It is user’s preference to change the thermistor to a different one in the final design. User should update TR25, TR50, TR75, and TR100 register value according to specifications of the thermistor used. For example, Murata’s 6.8KΩ NCP03XH682 is used in the design. The resistance values at 25°C, 50°C, 75°C, and 100°C are 6800Ω (0x1A90), 2774Ω (0x0AD6), 1287Ω (0x0507), and 662Ω (0x0296) respectively. To write the corresponding values to these registers, use the following under python3 environment:
  • SMBus.write_word_data(0x51, 0x28, 0x1a90) SMBus.write_word_data(0x51, 0x2a, 0x0ad6) SMBus.write_word_data(0x51, 0x2c, 0x0507) SMBus.write_word_data(0x51, 0x2e, 0x0296)
  • To read the values out, use the following under python3 environment: SMBus.read_word_data(0x51, 0x28) SMBus.read_word_data(0x51, 0x2a) SMBus.read_word_data(0x51, 0x2c) SMBus.read_word_data(0x51, 0x2e)
  • The return values are also 2-byte words. Since the commands handle 2-byte word directly, users don’t need to worry about little endian byte order here.

Write RDO (0x30~0x33)

  • To initiate a PDO request negotiation procedure, 4-byte data is written to RDO (Request Data Object) register in little-endian byte order. As example, to request PDO3 with 15V and 3A, 0x3004B12C will be written to RDO register. Use the following under python3 environment:
  • SMBus.write_i2c_block_data(0x51, 0x30, [0x2c, 0xb1, 0x04, 0x30])
  • Please refer to Table 9 and Table 10 of AP33772 Sink Controller EVB User Guide for detailed RDO content information.
  • User can issue a hard reset by writing RDO register with all-zero data:
  • SMBus.write_i2c_block_data(0x51, 0x30, [0x00, 0x00, 0x00, 0x00])
  • The AP33772 Sink Controller will be reset to its initial state and output will be turned off.

Practical Examples

Example 1: Bash I2C-Tools Example: ap33772_querypdo.bash
This example checks all valid PDOs and lists the voltage and current capability information out.
Code DetailsDIODES-AP33772-USB-PD-Sink-Controller-Raspberry-Pi-I2C-
Interface-FIG-8

Code Execution and OutputsDIODES-AP33772-USB-PD-Sink-Controller-
Raspberry-Pi-I2C-Interface-FIG-9

Example 2: Python SMBus2 Example: ap33772_allpdo.py3
This example checks all valid PDOs and requests them one by one in up and down order.
Code DetailsDIODES-AP33772-USB-PD-Sink-Controller-Raspberry-Pi-I2C-
Interface-FIG-10DIODES-
AP33772-USB-PD-Sink-Controller-Raspberry-Pi-I2C-Interface-
FIG-11DIODES-AP33772-USB-PD-
Sink-Controller-Raspberry-Pi-I2C-Interface-FIG-12

Code Execution and OutputsDIODES-AP33772-USB-PD-Sink-Controller-
Raspberry-Pi-I2C-Interface-FIG-13

Example Code Download

List of Example Codes

  • Example Codes have Bash Script and Python Versions
  1. ap33772_querypdo: queries all PDO information
  2. ap33772_reqpdo: reports all PDO information and sends out PDO request specified by user
  3. ap33772_allpdo: reports all PDO information and walks through all PDO requests in up and down manner
  4. ap33772_pps: reports all PDO information, and ramps up and down the entire PPS voltage range in 50mV step size
  5. ap33772_vit: reports voltage, current, and temperature information
Example Download Site

Example Codes can be downloaded from Github. Issue the following command to download: git clone https://github.com/diodinciot/ap33772.git- ap33772

References

  1. AP33772 Datasheet (USB PD3.0 PPS Sink Controller): https://www.diodes.com/products/power-management/ac-dc-converters/usb-pd-sink-controllers/
  2. AP33772 I2C Sink Controller EVB User Guide: https://www.diodes.com/applications/ac-dc-chargers-and-adapters/usb-pd-sink-controller/
  3. Raspberry Pi Zero 2 W: https://www.raspberrypi.com/products/raspberry-pi-zero-2-w/
  4. Raspberry Pi OS: https://www.raspberrypi.com/software/
  5. I2C-Tools utility: https://linuxhint.com/i2c-linux-utilities/
  6. SMBus2 Module: https://smbus2.readthedocs.io/en/latest/

Revision History

Revision Issue Date Comment Author
1.0 4/15/2022 Initial Release Edward Zhao
IMPORTANT NOTICE
  • DIODES INCORPORATED MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS DOCUMENT, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE (AND THEIR EQUIVALENTS UNDER THE LAWS OF ANY JURISDICTION).

  • Diodes Incorporated and its subsidiaries reserve the right to make modifications, enhancements, improvements, corrections, or other changes without further notice to this document and any product described herein. Diodes Incorporated does not assume any liability arising out of the application or use of this document or any product described herein; neither does Diodes Incorporated convey any license under its patent or trademark rights, nor the rights of others. Any Customer or user of this document or products described herein in such applications shall assume all risks of such use and will agree to hold Diodes Incorporated and all the companies whose products are represented on the Diodes Incorporated website, harmless against all damages.

  • Diodes Incorporated does not warrant or accept any liability whatsoever in respect of any products purchased through unauthorized sales channels.
    Should Customers purchase or use Diodes Incorporated products for any unintended or unauthorized application, Customers shall indemnify and hold Diodes

  • Incorporated and its representatives were harmless against all claims, damages, expenses, and attorney fees arising out of, directly or indirectly, any claim of personal injury or death associated with such unintended or unauthorized application.

  • Products described herein may be covered by one or more United States, international or foreign patents pending. Product names and markings noted herein may also be covered by one or more United States, international or foreign trademarks.

  • This document is written in English but may be translated into multiple languages for reference. Only the English version of this document is the final and determinative format released by Diodes Incorporated.

LIFE SUPPORT

  • Diodes Incorporated products are specifically not authorized for use as critical components in life support devices or systems without the express written approval of the Chief Executive Officer of Diodes Incorporated. As used herein:
  • A. Life support devices or systems are devices or systems which:
  1. are intended to implant into the body, or
  2. support or sustain life and whose failure to perform when properly used in accordance with instructions for use provided in the labeling can be reasonably expected to result in significant injury to the user.
    • B. A critical component is any component in a life support device or system whose failure to perform can be reasonably expected to cause the failure of the life support device or to affect its safety or effectiveness.
    • Customers represent that they have all necessary expertise in the safety and regulatory ramifications of their life support devices or systems, and acknowledge and agree that they are solely responsible for all legal, regulatory, and safety-related requirements concerning their products and any use of Diodes Incorporated products in such safety-critical, life support devices or systems, notwithstanding any devices- or systems-related information or support that may be provided by Diodes Incorporated.
    • Further, Customers must fully indemnify Diodes Incorporated and its representatives against any damages arising out of the use of Diodes Incorporated products in such safety-critical, life-support devices or systems.

Documents / Resources

| DIODES AP33772 USB PD Sink Controller Raspberry Pi I2C Interface [pdf] User Guide
AP33772 USB PD Sink Controller Raspberry Pi I2C Interface, AP33772, USB PD Sink Controller Raspberry Pi I2C Interface, Raspberry Pi I2C Interface, Pi I2C Interface
---|---

References

Read User Manual Online (PDF format)

Read User Manual Online (PDF format)  >>

Download This Manual (PDF format)

Download this manual  >>

Related Manuals