Arduino+模拟发现(UART)

2024-06-26 00:20:40 发布

您现在位置:Python中文网/ 问答频道 /正文

为了解决这个问题,我要发疯了:我需要配置我的模拟发现来读取PC通过RX引脚发送给Arduino的数据。PC和Arduino通过UART协议标准进行通信,有1个起始位、8个数据位和1个停止位。我试着用分频器对RX引脚上的信号进行采样。在

问题:通过模拟发现进行的样本读取是否传输了真实的位值?我必须用一个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]

[...]

谢谢支持!在


Tags: oftheinforthiscommandintwe