完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我正在把一个老的MPLABX项目改编成和声框架。这个项目有两个函数,即SpReWreByTE()和SpReByTyter(),它允许在SPI接口上写入/读取一个字节。现在我遇到了一些问题。MHC中的SPI配置是阻塞模式-轮询模式-主模式-标准缓冲模式- 8位模式,而我的代码ISI在这里看到了一个例子,在“DrvISPixBuffEdReCuffe2函数”部分。上面的代码不起作用,我不明白为什么。谁能给我一个例子来写一个字节或者告诉我为什么我的函数不起作用?
以上来自于百度翻译 以下为原文 I'm adapting an old MPLABX project to the HARMony framework. This project had two functions, SPIWriteByte() and SPIReadByte(), which allow to write/read one byte over the SPI interface. Now in Harmony I have some problem. The SPI configuration in the MHC is - Blocking Mode - Polled Mode - Master Mode - Standard Buffer Mode - 8-bit Mode and my code is appData.spi0Handle = DRV_SPI_Open(DRV_SPI_INDEX_0, DRV_IO_INTENT_READWRITE|DRV_IO_INTENT_BLOCKING); DRV_SPI_BUFFER_HANDLE bufferHandle, bufferHandle2; unsigned char SPIWriteByte(unsigned char byte) { bufferHandle = DRV_SPI_BufferAddWrite2(appData.spi0Handle, &byte, 1, NULL, NULL, &bufferHandle2); if((bufferHandle2 != DRV_SPI_BUFFER_HANDLE_INVALID) && (DRV_SPI_BUFFER_EVENT_COMPLETE & DRV_SPI_BufferStatus( bufferHandle2 ))) return 1; else return 0; } //This is a simple main loop while(1) { ADS_CHIP_SELECT_Assert(); SPIWriteByte(0x20); ADS_CHIP_SELECT_Deassert(); } I saw an example in the "DRV_SPI_BufferAddWrite2 Function" section here. The above code doesn't work and I don't understand why. Can anyone show me an example to write a single byte or tell me why my function doesn't work? |
|
相关推荐
5个回答
|
|
在SPI中没有单独的读写,每一个事务都是一个传输,所以在现实中:SpWristeByTE()意味着“发送这个字节,然后扔掉返回的东西”,并且SpReByByter()意味着“发送一个哑值,然后给我返回的内容”。对于SPITran有一个单一的函数就更加透明了。也就是说,你不需要使用和声函数。对于像SPI这样的简单外围设备,如果你有工作代码,只要使用它。如果你需要排队发送数据,你只想使用和声方法,并且在它发生的时候做别的事情。就是“非阻塞”意味着什么。
以上来自于百度翻译 以下为原文 There is no separate read or write in SPI, every transaction is a transfer, so in reality: SPIWriteByte() means "send this byte, and throw away what comes back", and SPIReadByte() means "send a dummy value, then give me what comes back". It's much more transparent to have a single function for SPITransferBytes(), and call it appropriately. Also, you do not HAVE to use the Harmony functions. For simple peripherals like SPI, if you have working code, just use it. You'd only want to use the Harmony approach if you needed to queue up data to be sent, and do something else while it is happening (which is what "non-blocking" means). |
|
|
|
是的,我知道。事实上,我的老函数使用了一个简单的传输子例程,比如:你告诉我,SPI驱动程序仅仅是为了大量数据吗?使用小数据的和声功能背后的问题是什么?无论如何都有可能吗?不过,谢谢你的建议。
以上来自于百度翻译 以下为原文 Yes, I know. In fact my old funcions uses a simple transfer sub-routine like this: unsigned char TransferByteOverSPI2(unsigned char data) { while(SPI2STATbits.SPITBF); SPI2BUF = data; while(!SPI2STATbits.SPIRBF); return SPI2BUF; } So are you tell me that the SPI driver in Harmony is only for large ammount of data? What are the issues behind the use of Harmony function for small data? Is it anyway possible? However, thanks for the suggestion. |
|
|
|
这是一个古老的“使用推土机来捉蝴蝶”综合症。如果你有什么有用的东西,为什么要换成一些别人不了解你的需求的错误代码。
以上来自于百度翻译 以下为原文 It's the old "use a bulldozer to catch a butterfly" syndrome. If you have something that works, why change to some overblown, bug ridden bit of code written by someone else, who has no understanding of YOUR requirements. |
|
|
|
好了,我明白了!我对和谐是新的,我想借此机会了解SPI驱动程序是如何工作的。
以上来自于百度翻译 以下为原文 Ok, I got it! I'm new to Harmony and I wanted to take this opportunity to understand how the SPI Drivers work. |
|
|
|
上面提到的代码应该工作。在MHC中是否配置了正确的SPI实例?波特率是多少?你的硬件设置正确吗?你看到BuffrStand了吗?
以上来自于百度翻译 以下为原文 @thoraz the mentioned code should work. have you configured correct SPI instance in MHC? whats ur baud rate? is ur hardware setup correct? did u see BufferStatus? |
|
|
|
只有小组成员才能发言,加入小组>>
5238 浏览 9 评论
2028 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3204 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
776浏览 1评论
665浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
594浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
675浏览 0评论
575浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-22 21:44 , Processed in 1.469610 second(s), Total 55, Slave 48 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号