2 Replies Latest reply on Feb 27, 2020 2:59 AM by AlCa_4650741

    SPI module in PsOc5 not working as expected.


      This is my first time working with any psoc device and I am having some problems trying to making the SPI module work.


      Here is the piece of code not working:


          SPI_LORA_WriteTxData(outval); 77 where outval = 0x01

          while (SPI_LORA_GetRxBufferSize()<1) ;

          return(SPI_LORA_ReadRxData() );


      Using the oscilloscope I was able to test that  "WriteTxData()" is actually writing data in the buffer, but somehow "GetRxBufferSize()" is returning 0 (where it should read '1' at some point, as far as I know), so the while loop does not break.

        • 1. Re: SPI module in PsOc5 not working as expected.



          Although I can not think of a reason why your issue is happening,

          I tried the following test with CY8CKIT-059.


          I could not observe your problem, so would you test your hardware with similar program?




          SPIM config








          #include "project.h"

          #include "stdio.h"


          #define STR_LEN 64

          char str[STR_LEN+1] ;

          void print(char *str)


              UART_PutString(str) ;



          void cls(void)


              print("\033c") ; /* reset */

              CyDelay(20) ;

              print("\033[2J") ; /* clear screen */

              CyDelay(20) ;



          void splash(void)


              cls() ;

              print("5LP SPI Test") ;

              snprintf(str, STR_LEN, "(%s %s)\n", __DATE__, __TIME__) ;

              print(str) ;



          void init_hardware(void)


              CyGlobalIntEnable; /* Enable global interrupts. */

              UART_Start() ;

              splash() ;


              SPIM_Start() ;



          int main(void)


              uint8_t outval = 0x01 ;

              uint8_t inval = 0 ;


              init_hardware() ;




                  SPIM_WriteTxData(outval) ;

                  while(SPIM_GetRxBufferSize() < 1) ;

                  inval = SPIM_ReadRxData() ;

                  snprintf(str, STR_LEN, "out: 0x%02X  -> in: 0x%02X\n\r", outval, inval) ;

                  print(str) ;

                  outval++ ;

                  inval = 0 ;

                  CyDelay(1000) ;





          Tera Term log

          (1) MISO and MOSI were open

          Note: I was not expecting the inval has same value with outval.

          Probably as I assigned MISO and MOSI to neighbor pins, they may have affected.


          (2) So I connected MISO to GND

          Note: inval is alwasy 0x00, which is what I expected.


          (3) Next I connected MISO to VDD

          Note: Don't keep this connection for a long time or add some resistor between VDD and the pin.




          • 2. Re: SPI module in PsOc5 not working as expected.

            Hi Moto, it was indeed the Rx and Tx buffer size in the lora module.


            Thank you so much.