完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
问候语!我有2个UC通过SPI连接。当我通过逻辑分析仪观看通信时,从控制器的答案似乎是1位右移。例如,如果我必须传输0x10,在线路上有0x08。这是我的函数,它的值是:我做错什么了吗?我在传输方面有问题-有时主机正确接收值,有时不正确!谢谢!
以上来自于百度翻译 以下为原文 Greetings! I have 2 uC connected through SPI. When I`m watching the communication through my logic analyzer it seem the answers of the slave controller are shifted by 1 bit to the right. For example if I have to transmit 0x10 there is 0x08 on the line. Here is my function which loads the values: spi_buff[spi_buff_pointer]=SSP1BUF; PIR1bits.SSPIF=0; SSP1BUF=spi_outcome_buffer[spi_buff_pointer]; spi_buff_pointer++; Am I doing anything wrong? I have problems with the transfer - sometimes the master receives the values correctly, sometimes it doesn`t! Thanks! |
|
相关推荐
7个回答
|
|
您忽略了重要的位,SPI外设是如何在每个末端初始化的。
以上来自于百度翻译 以下为原文 You left out the important bit, how the SPI peripheral has been initialised at each end. |
|
|
|
对不起的!从PIC18F45 K50主机DSPIC30F5015
以上来自于百度翻译 以下为原文 Sorry! Slave PIC18F45K50 void SPI_Init() { INIT_SPI_IO(); SSPSTATbits.CKE=0; SSPSTATbits.SMP=0; SSP1CON1bits.CKP=0; SSP1CON1bits.SSPOV=0; SSP1CON1bits.SSPM=5; SSP1CON1bits.SSPEN=1; SSP1CON3bits.BOEN=1; INTCONbits.GIE=1; INTCONbits.PEIE=1; PIE1bits.SSPIE=1; IPR1bits.SSPIP=0;//SSP low priority unsigned char data=SSP1BUF; SSP1BUF=0; } Master dsPIC30F5015 void SPI2_Init() { INIT_SPI2_IO(); SPI2CONbits.FRMEN=0; SPI2CONbits.CKP=0; SPI2CONbits.CKE=0; SPI2CONbits.SSEN=0; SPI2CONbits.DISSDO=0; SPI2CONbits.MODE16=0; SPI2CONbits.SMP=1; SPI2CONbits.MSTEN=1; SPI2CONbits.PPRE=0; SPI2CONbits.SPRE=1; SPI2STATbits.SPIEN=1; } |
|
|
|
|
|
|
|
所以,你在两端运行CKE=0和CKP=0。当SCK信号上升时,从属器应该开始输出第一个数据位(比特7),并在SCK的第二个上升沿开始输出比特6。在第一个POST中的代码中,没有显示任何等待循环,以确保在发送下一个字节之前已经发送了字节。你发送的速度够慢吗?
以上来自于百度翻译 以下为原文 ok, so you are running CKe=0 and CKP=0 at both ends. The slave should start output the first data bit (Bit 7) when the SCK signal rises, and start outputting bit 6 on the second rising edge of SCK. What are you seeing on your analyser? In the code in your first post, you did not show any wait loop to make sure the byte has sent before you send the next one. Are you sending slow enough to be sure that's not needed? |
|
|
|
是的,我有足够的延迟。在我的分析器中,所有从奴隶发送的数据都像我刚才提到的那样移动。例如,如果奴隶必须发送0x10,我在分析仪中看到0x08…
以上来自于百度翻译 以下为原文 Yes, I have enough delay. if(SSP2_HasData()) { transmitionIncomeArray[transmitionArrayPointer]=SSP2_GetData(); Delay_us(50);//delay so the slave can reload its buffer SSP2_PutData(transmitionArray[transmitionArrayPointer]); transmitionArrayPointer++; } In my analyzer all data sent by the slave is shifted right as I mentioned. For example if the slave has to send 0x10, I`m seeing 0x08 in the analyzer... |
|
|
|
但是分析器设置了什么模式?它可能触发不同的边缘。忽略它显示的数字,并在看到数据行更改时报告。
以上来自于百度翻译 以下为原文 But what mode is the analyser set to? It may be triggering off a different edge. Ignore the number it displays, and report when you are seeing the data line change. |
|
|
|
主代码将SMP设置为1,因此它可能在错误的SCK转换中进行采样。苏珊
以上来自于百度翻译 以下为原文 The master code sets the SMP to 1 so it is probably sampling at the wrong SCK transition. Susan |
|
|
|
只有小组成员才能发言,加入小组>>
4842 浏览 9 评论
1845 浏览 8 评论
1757 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
2969 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2073 浏览 5 评论
467浏览 1评论
1122浏览 1评论
309浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
373浏览 0评论
270浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-5-9 16:58 , Processed in 1.072844 second(s), Total 88, Slave 72 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号