完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
也许有些拥有SPI经验的人可以轻松发现这一点。我有一个SPI从设备连接到我的STM8L152。我看到设备请求读取寄存器的时钟和数据流,然后我可以看到MISO线上返回的正确比特流。但是,我无法让STM8L的RX缓冲区正确读取。实际上,无论我在线上看到的位模式,它都很少改变。我已经尝试了两种相位极性,我相信时钟极性应该是“低空闲”。以下是代码的简短部分,仅使用标准库调用,遵循协议,据我所知,它来自用户手册(第549页,“全双工”)。我在最后一行后断行并读取返回的结果。欢迎任何建议。谢谢。
//通过SPI外设发送字节 SPI_SendData(SPI1,0x42); //循环,而DR寄存器不为空 while(SPI_GetFlagStatus(SPI1,SPI_FLAG_TXE)== RESET); //通过SPI外设发送冗余字节(响应第一次读取的时钟) SPI_SendData(SPI1,0x42); //等待接收一个字节 while(SPI_GetFlagStatus(SPI1,SPI_FLAG_RXNE)== RESET); //返回从SPI总线读取的字节 spiByte = SPI_ReceiveData(SPI1); #spi 以上来自于谷歌翻译 以下为原文 Maybe some of you with SPI experience can spot this one easily. I have a SPI slave device connected to my STM8L152. I watch the clock and data stream to the device requesting a read of a register, and then I can see the proper bit stream returned on the MISO line. However, I cannot get the STM8L's RX buffer to read the thing correctly. In fact, it rarely changes no matter what the bit pattern I see on the line. I have tried both phase polarities, and I am confident the clock polarity should be ''idle low''. Here is the short section of code, using only standard library calls, following the protocol as I understand it to be from the User's Manual (pg 549, ''full duplex''). I break on a line following the last and read the returned result. Any suggestions are welcome. Thanks. //send byte through the SPI peripheral SPI_SendData(SPI1, 0x42); //loop while DR register in not empty while (SPI_GetFlagStatus(SPI1, SPI_FLAG_TXE) == RESET); //send redundant byte through the SPI peripheral (clocks in response to first read) SPI_SendData(SPI1, 0x42); //wait to receive a byte while (SPI_GetFlagStatus(SPI1, SPI_FLAG_RXNE) == RESET); // Return the byte read from the SPI bus spiByte = SPI_ReceiveData(SPI1); #spi |
|
相关推荐
1个回答
|
|
嗨,MISO的问题是缺少大于0X80的数据,这意味着如果First Bit为1,那么STM8S将“忽略”它!(错过0x8F,但得到0x7F!)
我还是不明白为什么! 因为我尝试将设备转到STM32就好了! 以上来自于谷歌翻译 以下为原文 Hi, the problem of MISO is missing data that Larger than 0X80, it means if First Bit is 1,then STM8S will ''ignore'' it!(miss 0x8F, but get 0x7F!) I still can't understand WHY! Because I try that device to STM32 is fine! |
|
|
|
只有小组成员才能发言,加入小组>>
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
2669 浏览 1 评论
3224 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
1796 浏览 1 评论
3625 浏览 6 评论
6007 浏览 21 评论
953浏览 4评论
1324浏览 4评论
在Linux上安装Atollic TRUEStudio的步骤有哪些呢?
598浏览 3评论
使用DMA激活某些外设会以导致外设无法工作的方式生成代码是怎么回事
1317浏览 3评论
1376浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-3 03:26 , Processed in 1.763682 second(s), Total 76, Slave 60 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号