你好
我所使用的開(kāi)發(fā)板是從淘寶上muselab買(mǎi)的貴司的開(kāi)發(fā)板,usb轉(zhuǎn)uart/i2c/spi/jtag。我所使用的是SPI功能。
我用python簡(jiǎn)單寫(xiě)了個(gè)調(diào)用CH347DLL.DLL里面的兩個(gè)函數(shù)實(shí)現(xiàn)單字節(jié)的讀寫(xiě):
CH347.CH347StreamSPI4(dev_index,0x80,2,spi_buf)
CH347.CH347SPI_WriteRead(dev_index,0x80,2,spi_buf)
另外SPI的結(jié)構(gòu)體配置如下:
classspi_config(Structure):
_fields_=[
("iMode",c_ubyte),
("iClock",c_ubyte),
("iByteOrder",c_ubyte),
("iSpiWriteReadInterval",c_ushort),
("iSpiOutDefaultData",c_ubyte),
("iChipSelect",c_ulong),
("CS1Polarity",c_ubyte),
("CS2Polarity",c_ubyte),
("iIsAutoDeativeCS",c_ushort),
("iActiveDelay",c_ushort),
("iDelayDeactive",c_ulong),
]
CH347_spi_cfg=spi_config()
CH347_spi_cfg.iMode=0x00
CH347_spi_cfg.iClock=0x01
CH347_spi_cfg.iByteOrder=0x01
CH347_spi_cfg.iSpiWriteReadInterval=0x00
CH347_spi_cfg.iSpiOutDefaultData=0xff
CH347_spi_cfg.iChipSelect=0x80
CH347_spi_cfg.CS1Polarity=0x00
CH347_spi_cfg.CS2Polarity=0x00
CH347_spi_cfg.iIsAutoDeativeCS=0x01
CH347_spi_cfg.iActiveDelay=0x00
CH347_spi_cfg.iDelayDeactive=0x00
CH347.CH347SetTimeout(dev_index,0xffffffff,0xffffffff)
CH347.CH347SPI_Init(self.dev_index,pointer(CH347_spi_cfg))
目前情況是調(diào)用前面的兩個(gè)函數(shù)讀寫(xiě)是正常的,能夠正常讀寫(xiě)數(shù)據(jù),
但是測(cè)試時(shí)間(按上面的參數(shù)調(diào)用1W次上面的函數(shù),計(jì)算平均時(shí)間)時(shí),
發(fā)現(xiàn)調(diào)用CH347StreamSPI4/CH347SPI_WriteRead這兩個(gè)函數(shù),
都存在大概200us的延時(shí)才返回?cái)?shù)據(jù),
這樣的話導(dǎo)致SPI的各種頻率(64M/32M/16M/......400khz)設(shè)置都沒(méi)有意義,
都是花了差不多時(shí)間。發(fā)起SCK的的頻率確實(shí)是按照32Mhz去發(fā),
但是大部分時(shí)間都是啥都沒(méi)干,被浪費(fèi)掉了。
想請(qǐng)教下:
1.我前面的spi配置以及調(diào)用方法有問(wèn)題嗎?
2.如何提高效率?
PS1:使用的UART1+I2C+SPI(VCPMode)
PS2:中途沒(méi)有使用函數(shù)CH347OpenDevice/CH347CloseDevice
PS3:win10系統(tǒng)
謝謝