请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:PCM9211 工具与软件:
您好!
这是我用于通过 I2C 接口对 PCM9211进行编程的脚本。 作为 I2C 主设备、我使用 Digital Discovery 器件:
from ctypes import *
from dwfconstants import *
import time
I2C_freq = 100e3
SCL_PIN = 24 # Change if needed
SDA_PIN = 25 # Change if needed
I2C_ADDR_MAX98089 = 0x10
I2C_ADDR_PCM9211 = 0x40
I2C_ADDR = I2C_ADDR_PCM9211
dwf = cdll.dwf
hdwf = c_int()
iNak = c_int()
dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf))
if hdwf.value == hdwfNone.value:
print("failed to open device")
quit()
dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(1), c_int(0), c_double(3.3))
dwf.FDwfAnalogIOEnableSet(hdwf, c_int(True))
print("Configuring I2C...")
iNak = c_int()
dwf.FDwfDigitalI2cRateSet(hdwf, c_double(I2C_freq))
dwf.FDwfDigitalI2cSclSet(hdwf, c_int(SCL_PIN))
dwf.FDwfDigitalI2cSdaSet(hdwf, c_int(SDA_PIN))
dwf.FDwfDigitalI2cClear(hdwf, byref(iNak))
if iNak.value == 0:
print("I2C bus error. Check the pull-ups.")
quit()
time.sleep(1)
#Configure PCM9211
# 1. To enable DIT Standalone Mode, set Register 0x6F = 0x05
DIT_Standalone_Mode_En = (0x6F, 0x05, "Enable DIT Standalone Mode, MPIO_C3 = TXDIN, MPIO_C1 = TXBCK, MPIO_C2 = TXLRCK")
# 2. Set master clock XMCKO as XTI/2, i.e. 12.288 MHz
Master_CLK_Freq = (0x24, 1<<2, "Set master clock to 12.288MHz")
# 3. Enable S/PDIF on MPO0 and XMCKO on MPO1 (p. 111)
MPO0_DITOUT = (0x78, 0x0D | 0x0C << 4, "Route DIT Output (TXOUT) to MPO0 and XMCKO to MPO1")
# 4. Select RXIN0 as the S/PDIF Input (DIR)
DIR_RXIN0 = (0x34, 0x00, "Select RXIN0 as input for DIR")
# 5. Route DIR Output to Main Output Port (MOP)
MOP_DIR = (0x6B, 0x01, "Route DIR Output to Main Output Port (MOP)")
Config_PCM9211 = (DIT_Standalone_Mode_En, Master_CLK_Freq, MPO0_DITOUT, DIR_RXIN0, MOP_DIR)
for reg_addr, reg_value, comment in Config_PCM9211:
data = (c_ubyte*2)(reg_addr, reg_value)
dwf.FDwfDigitalI2cWrite(hdwf, c_int(I2C_ADDR<<1), data, c_int(2), byref(iNak))
if iNak.value != 0:
print("Device power NAK "+str(iNak.value))
quit()
else:
print(comment)
dwf.FDwfDeviceCloseAll()
以下是输出:
========== 重新启动:C:\Users\pyoha\Documents\work\Python_scripts\programming_motherboard_over_i2c.py ====
正在配置 I2C...
启用 DIT 独立模式、MPIO_C3 = TXDIN、MPIO_C1 = TXBCK、MPIO_C2 = TXLRCK
将主时钟设置为12.288MHz
将 DIT 输出(TXOUT)路由到 MPO0并将 XMCKO 路由到 MPO1
选择 RXIN0作为 DIR 的输入
路由 DIR 输出至主输出端口(MOP)
但当我尝试测量 PCM9211的 MPO1引脚处的信号时(使用 Digilent Waveforms 软件的"Logic"接口)、我看不到任何信号...但希望看到12.888MHz。
