Microchip
直播中

胡书琴

7年用户 209经验值
私信 关注
[问答]

为dsPIC33F实现MCP23S17的接口时无法获取spi所需的定时

您好,我正在尝试为dsPIC33F(找不到现成的驱动程序)实现MCP23S17的接口,我从数据表中无法理解spi所需的定时。如果它希望写8位数据或16位数据。我看到一些驱动程序在网上,有些只使用8位数据,而有些只使用8位数据。e其他16位数据,所以spi传输4个字节:tx[0]=0x40tx[1]=commandtx[2]=value tx[3]=value>8我不明白最后2个字节来自哪里,在数据表中没有对此的引用。我还看到其他驱动程序只使用一个字节作为数据(没有tx[3])。戴维

以上来自于百度翻译


      以下为原文

    Hello,

I am trying to implement interface for MCP23S17 for dsPIC33F (could not find ready implemented driver),
I could not understand from datasheet what's the required timing with spi.
Should it expect to write 8 bits data or 16 bits data.
I saw some drivers in net,  some are using only 8-bit data, while other 16 bit data, so that the spi transfer 4 bytes:
tx[0] = 0x40
tx[1] = command
tx[2] = value
tx[3] = value >> 8
I can't understand where these 2 last bytes come from, there is no reference for this in datasheet.
I also see that other driver use only one bytes for data (there is no tx[3]).

Best Regards,
David

回帖(6)

李铭鑫

2019-6-26 12:35:47
嗨,因为SPI总是有它自己的位时钟信号在单独的线/迹上,所以SCK引脚、精确定时并不重要,只要它不太快。MCP23S17的数据表规定了10MHz的最大值。dsPIC33中的SPI硬件通常有一个控制位以8位或16位模式操作。此外,MCP23S17具有内部控制以8位数据或16位序列操作。这对SPI信号线并不重要:当SPI数据传送时。r开始,通过设置/CS低,SPI传输是连续的比特序列,在字节或单词之间没有标点。如果从数组传输数据,则数据的排序可能根据8位或16位模式而受到影响。代码片段显示以8位字节数组构建缓冲区,这是在DSSPIC33中使用8位模式传输到MCP23 S17。“值”是软件中的16位或更长的整数变量。它应该包含要传送到端口扩展器的数据、控制寄存器设置或输出管脚数据。每次传送到MCP23S17时,可以传送1个或更多个数据字节,即一起传送3个或更多个字节。字节4和后续将如何解释,将取决于ICOON寄存器中的设置。

以上来自于百度翻译


      以下为原文

    Hi,
Since SPI always have it's own bit clock signal on a separate wire/trace, the SCK pin, precice timing do not matter, as long as it is not too fast. The datasheet for MCP23S17 specify 10 MHz maximum.
 
SPI hardware in dsPIC33 usually have a control bit to operate in 8 bit or 16 bit mode.
Also, the MCP23S17 have internal controls to operate either with 8 bit data or 16 bit sequences.
This do not matter to the SPI signal lines: when a SPI data transfer is started, by setting /CS low,
a SPI transfer is a contigous sequence of bits, with no punctuation between bytes or words.
If transferring data from an array, the ordering of data may be affected depending upon 8-bit or 16-bit mode.
 
The code snippet show building a buffer in a array of 8-bit bytes, this is for transfer to the MCP23S17 using 8-bit mode in the dsPIC33.
'value' is a 16 bit or longer integer variable in your software. It should contain the data you want to transfer to the port expander, control register settings or output pin data.
 
It is possible to transfer 1 or more data bytes in each transfer to the MCP23S17, that is 3 or more bytes together. How byte 4 and following will be interpreted, will depend upon settings in the IOCON register.
 
Regards,
   Mysil
举报

张娜

2019-6-26 12:48:52
嗯,“值”可以是一个或多个字节,这取决于命令,所以上述是有意义的…

以上来自于百度翻译


      以下为原文

    Hmmm, the "value" can be one or more byte, depending upon the command, so the above makes sense...
举报

张东群

2019-6-26 13:08:43
但是根据寄存器汇总(MCP23S17数据表),所有的寄存器都是8位的。那么,在8位大小的寄存器中写入16位的内容意味着什么?问候,戴维

以上来自于百度翻译


      以下为原文

     
But according to register summary (in MCP23S17 datasheet) all register are 8-bits only.
So, what does it means to write content of 16-bits in registers of 8-bit size ?
 
Regards,
David
举报

王焕树

2019-6-26 13:16:37
当IOCON.BANT位是明确的,寄存器成对分组,可以被视为16位。

以上来自于百度翻译


      以下为原文

    When the IOCON.BANK bit is clear, the registers are grouped in pairs which can be regarded as 16 bit.
 
举报

更多回帖

发帖
×
20
完善资料,
赚取积分