1 Reply Latest reply on May 16, 2019 3:58 AM by BragadeeshV_41

    PSoC 6 - SPI with two devices


      Good day. This is my first post. I have a problem with SPI communication. I am using PSoC 6 and would like to communicate it with two devices using SPI communication. Unfortunately, I do not know how to do it. I do not know how to give them ID numbers. My second question is how to send a structure using SPI? I want to communicate with PSoC 6 with Analog Devices AD converter model AD7177-2. I found sample libraries on GitHub but I can not use them. Please help.

        • 1. Re: PSoC 6 - SPI with two devices

          Hi user_349366,


          Welcome to the community.


          Did you get a chance to see the code examples we have in PSoC 6? If not please visit the following page:



          PSoC 6 SPI Master Code example:



          You need to select the no of SS pins to two and connect each SS pin to each on of the slave devices.


          Passing structure in SPI:


          typedef struct


              uint8 data1;

              uint8 data2[10];

              uint16 data3;

              uint16 data4[5];




          uint32_t WriteSPI ()


            cy_en_scb_spi_status_t errorStatus;

            TXBuffer dataBuf = {

                                  .data1 = 1,

                                  .data2 = {1,2,3,4,5,6,7,8,9,0xA},

                                  .data3 = 0xABCD,

                                  .data4 = {0x12CD,0x3412,0x2334,0x5634,0x7324}



          uint8_t statusRxBuf[sizeof(dataBuf)];


          errorStatus = Cy_SCB_SPI_Transfer(mSPI_HW, &dataBuf, statusRxBuf, sizeof(dataBuf), &mSPI_context);


            /* If no error wait till master sends data in Tx FIFO */

              if(errorStatus == CY_SCB_SPI_SUCCESS)


                  uint32_t masterStatus;      

                  /* Timeout 1 sec */

                  uint32_t timeOut = 1000UL;


                  /* Wait until master complete read transfer or time out has occured */



                      masterStatus  = Cy_SCB_SPI_GetTransferStatus(mSPI_HW, &mSPI_context);




                  } while ((0UL != (masterStatus & CY_SCB_SPI_TRANSFER_ACTIVE)) && (timeOut > 0UL));



                  if ((0UL == (MASTER_ERROR_MASK & masterStatus)) &&

                      (sizeof(dataBuf) == Cy_SCB_SPI_GetNumTransfered(mSPI_HW, &mSPI_context)))


                      status = TRANSFER_CMPLT;    








              return (status);