3 Replies Latest reply on Jun 14, 2016 1:56 AM by JoMe_264151

    SPI in Slave mode


      Hi all,


      I am trying to configure SPI in  PSoC 5 as Slave.


      Whenever I do get a byte of data from the Master, I need to immediately transmit the byte to the Master.


      The response to Master will change based on the data received from the Master.


      The following are the configuration of the SPI slave:

      • Enabled the Rx internal interrupt
      • CPHA = 0 and CPOL =0
      • 8 bit word
      • Tied a interrupt component to SPIS

      I am not able to get the interrupts and on the MISO line I am not able to see the data what I intended to transmit (Used an oscilloscope to check the data on MISO).


      Can anyone let me know, what is wrong?


      I have attached the project.

        • 1. Re: SPI in Slave mode

          For a bit rate of 12 Mbit/s your provided 2MHz clock will not work. Better to choose internal clock for the SPI slave.


          You set the internal interrupt which will handle all receive, but will not allow you to handle reading data from component. See the interrupts section in the datasheet.


          You fill your Tx buffer each time the interrupt handler is called which will burn lots of MIPS.


          I would suggest you to Increase the SPIS Rx and Tx buffers to 30bytes and let the component handle all the transfers automatically.


          You can use a callback macro for detecting the initial byte of 0x55 or 0xff and then filling the Tx buffer appropriately once. Look into datasheet for "SPIS_RX_ISR_ExitCallback" for the right callback macro name.


          Do not forget to clear the Rx Buffer after a complete transaction.





          • 2. Re: SPI in Slave mode

            Hi Bob,


            I am new to PSoC.


            Can you please let me know how callback macro is useful?


            Based on the contents of first few bytes received, the data to Master would get changed.


            How can this be done?

            • 3. Re: SPI in Slave mode

              Callback macros are explained in Creator Help. They are not interrupts, but may be an extension to a component interrupt. An example:


              I2C component has just a single interrupt that fires before any internal processing is done. But there are four (4) Calback macros defined that are called before and after the processing.