我要疯了才能解决这个问题:我需要配置我的 Analog Discovery 以读取 PC 通过 RX 引脚发送到 Arduino 的数据。PC和Arduino通过UART协议标准进行通信,具有1个起始位、8个数据位和1个停止位。我尝试使用模拟发现频率的分频器对 RX 引脚上的信号进行采样。
问题:Analog Discovery 读取的样本是传输的真实位值吗?我必须使用 1 位样本逐位读取数据,还是有一种方法可以使用 10 位样本以 1/10 的实际波特率读取所有 8(+2)位?
第二个解决方案有一部分python脚本代码:
[...]
# baud rate for arduino uno is 9600 / 10 byte
# sample rate = system frequency / divider, 100MHz/104166.6p = 960Hz
dwf.FDwfDigitalInDividerSet(hdwf, c_int(104166))
# with this command we setup the incoming frame on 10 bit
dwf.FDwfDigitalInSampleFormatSet(hdwf, c_int(10))
# we instantiate a pool of 10 samples
cSamples = 10
rgwSamples = (c_uint8*cSamples)()
dwf.FDwfDigitalInBufferSizeSet(hdwf, c_int(cSamples))
# disable auto trigger
dwf.FDwfDigitalInTriggerAutoTimeoutSet(hdwf, c_double(0))
# one of the analog in channels
dwf.FDwfDigitalInTriggerSourceSet(hdwf, trigsrcDetectorDigitalIn)
# with this command, we demand for a sampling after trigger in a buffer
# which has same specified size
dwf.FDwfDigitalInTriggerPositionSet(hdwf, c_uint(cSamples))
#dwf.FDwfAnalogInTriggerConditionSet(hdwf, trigcondRisingPositive)
#With this command we setup the falling edge triggered on the channel 0
#each field of the function is a bitmask
dwf.FDwfDigitalInTriggerSet(hdwf, 0, 0, 1, 0)
#give it the time for a breath!
time.sleep(1)
#let's begin the acquisition
dwf.FDwfDigitalInConfigure(hdwf, c_bool(0), c_bool(1))
while sts.value != stsDone.value:
dwf.FDwfDigitalInStatus(hdwf, c_int(1), byref(sts))
# get samples, byte size
dwf.FDwfDigitalInStatusData(hdwf, rgwSamples, cSamples)
samples = [0] * cSamples
rgpy=[0.0]*len(rgwSamples)
for i in range(0,len(rgpy)):
rgpy[i]=rgwSamples[i]
samples[i] = rgpy[i]
[...]
谢谢你的支持!