完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
好的,伙计们。我想弄清楚如何在PIC18F2550上为SPI模块编写一个读取和其他写入功能,但它驱动我疯狂。BF:缓冲器满状态位(仅接收模式)。如果写和读是同时执行的操作,“接收MOD的目的是什么?”仅E)?好的,所以在发送/接收数据之后,BF设置为1,并保持设置,直到SPBUF被读取,对不对?我没有遇到任何问题的阅读功能,如下所示:相反,我遇到的问题在写功能。如果我这样写:我怎么能确信我没有覆盖SpBuf做一些类似的事情:在这个CASEWCOL被设置并且第二个传输没有启动。如果我错了,请纠正我。我怎样才能克服这个问题呢?我可以这样做:非常感谢你们!祝您有个美好的一天。。。还是夜晚?:)
以上来自于百度翻译 以下为原文 Ok guys. I'm trying to figure it out how to write a function for read and other for write on an spi module for the pic 18f2550 but it drives me crazy. BF: Buffer Full Status bit (Receive mode only) - If writing and reading are operations that are executed in the same time, what's the purpose of "(Receive mode only)"? Ok, so after transmitting/receiving the data, the BF is set to 1 and remains set until SSPBUF is read, right? I do not encounter any problems for the read function, exampled below: unsigned char SPI_read(void) // Read the received dataRead the received data { while ( !SSPSTATbits.BF ); // Wait for Data Receipt complete return (SSPBUF); } Instead I encounter problems at the write function. If I write it like this: void SPI_Write(unsigned char data) //Write data to SPI bus { SSPBUF = data; } How can I be sure I do not overwrite the SSPBUF doing something like: SPI_Write(0xaa); SPI_Write(0xbb); In this case WCOL is set and the second transmission does not start. Correct me if I'm wrong. How can I overcome this problem? can I do something like: void SPI_Write(unsigned char data) //Write data to SPI bus { while ( SSPSTATbits.BF ); SSPBUF = data; } main functions call: SPI_Write(0xaa); SPI_Read(); // dummy read to set BF to 0. SPI_Write(0xbb); Thank you guys so much! Have a nice day... or night? :) |
|
相关推荐
3个回答
|
|
因为SPI是(通常)全双工操作(它同时读写),所以我通常没有分离的读写功能。单个读写功能就足够了。始终读取SSPBUF寄存器,它将包含接收到的最后一个字节,然后用字节加载SSPBUF进行传输(新数据将同时接收)。您可以检查BF或SSPIF标志(在PIR1中),以确定最后的发送/接收操作是否完成。如果你只需要接收数据,然后发送一个“哑”字节(0xFF多次使用)。只发送,忽略接收到的数据。
以上来自于百度翻译 以下为原文 Because SPI is (in general) a full-duplex operation (it reads and writes simultaneously) I usually do not have seperate read and write functions. A single read/write function is sufficient. Always read the SSPBUF register, it will contain the LAST byte received, then load the SSPBUF with the byte to transmit (new data will be received at the same time). You can check the BF or SSPIF flag (in PIR1) to determine if the last transmit/receive operation has completed. If you just need to receive data then send a "dummy" byte (0xFF is used many times). To transmit only, ignore the received data. |
|
|
|
+ 1用一个同时写入和读取的函数来完成。
以上来自于百度翻译 以下为原文 +1 do it with a single function that writes and reads at the same time. |
|
|
|
这就是为什么其他PIC系列的SPI外设有更多的状态位,包括告诉你RX是否完成,如果Tx可以采取另一个字符。只要你坚持一个阻塞功能或中断驱动操作,事情就会很好地工作。对于一个阻塞函数,在交换完成之前不退出它,所以对函数的顺序调用总是OK。如果你进入中断驱动,那么中断只发生在交换完成之后,然后它将从下一个缓冲字符中设置。苏珊
以上来自于百度翻译 以下为原文 This is why the SPI peripheral on other PIC families have more status bits including ones that tell you if the RX has completed and if the Tx can take another character. As long as you stick to either a blocking function or an interrupt driver operation then things will work nicely. For a blocking function you don’t exit it until the exchange has completed so sequential calls to the function are always OK. If you go interrupt driven, then the interrupt only occurs after an exchange has completed so it will then set up from the next buffered character. Susan |
|
|
|
只有小组成员才能发言,加入小组>>
5250 浏览 9 评论
2037 浏览 8 评论
1958 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3218 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2266 浏览 5 评论
788浏览 1评论
681浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
610浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
685浏览 0评论
582浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-29 09:04 , Processed in 1.238782 second(s), Total 80, Slave 64 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号