完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,我试图发送3字节的信息,然后填入3个垃圾字节,然后读取3个垃圾字节,然后读取剩下的3个有意义的字节。我的方法是正确的吗?如何改进呢?非常感谢:我使用的是DSPIC33 EP64 GP506和XC16编译器。
以上来自于百度翻译 以下为原文 Hello all , ı am trying to send 3 bytes of information, then stuff 3 trash bytes , then read 3 trash bytes and then read the 3 remaining meaningful bytes. Is my way correct way of doing this ? And how can it be improved ? Thanks a lot :) CLEAR_CS; SPI1BUF = device_address ; SPI1BUF = register_address ; SPI1BUF = length ; SPI1BUF = 0x00 ; // Sending 3 dummy bytes SPI1BUF = 0x00 ; SPI1BUF = 0x00 ; BQ_READ_BUFFER[0] = SPI1BUF ; // Reading 3 dummy bytes BQ_READ_BUFFER[0] = SPI1BUF ; BQ_READ_BUFFER[0] = SPI1BUF ; BQ_READ_BUFFER[0] = SPI1BUF ; BQ_READ_BUFFER[1] = SPI1BUF ; BQ_READ_BUFFER[2] = SPI1BUF ; ASSERT_CS; #define CLEAR_CS {LATBBITS.LATB0 = 0 ; __delay_us(2) ;} #define ASSERT_CS {__delay_us(2) ; LATBBITS.LATB0 = 1 ;} I am using DSPIC33EP64GP506 and xc16 compiler. |
|
相关推荐
11个回答
|
|
然后增强函数来处理所有可能的错误。幸运的是没有重大事故发生。
以上来自于百度翻译 以下为原文 And then enhance the function to handle all the possible errors. Luckily no major SPI errata. |
|
|
|
你能给我看看SPI错误检测机制代码片段吗?
以上来自于百度翻译 以下为原文 Can you please show me any SPI error detection mechanism code snippet ? |
|
|
|
查看MCU的数据表,(通常)在SPI状态寄存器中,当硬件检测到错误情况时,将设置一些错误标志。从一个设备到另一个设备,可以检测到什么类型的错误。大多数情况下,错误条件只能由固件重置,也可以阻止外围设备的操作。如何处理错误情况取决于它是什么以及对你有多重要。例如,如果你得到了一个溢出错误(这意味着你没有读之前收到的值在下一个接收之前),那么这可能是一个主要的问题给你-例如,你可能错过了一个请求重新启动一些起搏器,因此,他们可能会死-或者它可能没有任何缺点。你将再次发送数据,因为你没有以某种方式回应缺失的值。苏珊
以上来自于百度翻译 以下为原文 Look at the data sheet for the MCU and (typically) on the SPI status register there will be some error flags that will be set when the hardware detects an error condition. What type of errors are detected can vary from once device to another. Most often the error conditions can only be reset by your firmware and can also stop the peripheral from operating. How you handle an error condition depends on what it is and how important that is to you. For example, if you get an overrun error (which means that you have not read a previously received value before the next one is received) then that may be a major problem to you - e.g. you could have missed a request to restart someones pacemaker and they therefore may die - or it may be of no consequence - you will be sent the data again because you have not responded to the missed value in some way. Susan |
|
|
|
注意,如果您在编写SSPBUF之前检查SPITBF,正如上面所述的代码所做的那样,那么主机就不可能获得溢出错误,因为所有时钟都是由主机控制的。在SPI,从设备比主设备需要更多地注意错误检查。
以上来自于百度翻译 以下为原文 Note, if you check SPITBF before writing to SSPBUF, as the code I posted above does, then it is impossible for the Master to get an overrun error, because all the clocking is controlled by the Master. In SPI, slave devices have to pay a lot more attention to error checking than Master devices do. |
|
|
|
读取健壮的代码和正确的代码。这只是等待失败。当然,如果硬件不会因为一些棕色、噪声、ESD事件……(SPI1STATSPATIOSP.SPITBF)而被破坏,那么它就可以工作了;如果这个位子永远不会到达这个条件,你的应用程序将挂起,应该有很多重试,并且基于SPI时钟和数据宽度进行等待。
以上来自于百度翻译 以下为原文 Read robust code vs correct code. This is just waiting to fail. Sure, it will work if the hardware never messes up because of some brown out, noise, ESD event, ... while (SPI1STATBITS.SPITBF); if that bit never gets to the condition, your application will hang, forever there should be a number of retries, and a wait based upon the SPI clock and the data width. |
|
|
|
|
|
|
|
你已经有了你自己的主题,关于PIC32上的SPI,在www. MICCHIP.COM/FUMMS/M1035691.ASPX,为什么你在XC16论坛中劫持了别人的话题,这甚至不适用于你的PIC?
以上来自于百度翻译 以下为原文 You already have your own topic asking about SPI on a PIC32 at www.microchip.com/forums/m1035691.aspx Why have you hijacked someone else's topic in the XC16 forum, which isn't even applicable to your PIC? |
|
|
|
|
|
|
|
SPI外设并不完全相同。PIC32 SPI外围设备具有比PIC16SSP或MSSP更多的特性,并且必须以不同的方式进行处理。如果您将问题保持在一个线程中,则更容易帮助您。
以上来自于百度翻译 以下为原文 SPI peripherals are NOT all the same. A PIC32 SPI peripheral has many more features than a PIC16 SSP or MSSP, and must be handled differently. It makes it much easier to help YOU if you keep your questions in one thread. |
|
|
|
检查“通信(EASART/AASART,I2C/SPI,USB,CAN,LIN,KeeLoq)”“外围/核心独立外设”论坛的子论坛。然而,正如QHB所说,外围设备是相同的,但也有不同的领域。家庭之间也存在差异,所以你必须查看合适的数据表和FRM部分,然后在最合适的论坛中提问。苏珊
以上来自于百度翻译 以下为原文 Check out the "Communications (EUSART/AUSART, I2C/SPI, USB, CAN, LIN, KeeLoq)" sub-forum of the "Peripherals/Core Independent Peripherals" forum. However, as qhb says, there are areas where the peripherals are the same but also areas where they differ. Also there can be variations between families so you must look at the appropriate data sheets and FRM sections and then ask in the most appropriate forum. Susan |
|
|
|
OK,我找到你了。注意,我仍然在论坛上寻找我的方向。掌握整个论坛结构需要花费一点时间。
以上来自于百度翻译 以下为原文 Oke, I got you. Note I still try to find my way on the forum. Getting grip of the overall forum structure takes a bit of time. |
|
|
|
只有小组成员才能发言,加入小组>>
5189 浏览 9 评论
2009 浏览 8 评论
1933 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3181 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2232 浏览 5 评论
746浏览 1评论
632浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
517浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
644浏览 0评论
544浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-30 17:32 , Processed in 1.253497 second(s), Total 68, Slave 61 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号