- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
PSOC5, SPI Master. I think I am supposed to be clearing the RX Buffer, but it's not empty. Why?
Solved! Go to Solution.
- Labels:
-
PSoC 5 Device Programming
-
PSoC 5LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have created a project containing a SPI Master with 32Byte buffer. Following is the content of the SPIM_1_ClearRxBuffer(void)
void SPIM_1_ClearRxBuffer(void)
{
/* Clear Hardware RX FIFO */
while(0u !=(SPIM_1_RX_STATUS_REG & SPIM_1_STS_RX_FIFO_NOT_EMPTY))
{
(void) CY_GET_REG8(SPIM_1_RXDATA_PTR);
}
#if(SPIM_1_RX_SOFTWARE_BUF_ENABLED)
/* Disable RX interrupt to protect global veriables */
SPIM_1_DisableRxInt();
SPIM_1_rxBufferFull = 0u;
SPIM_1_rxBufferRead = 0u;
SPIM_1_rxBufferWrite = 0u;
SPIM_1_EnableRxInt();
#endif /* (SPIM_1_RX_SOFTWARE_BUF_ENABLED) */
}
In the function the number of characters in the buffer, SPIM_1_rxBufferRead and SPIM_1_rxBufferWrite are cleared but the content of the rxBuffer is not modified.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello DaMe_598781
Please share your project, or atleast the main file so that we can debug the problem at out end. Please refer this KBAArchiving a PSoC Creator Design for details on archiving a project.
Thanks and regards
Harigovind
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have created a project containing a SPI Master with 32Byte buffer. Following is the content of the SPIM_1_ClearRxBuffer(void)
void SPIM_1_ClearRxBuffer(void)
{
/* Clear Hardware RX FIFO */
while(0u !=(SPIM_1_RX_STATUS_REG & SPIM_1_STS_RX_FIFO_NOT_EMPTY))
{
(void) CY_GET_REG8(SPIM_1_RXDATA_PTR);
}
#if(SPIM_1_RX_SOFTWARE_BUF_ENABLED)
/* Disable RX interrupt to protect global veriables */
SPIM_1_DisableRxInt();
SPIM_1_rxBufferFull = 0u;
SPIM_1_rxBufferRead = 0u;
SPIM_1_rxBufferWrite = 0u;
SPIM_1_EnableRxInt();
#endif /* (SPIM_1_RX_SOFTWARE_BUF_ENABLED) */
}
In the function the number of characters in the buffer, SPIM_1_rxBufferRead and SPIM_1_rxBufferWrite are cleared but the content of the rxBuffer is not modified.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you - but can you elaborate? Why does the API call ClearRxBuffer() NOT clear the RX buffer?
Also, using the global functions you suggest - seems this only clears one byte. For example the description of BufferRead is "Receives buffer location of the last data read from the buffer by the API.". How would BufferRead = 0u clear the entire buffer?
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
On ClearRxBuffer()API only the read/write indices into the circular buffer are set accordingly, so that the software sees an empty buffer. The contents of the buffer remain unchanged until new data gets in.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
THanks - not at all clear from the data sheet... and why would SPIM_1_rxBufferRead = 0u; clear the buffer, not just one location?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When a circular buffer is implemented two indices rxBufferRead and rxBufferWrite are declared.
rxBufferWrite indicates the location where the last byte was written to.
rxBufferRead indicates the location where the last byte was read from.
rxBufferWrite increased when a byte is received from the SPI, and rxBufferRead increased when a byte is gotten from the buffer. So if the rxBufferRead is equal to the rxBufferWrite, it is assumed that there is no data in the buffer.
Please refer Circular buffer - Wikipedia for a generic information.