2 Replies Latest reply on Aug 4, 2020 8:10 AM by LePo_1062026

    Controlling PSoC6 SPI

    LePr_1339861

      I am adding an LCD to the CY8CKIT-062-WIFI-BT board which uses both SPI and parallel interfaces. Initialization must be done with the SPI. I am advised that the Cypress EmWin implementation for this display controller is missing the init code. I have added the SCB_SPI_PDL component, but the ways of talking to it seem higher level than the initialization code provided by the LCD vendor provided, below is the SPI code. My question is, are there ways to talk to the SPI similar to the low level way they are doing it (actually setting and clearing the signals), r is there a better (but simple) way? Any thoughts are appreciated.

       

      void write_command (unsigned char y) // (uchar y,uchar x)

      {

        unsigned char i;

      csb=0;

      sclb=0;

      sdi=0;

      sclb=1;

      for(i=0;i<8;i++)

          {

           sclb=0;     

            if (y&0x80)

             {

                sdi=1;

              }

                else

               {

                sdi=0;

               }

             sclb=1;

            y=y<<1;

          }

      csb=1;

      }

      //------------------------

      void write_data(unsigned char w) // (uchar w, uchar v)

      {

        unsigned char i;

      csb=0;

      sclb=0;

      sdi=1;

      sclb=1;

      for(i=0;i<8;i++)

      {

        sclb=0;

           if (w&0x80)

           {

              sdi=1;

             }

                else

              {

               sdi=0;

              }

         sclb=1;

         w=w<<1;

          }

      csb=1;

      }

        • 1. Re: Controlling PSoC6 SPI
          EktaN_26

          Hello LePr_1339861

           

          The SPI(SCB) PDL has APIs for writing the data. You can straight away use the existing API to transfer the data instead of implementing the function yourself. For example if you want to transfer the data to the  SPI slave you can use the following API:

           

           

          Please refer to PSoC 6 Peripheral driver Library: PSoC 6 Peripheral Driver Library: SPI (SCB) which mentions all details about using the SPI component. You can refer to the code snippets for configuring the SPI in the beginning.

           

          You can also refer to the following code example that demonstrates the use of SPI SCB (Serial Communication Block) Component for PSoC® 6 MCU in master mode: https://www.cypress.com/documentation/code-examples/ce221120-psoc-6-mcu-spi-master

           

          Kindly let me know if you have any further queries related to this.

           

          Best Regards

          Ekta

          • 2. Re: Controlling PSoC6 SPI
            LePo_1062026

            LePr,

             

            I believe the reason that Seegar (the creators of the EmWin) library did not provide an initialization routine is that depending on the display IC involved (eg. the ST7789, ST7735, etc) these init commands might be different.  This includes your application specific setup like the screen size (eg 240x320 pixels) and display orientation (eq Portrait or Landscape).

             

            As Ekta indicated using the Cypress SPI APIs are best if you can use them.  It does the hard work of the HAL (HW Abstraction Layer) calls to the actual PSoC registers.

             

            Len