如何使用spidev在树莓派上传输spi上的24位数据

时间:2021-03-17 13:00:20

标签: python spi raspberry-pi4

我正在尝试使用 python 中的 spi throw spiDev 在 Pi 和 ad5422 之间发送 24 位数据。输入移位寄存器为 24 位宽。在串行时钟输入 SCLK 的控制下,数据首先作为 24 位字加载到器件 MSB 中。数据在 SCLK 的上升沿输入。 输入寄存器由 8 个地址位和 16 个数据位组成。 24 位字在 LATCH 引脚的上升沿无条件地锁存。 例如发送数据:地址 0x01 ,数据:0x0148 =>0x010148 有谁知道我在做什么? 我的代码是:

import spidev
import time
import RPi.GPIO as GPIO            # import RPi.GPIO module
from time import sleep             # lets us have a delay 
GPIO.setmode(GPIO.BCM)             # choose BCM or BOARD
GPIO.setup(12, GPIO.OUT)           # set GPIO24 as an output



spi_bus = 3
spi_device = 0

spi = spidev.SpiDev()
spi.open(spi_bus, spi_device)
spi.max_speed_hz = 1000000

send_controll=0x55
send_data_ctrl1=0xb0
send_data_ctrl2=0x06

send_add=0x01
send_data=0x01
send_data=0x48

try:
     print("set GIOP high")
     #spi.xfer2([send_controll])
     spi.xfer2([send_controll,send_data_ctrl,send_data_ctrl2])
     GPIO.output(12, 1)
     sleep(0.01)
     GPIO.output(12, 0)

     sleep(0.5)
     spi.xfer2([send_add,send_data1,send_data2])
     GPIO.output(12, 1)
     sleep(0.01)
     GPIO.output(12, 0)
     
     print("end GIOP high")
     
except KeyboardInterrupt: # If CTRL+C is pressed, exit cleanly:
   print("Keyboard interrupt")

except:
   print("some error") 

finally:
   print("clean up") 
   GPIO.cleanup() # cleanup all GPIO 

 










但是没有用!

0 个答案:

没有答案
相关问题