6 Replies Latest reply on Aug 14, 2019 6:08 PM by NoriakiT_91

    Why is my Rx Buffer Not cleared?

    DaMe_598781

      PSOC5, SPI Master. I think I am supposed to be clearing the RX Buffer, but it's not empty. Why?

        • 1. Re: Why is my Rx Buffer Not cleared?
          AH_96

          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

          • 2. Re: Why is my Rx Buffer Not cleared?
            NoriakiT_91

            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.

            1 of 1 people found this helpful
            • 3. Re: Why is my Rx Buffer Not cleared?
              DaMe_598781

              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.

              • 4. Re: Why is my Rx Buffer Not cleared?
                JoMe_264151

                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

                • 5. Re: Why is my Rx Buffer Not cleared?
                  DaMe_598781

                  THanks - not at all clear from the data sheet... and why would SPIM_1_rxBufferRead  = 0u;    clear the buffer, not just one location?

                  • 6. Re: Why is my Rx Buffer Not cleared?
                    NoriakiT_91

                    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.