from machine import Pin, SoftSPI
import time
def ID(agreement):
#txbuf 需要将16进制转换为10进制
rxbuf = bytearray(3) # create a buffer
spi = SoftSPI(baudrate=200000, polarity=1, phase=0, mosi=Pin(16), miso=Pin(4), sck=Pin(2))
spi.init(baudrate=125000) # set the baudrate
CS = Pin(17, Pin.OUT) # create output pin on GPIO16
CS.value(1) # set pin to on/high
time.sleep(1)
CS.value(0) # set pin to on/high
txbuf =bytearray([16,0,0])
spi.write_readinto(txbuf, rxbuf) # write to MOSI and read from MISO into the buffer
CS.value(1) # set pin to on/high
return rxbuf
#采集P=AIN0 N=AIN1时候的电压
def GetADCValue(agreement):
#Rxbuffs = bytearray(3) # create a buffer
spi = SoftSPI(baudrate=200000, polarity=1, phase=0, mosi=Pin(16), miso=Pin(4), sck=Pin(2))
spi.init(baudrate=125000) # set the baudrate
CS = Pin(17, Pin.OUT) # create output pin on GPIO16
CS.value(1) # set pin to on/high
time.sleep(1)
CS.value(0) # set pin to on/high
#第4位设置电压采样输入p和n
txbuf =bytearray([15,81,0,1,252,0,1])
spi.write(txbuf)
txbuf =bytearray([0,0,0])
#读取三个字节
rxbuf=spi.read(3,0)
CS.value(1) # set pin to on/high
return rxbuf
逻辑分析仪波形
关注公众号不迷路