4 Replies Latest reply on Mar 10, 2015 5:14 PM by adam.kadolph

    SPI Receive Buffer

              Handling the SPI Receive buffer on PSoC 5   
        • 1. Re: SPI Receive Buffer
                  I was writing some to interface with an SPI based LCD module. I was able to setup the SPI Master in mode 0 with no issues. The transmit data worked fine no issues, as verified with a scope and a logic analyzer. Its when i tried to receive data back from the SPI module that i had issues. I did some research and found out that there is a 4 byte hardware FIFO buffer with the option of adding an adjustable software buffer. I have used the SPI module before and i was able to send and receive single bytes of data ok. But in my LCD controller i need to send sometimes 5-6 bytes at a time (during the time the CS is asserted). I ran into issues with receiving the correct data from the buffer. If i am understanding the receive buffer correctly, i have to use the SPIM_ReceiveRxData() command to increase the buffer pointer. The hardware only buffer (FIFO set to 4 bytes by default), seems to be the easiest approach. But i have more than 4 bytes handling at once and i need to set the buffer to higher than 4 bytes. The issues i run when using the software based received buffer, is that i now have to poll the interrupt bits. Is that correct? I spent half a day at work messing around with the SPI on PSoC 5 and its a really pain. This is a borderline deal breaker. All i want to do is send variable lengths of data to an LCD via the SPI bus with a software controlled CS. I can actually see the data i need to read from the SPI bus on my logic analyzer but the internal buffer handlers wont allow me to access that data. Any suggestions?   
          • 2. Re: SPI Receive Buffer

            To tell exactly what goes wrong with your approach best would be to post your complete project,  so that we all can have a look at all of your settings. To do so, use
            Creator->File->Create Workspace Bundle (minimal)
            and attach the resulting file.


            • 3. Re: SPI Receive Buffer

              You are saying that you need to send 5 to 6 bytes to the LCD, but are worrying about receiving data. What data do you need to receive from the LCD module?


              For sending, the WriteTxData() call does take care of handling the Tx buffer correctly. if you give it 6 bytes, and use the hardware FIFO, it waits until 2 bytes got transmitted and returns then it placed the 6th byte in the FIFO.


              If you don't need the data returned from the LCD, just skip reading the Rx FIFO. If you indeed need it, you have two options:

              • use an ISR that gets called as soon as a byte is in the Rx FIFO, reads it and plces it to where you need it later on
              • use the internal ISR of the SPI component and define a read buffer that large enough to hold the data you need. That way you can complete the transaction, and read the data send by the LCD byte by byte afterwards

              (Probably option 2 is simpler, but you need to copy data twice)

              • 4. Re: SPI Receive Buffer
                        I attached my example code I have been working on. I ended up increasing the receive buffer to 6 bytes and then did several spi_read functions and it appeared to work. Let me know if there is a much better and efficient way to accomplish this.