scorpia
Posts: 18
Joined: Mon Oct 08, 2018 10:54 am

Reading AN1/AN2 from MxL7704

Sun Jul 14, 2019 1:46 pm

Does anyone know if there is the capability to read AN1/AN2 on the MxL7704 IC from userspace in order to determine the Type-C current available to the pi. I believe the I2C interface to the IC is controlled directly by the low level firmware so would assume there would need a vgencmd function to read this data.

trejan
Posts: 135
Joined: Tue Jul 02, 2019 2:28 pm

Re: Reading AN1/AN2 from MxL7704

Sun Jul 14, 2019 3:55 pm

I have this particular RPi 4 powered via a USB A to USB C cable so 56K Rp and no Rd. The reading is about right to indicate that.

# vcgencmd measure_volts usb_pd
volt=0.4000V

ain1 is actually AN0 which is connected to the neighbouring AGND pin.

# vcgencmd measure_volts ain1
volt=0.0100V

You can query the internal temperature sensor of the PMIC as well.

# vcgencmd measure_temp pmic
temp=49.6'C

scorpia
Posts: 18
Joined: Mon Oct 08, 2018 10:54 am

Re: Reading AN1/AN2 from MxL7704

Tue Jul 16, 2019 9:49 pm

Thanks for that. As the pi doesn't have /sys/class/typec/ support yet I have turned this into a basic script to determine the available Type-C current on the pi, have posted below for anyone else who might find it usefull.

Code: Select all

#!/usr/bin/python3

import subprocess

def getCCvoltage():
    vcgenresult = subprocess.run(["vcgencmd","measure_volts","usb_pd"],capture_output=True)
    return(float(vcgenresult.stdout[5:-2]))

def getTypeCCurrent():
    voltage = getCCvoltage()
    if(voltage < 0.2):
        return ("Disconnected",0)
    if(voltage < 0.66):
        return ("Default USB current",0.5)
    if(voltage < 1.23):
        return ("Type C current 1.5A",1.5)
    return ("Type C current 3.0A",3.0)


print(getTypeCCurrent()[0])

Return to “Interfacing (DSI, CSI, I2C, etc.)”