完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
在写一个字节到SPI之后,什么是推荐的方法来确保所有的位都被完全传输?我的应用程序只写(从不读取)。它还需要等待每个字节被完全发送,因为在每个字节之后,一个单独的硬件脉冲必须发送到接收器,这使得接收器处理接收到的字节。最初,我的写入和轮询看起来是这样的:但是上面的代码看起来是不可靠的。我认为这个问题是一个竞赛:在字节到达移位寄存器之前(即字节仍在FIFO中工作),可以很快轮询移位寄存器,在这种情况下,在字节被发送之前轮询结束。这种失败将是时间相关的,对ISRs正在运行的内容非常敏感。根据我的阅读,我得到的印象是,我应该轮询SPixType,如下:SPI文档只说SPICONTHOST=1意味着“SPI外围设备目前正忙于一些事务。”忙位保持设置,直到所有挂起的事务完成,经验表明这是真的。但是SPI文档没有说明什么时候比特被设置。在硬件有机会设置它响应缓冲区写入之前,是否可以很快轮询SPILASH?或者SpBiF的写入保证了SPICONT的设置?换句话说,SPI模块是否向SPIBUF写入并设置SPIBUSY atomic?请注意,我已经启用了FIFO,因为这是和谐设置它,但它没有获得任何东西,因为需要在每个字节之后等待。我使用的是PIC32 MZ1024ECG144。
以上来自于百度翻译 以下为原文 After writing a byte to SPI, what's the recommended method of polling to ensure that all its bits have been entirely transmitted? My application does writes only (never reads). It also needs to wait for each byte to be completely sent, because after each byte a separate hardware pulse must be sent to the receiver, which causes the receiver to process the received byte. Originally my write and polling looked like this: PLIB_SPI_BufferWrite(SPI_ID_1, data); while (!PLIB_SPI_TransmitBufferIsEmpty(SPI_ID_1)); while (!PLIB_SPI_FIFOShiftRegisterIsEmpty(SPI_ID_1)); // assume SPI transaction complete But the above code appears to be unreliable. I assume the issue is a race: it's possible to poll the shift register too soon, before the byte reaches the shift register (i.e. the byte is still working its way through the FIFO), in which case polling ends before the byte has been sent. This failure would be timing-dependent and sensitive to what ISRs were running etc. Based on my reading I get the impression that I should poll SPIBUSY instead, as follows: PLIB_SPI_BufferWrite(SPI_ID_1, data); while (PLIB_SPI_IsBusy(SPI_ID_1)); // assume SPI transaction complete The SPI doc says only that SPIBUSY = 1 means "SPI peripheral is currently busy with some transactions." I take this to mean that the busy bit remains set until all pending transactions are completed, and experience suggests this is true. But the SPI doc says nothing about when the bit becomes set. Is it possible to poll SPIBUSY too soon, before the hardware has had a chance to set it in response to the buffer write? Or does writing to SPIBUF guarantee that SPIBUSY is set? In other words, does the SPI module make writing to SPIBUF and setting SPIBUSY atomic? Note that I have the FIFO enabled, because that's how HARMony set it up, but it doesn't gain me anything, due to the need to wait after each byte. I'm using the PIC32MZ1024ECG144. |
|
相关推荐
7个回答
|
|
我通常知道当SPI传输完成的时候是RX完成的时候。我知道你提到你的应用程序只是TX,但是应该有一个断开的SDIX引脚和模拟RX。SpxBuf SHIL当然有垃圾,但是一旦RX完成,TX就必须完成。这就是我在我的应用程序中非常可靠地知道TX物理完成的。也许你可以修改你的应用程序,这样做…
以上来自于百度翻译 以下为原文 The way I typically know when the SPI transfer is completed is when the RX is completed. I know you mentioned that your application is TX only, but it should be possible to have a disconnected SDIx pin and mock a RX. The SPIRXBUF sill certainly have garbage in it, but once the RX is completed, the TX has to be completed. This is how I knew in my applications very reliably that the TX PHYSICALLY completed. Maybe you can modify your application to function as such... |
|
|
|
PIC32 MZ1024ECG144U有一个EC系列芯片,你检查了勘误表吗?您可能需要考虑EFG PIC32MZ芯片。
以上来自于百度翻译 以下为原文 PIC32MZ1024ECG144 You have an EC series Chip. Did you review the Errata? You would want to consider a EFG PIC32MZ chip. Look at PLIB_SPI_ReceiverBufferIsFull() since TX and RX happen at the same time if there is a byte/Word in the RX buffer the TX is Done |
|
|
|
NKurzman,我试着按照你的建议去做:但是它没有用:轮询接收缓冲器全循环。你知道为什么会这样吗?SPI模块需要配置不同吗?或者是因为远程设备实际上没有发送任何东西,所以硬件信号需要被欺骗吗?
以上来自于百度翻译 以下为原文 NKurzman, I tried doing as you suggest: PLIB_SPI_BufferWrite(SPI_ID_1, data); while (!PLIB_SPI_ReceiverBufferIsFull(SPI_ID_1)); PLIB_SPI_BufferRead(SPI_ID_1); But it doesn't work: the polling for receive buffer full loops forever. Any idea why that might be? Does the SPI module need to be configured differently? Or is that because the remote device isn't actually sending anything back, hardware signal(s) need to be spoofed? |
|
|
|
这将是一个配置问题。接收器不关心是否有任何数据。你把PPS设置为时钟引脚的输入和输出?
以上来自于百度翻译 以下为原文 It would be a configuration issue. The receiver does not care if the there is any data. Are you setting the PPS to the clock pin for in and out? |
|
|
|
通过PPS,我假设你是指外围引脚选择?我的SPI配置如下:SPI引脚被重新映射到其他地方:
以上来自于百度翻译 以下为原文 By PPS I assume you mean Peripheral Pin Select? My SPI configuration is as follows: PLIB_SPI_Disable(SPI_ID_1); PLIB_SPI_MasterEnable(SPI_ID_1); PLIB_SPI_SlaveSelectEnable(SPI_ID_1); PLIB_SPI_StopInIdleDisable(SPI_ID_1); PLIB_SPI_ClockPolaritySelect(SPI_ID_1, SPI_CLOCK_POLARITY_IDLE_LOW); PLIB_SPI_OutputDataPhaseSelect(SPI_ID_1, SPI_OUTPUT_DATA_PHASE_ON_ACTIVE_TO_IDLE_CLOCK); PLIB_SPI_InputSamplePhaseSelect(SPI_ID_1, SPI_INPUT_SAMPLING_PHASE_IN_MIDDLE); PLIB_SPI_CommunicationWidthSelect(SPI_ID_1, SPI_COMMUNICATION_WIDTH_8BITS); PLIB_SPI_FramedCommunicationDisable( SPI_ID_1 ); PLIB_SPI_AudioProtocolDisable(SPI_ID_1); PLIB_SPI_FIFOEnable( SPI_ID_1 ); PLIB_SPI_BaudRateSet(SPI_ID_1, SYS_CLK_PeripheralFrequencyGet(CLK_BUS_PERIPHERAL_2), SPI_CLK_FREQ); PLIB_SPI_Enable(SPI_ID_1); And the SPI pin is remapped elsewhere with: PLIB_PORTS_RemapInput(PORTS_ID_0, INPUT_FUNC_SDI1, INPUT_PIN_RPC14 ); |
|
|
|
好,我得到它与轮询接收缓冲区满。诀窍是禁用FIFO,例如:这样做是有效的,虽然也慢了100ns,可能是由于读取接收缓冲区的额外开销:但我最初的问题仍然是:SPIBUSY=0的轮询是否同样可以接受?
以上来自于百度翻译 以下为原文 OK I got it working with polling for receive buffer full. The trick was to disable the FIFO, e.g.: PLIB_SPI_FIFODisable( SPI_ID_1 ); So this works, though it's also about 100ns slower, presumably due to the additional overhead of reading the receive buffer: PLIB_SPI_BufferWrite(SPI_ID_1, data); while (!PLIB_SPI_ReceiverBufferIsFull(SPI_ID_1)); PLIB_SPI_BufferRead(SPI_ID_1); But my original question still stands: is polling for SPIBUSY = 0 equally acceptable, or not? |
|
|
|
延迟的一部分也可以是输出时钟与输入的时钟之间的最后半时钟。如果您没有真正地读取它们,那么就将它们设置为与FIFOPLIB_SPI_ReceiverFIFOIsEmpty()相同,但是您的应用程序不需要FIFONoteSPIxSTATbits.SRMT应该告诉您最后一位何时消失。我不能肯定忙碌的一点。PDF章可能在时序图中有更多的信息。
以上来自于百度翻译 以下为原文 Part of the delay could also be the last half clock between the time the output is clocked out and the input it clocked in. If you are not really reading them then set in and out to be the same. with the FIFO PLIB_SPI_ReceiverFIFOIsEmpty() But your application would not need the FIFO Note SPIxSTATbits.SRMT should tell you when the last bit is gone. SPIxCON2bits.IGNROV would need to be used if you do nor read the RX buffer. I am not sure about the Busy Bit. the chapter pdf may have more info in the timing diagrams. |
|
|
|
只有小组成员才能发言,加入小组>>
5184 浏览 9 评论
2005 浏览 8 评论
1932 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3179 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2230 浏览 5 评论
742浏览 1评论
628浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
512浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
640浏览 0评论
538浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-28 19:21 , Processed in 1.423084 second(s), Total 89, Slave 73 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号