TI DAC8568 raspberry pi 上的 SPIDEV 未按预期运行

SPIDEV on raspberry pi for TI DAC8568 not behaving as expected

我在他们的 BOOST 分线板包装中有一个 Texas Instruments DAC8568。 DAC8568 是一款带有 SPI 接口的 8 通道、16 位 DAC。 BOOST 包具有连接到我的 raspberry pi 的接头,并且它具有连接到输出电压的 LED,因此您可以轻松检查您的代码是否按照您认为的那样进行。 DAC8568 的 BOOST 包和数据 sheet 的链接在我下面的 python 代码中。

我用 3.3V 电源、5V 电源(LED 需要)和地线连接到 raspberry Pi。 DAC的SCLK到Pi SCLK,DAC /SYNC(真的是芯片select)到Pi CE1,DAC /LDAC到Pi Gnd,DAC MOSI到Pi MOSI。我没有连接 DAC/CLR,但如果需要,我可以将其物理连接到地面以重置芯片。

我相信我的布线是好的,因为我可以使用 python 脚本或使用以下命令从终端点亮 LED:sudo echo -ne "\xXX\xXX\xXX\xXX" > /dev/spidev0 .1

我从这个视频中学到了终端技巧:https://www.youtube.com/watch?v=iwzXh2V1SP4

但我的问题是,根据数据 sheet,LED 没有像我期望的那样点亮。我应该点亮 A,但我点亮了 B。我应该点亮 B,但我点亮了 D,等等。我试图理解这一切,并且可以调暗 LED 并打开新的 LED,但从来没有像我这样真的希望它能根据数据sheet 工作。

下面是我的 python 脚本。在我提到的评论中,我在数据 sheet 中寻找要发送的位。我对使用模拟组件非常陌生,而且我不是 EE,所以也许我没有正确地计时,或者犯了一些其他愚蠢的错误。也许有人可以查看数据 sheet 并看到我的错误,而无需实际手持芯片。感谢您的帮助!

# -*- coding: utf-8 -*-
"""
Created on Sat Jul  8 16:33:05 2017

@author: pi

for texas instruments BOOST DAC8568
for BOOST schematic showing LEDs http://www.ti.com/tool/boost-dac8568
for DAC8568 datasheet:  http://www.ti.com/product/dac8568
"""


import spidev
import time

spi = spidev.SpiDev()  #create spi object
spi.open(0,1)  #open spi port 0, device (CS) 1
#spi.bits_per_word = 8  does not seem to matter
#spi.max_speed_hz = 50000000  #does not seem to matter

#you have to power the DAC, you can write to the buffer and later power on if you like
power_up = spi.xfer2([0x04, 0x00, 0x00, 0xFF]) #p.37 Table11 in datasheet: powers all DACS

voltage_write = spi.xfer2([0x00, 0x0F, 0xFF, 0xFF ]) #p.35 Table11 in datasheet supposed write A--but lights B
voltage_write = spi.xfer2([0x00, 0x1F, 0xFF, 0xFF ]) #supposed write B--but lights D
voltage_write = spi.xfer2([0x00, 0x2F, 0xFF, 0xFF ]) #supposed write C--but lights F
voltage_write = spi.xfer2([0x00, 0x3F, 0xFF, 0xFF ]) #supposed write D--but lights H
voltage_write = spi.xfer2([0x00, 0x4F, 0xFF, 0xFF ]) #supposed write E--but does nothing

spi.close() 

注意 以后的读者,上电需要打开内部参考,即

power_up = spi.xfer2([0x08, 0x00, 0x00, 0xFF]) #(p.37 datasheet

Comment: the bits are shifted. ... how ... compensate for the shift or eliminate the shift?

如果 SPIDIV.mode 与 DAC 不同步,可能会出现这种情况。

DAC Datasheet Page 6/7:
This input is the frame synchronization signal for the input data.
When SYNC goes low, it enables the input shiftregister, and data are sampled on subsequent SYNC falling clock edges.
The DAC output updates following the 32nd clock.

Reference: Clock polarity and phase

根据上面和时序图我得出的结论是SPDIV.mode == 2 是对的。

  1. 检查实际SPDIV.mode
  2. 改为SPDIV.mode = 2

我可以通过阅读 Table 11 第 35 页来确认您使用的值。
写入输入寄存器 - DAC 通道 X
我的示例设置特征位 = 0

            3         2         1
           10987654321098765432109876543210
           RXXXCCCCAAAADDDDDDDDDDDDDDDDFFFF
A = 32-bit[00000000000011111111111111110000]:0xffff0 ('0x00', '0x0f', '0xff', '0xf0')
            3         2         1
           10987654321098765432109876543210
           RXXXCCCCAAAADDDDDDDDDDDDDDDDFFFF
B = 32-bit[00000000000111111111111111110000]:0x1ffff0 ('0x00', '0x1f', '0xff', '0xf0')

Page 33: DB31(MSB) is the first bit that is loaded into the DAC shift register and must be always set to '0'.

接线看起来简单直接,但值得仔细检查。

来自测试的代码片段:

def writeDAC(command, address, data, feature=0x0):
    address = ord(address) - ord('A')
    b1 = command
    b2 = address << 4 | data >> 12          # 4 address Bits and 4 MSB data Bits
    b3 = data >> 4                          # middle 8 Bits of data
    b4 = 0xF0 & (data << 4) >> 8 | feature  # 4 data Bits and feature Bits
    voltage_write = spi.xfer2([b1, b2, b3, b4])

# Usage:
# Write Command=0 Channel=B Data=0xFFFF Default Features=0x0
writeDAC(0, 'B', 0xFFFF)