1 2 Previous Next 18 Replies Latest reply on Aug 6, 2019 4:10 AM by TaH_4345166

    How to configure SCB_SPI clock to 24MHZ in CY8CKIT-042 poineer Kit?

    sako_4328186

      spi_clk.PNGhow to configure SPIM_SCBCLK  to 24MHZ?

      can someone explain that on what parameter it depends on?

      i have research documents from Cypress, i didn't find a proper flow of solution.

       

      Thanks,

       

       

      SD

        • 1. Re: How to configure SCB_SPI clock to 24MHZ in CY8CKIT-042 poineer Kit?
          NoriakiT_91

          The SPIM_SCBCLK is an internal clock defined and used by the SPIM component. 

          Its frequency is a product of the "Data rate" and the "Oversampling"

          GS004361.png

          So, when the "Data rate" is set to 8Mbps and the "Oversampling" is set to 6, a 48MHz clock is desired by the SPIM component.

          GS004362.png

          But it is unavailable to provide a 48MHz clock to the SPIM component because the IMO clock is set to 24MHz in this case.

          Here the "Tolerance" parameter is effective.  The Tolerance is set to -100% to +2%  This means any clock frequency is acceptable lower than or equal to 102% of 48MHz.  So, PSoC Creator selects 24MHz which is the highest clock frequency made from existing clocks.

           

          Regards,

          Noriaki

          • 2. Re: How to configure SCB_SPI clock to 24MHZ in CY8CKIT-042 poineer Kit?
            TaH_4345166

            Hello Noriaki,

            That makes sense. Thanks for the quick response on this clock issue.

             

            But in the case explained below, we expect the “SPIM:sclk_m” to drive at 24MHz.

            But with this configuration of Data Rate = 8MBPS and Oversampling of 6, we are getting clock rate of 4MPBS as shown in below pic as Actual Data Rate I,e 4000 KBPS,

            https://community.cypress.com/servlet/JiveServlet/downloadImage/2-203188-399616/GS004361.png

             

            What are the other factors which affect the SPIM:sclk_m to drive low, like 4MPBS even though desired was 24MPBS?

             

            Please give us some configuration, which drives SPIM:sclk_m with 24MHz.

             

            • 3. Re: How to configure SCB_SPI clock to 24MHZ in CY8CKIT-042 poineer Kit?
              NoriakiT_91

              If you set the IMO frequency to 48MHz, you can use 8Mbps Data rate.  This is the maximum SCLK frequency using the SCB.

               

              If you want more fast SCLK, please consider to use the UDB version of "SPI Master" component.

              GS004365.png

              The maximum data rate is 12Mbps a little bit faster.

               

              Regards,

              Noriaki

              • 4. Re: How to configure SCB_SPI clock to 24MHZ in CY8CKIT-042 poineer Kit?
                TaH_4345166

                Any sample code examples available for the UDB version of "SPI Master" component?

                • 5. Re: How to configure SCB_SPI clock to 24MHZ in CY8CKIT-042 poineer Kit?
                  MoTa_728816

                  Hi,

                   

                  I just made one for CY8CKIT-042.

                  Since I'm using only 1 SPI, I connected MOSI (P2[0]) and MISO (P2[1]) to test.

                   

                  Schematic

                  001-schematic.JPG

                  SPIM Config (1)

                  002-SPIM_CONFIG1.JPG

                  SPIM Config(2)

                  Note: Although the default buffer size is 4, as I set num to send to 8, I made Buffer Size bigger (16).

                  003-SPIM_CONFIG2.JPG

                   

                  Pin assignment

                  004-Pin-list.JPG

                   

                  main.c

                  ==================

                  #include "project.h"

                  #include "stdio.h"

                   

                  char str[128] ; /* print buffer */

                  void print(char *str)

                  {

                      UART_UartPutString(str) ;

                  }

                   

                  void init_hardware(void)

                  {

                      UART_Start() ;

                      SPIM_Start() ;

                      CyGlobalIntEnable; /* Enable global interrupts. */

                  }

                   

                  void splash(void)

                  {

                      sprintf(str, "UDB SPI(Master) Loop Back Test (%s %s)\n", __DATE__, __TIME__) ;

                      print(str) ;

                  }

                   

                  #define TIMEOUT_MS 1000

                  #define RX_BUF_LEN 32

                  #define RX_BUF_LEN 32

                   

                  int main(void)

                  {

                      int offset = 0 ;

                      int i ;

                      uint8_t tx_buf[RX_BUF_LEN] ;

                      uint8_t rx_buf[RX_BUF_LEN] ;

                      int    tx_count, rx_count ;

                      int    num_to_send = 8 ;

                      int    timeout_count = 1000 ;

                    

                      init_hardware() ;

                    

                      splash() ;

                   

                      for(;;)

                      {

                          /* prepare data to send */

                          for (i = 0 ; i < num_to_send ; i++ ) {

                              tx_buf[i] = offset + i ;

                          }

                          tx_count = num_to_send ;

                          /* send data */

                          SPIM_PutArray(tx_buf, tx_count) ;

                          /* wait for the data to be sent */

                          while(SPIM_GetTxBufferSize() > 0) {

                              timeout_count++ ;

                              if (timeout_count >= TIMEOUT_MS) {

                                  print("SPIM Sending Timeout!\n") ;

                                  break ;

                              }

                              CyDelay(1) ; /* wait 1ms */

                          }

                        

                          /* receive data */

                        

                          rx_count = 0 ;

                          while(SPIM_GetRxBufferSize() > 0) {

                              rx_buf[rx_count] = SPIM_ReadRxData() ;

                              rx_count++ ;

                              if (rx_count >= RX_BUF_LEN) { /* overflow! */

                                  break ;

                              }

                          }

                        

                          print("Data  Sent  : ") ;

                          for (i = 0 ; i < tx_count ; i++ ) {

                              sprintf(str, "%02X ", tx_buf[i]) ;

                              print(str) ;

                          }

                          print("\n") ;

                        

                          print("Data Received: ") ;

                                  for (i = 0 ; i < rx_count ; i++ ) {

                              sprintf(str, "%02X ", rx_buf[i]) ;

                              print(str) ;

                          }

                          print("\n\n") ;

                        

                          CyDelay(2000) ; /* wait 2 sec */

                          offset++ ;

                          if (offset >= 20) {

                              offset = 0 ;

                          }

                      }

                  }

                  ==================

                   

                  Tera Term Log

                  000-tera_term.JPG

                   

                  moto

                  • 6. Re: How to configure SCB_SPI clock to 24MHZ in CY8CKIT-042 poineer Kit?
                    TaH_4345166

                    Hello Tanaka,

                    Thanks for the reply.

                     

                    I could verify the loopback behavior and it's working fine.

                     

                    But I am not getting any clock pulse on the pin-44 (P1.7) pin as configured for SCLK in this project.

                     

                    Are we missing anything here?

                    • 7. Re: How to configure SCB_SPI clock to 24MHZ in CY8CKIT-042 poineer Kit?
                      MoTa_728816

                      Hi,

                       

                      Actually it was me who was missing something.

                       

                      In CY8CKIT-042, pin-44 (P1[7]) is used for AREF and connected to a capacitor,

                      which means that this pin is not good for high frequency signal.

                       

                      But as I was doing loop back, PSoC actually did not care much about the SCLK...

                       

                      Anyway, I changed the SCLK to P2[2], which is next to MISO/MOSI

                      000-pin-list.JPG

                       

                      Now I can observe SCLK, although this oscilloscope is not quite fast enough...

                      TEK0003.jpg

                       

                      I'm sorry for the inconvenience.

                       

                      moto

                      P.S. I wonder how I could ended up using P1[7] for SCLK... orz

                      • 8. Re: How to configure SCB_SPI clock to 24MHZ in CY8CKIT-042 poineer Kit?
                        TaH_4345166

                        Thanks. That worked.

                         

                        Actually I had a doubt but couldn't get anything on UDB discerption.

                         

                        And one more thing. From where we can get this UDB code examples? Because I can see only SCB code examples from my creator IDE!

                        • 9. Re: How to configure SCB_SPI clock to 24MHZ in CY8CKIT-042 poineer Kit?
                          MoTa_728816

                          Hi,

                           

                          > That worked.

                          I'm glad hearing that!

                           

                          > And one more thing. From where we can get this UDB code examples?

                          IMHO, Cypress Developer Community (aka here) and KBA should be the best place to search.

                           

                          But as you already know, we are not always lucky enough to find an expecting sample.

                          In such case, what I usually do is/are

                          (1) Read the component datasheet, which we can open the components' catalog.

                          010-Open_datasheet.JPG

                           

                          I think that the component datasheet is the most complete and reliable information for the component.

                          Especially it matters when there is/are difference(s) between UDB component and SCB component.

                          011-Datasheet.JPG

                          011-Datasheet_API_Function.JPG

                          (2) Having said that still I must admit that usually I refer to the generated source itself.

                             So for this case, SPIM.h and SPIM.c

                           

                          SPIM.h, with the header we can see what kind of APIs are available.

                          012-SPIM_h.JPG

                          Then I read the SPIM.c, I like the way Cypress Programmers comment their code.

                          They usually list choices of parameter (defined ones), which help me a lot to write code(s).

                          013-SPIM_c.JPG

                           

                          (3) And the last but not the least, they recently opened "Community Code Examples" area.

                          Community Code Examples

                           

                          Not only there is/are examples, I think that you can request an example there.

                           

                          Well, can we call it a day?

                           

                          moto

                          • 10. Re: How to configure SCB_SPI clock to 24MHZ in CY8CKIT-042 poineer Kit?
                            sako_4328186

                            Hi,

                            Thanks for the Great help..!

                            Everything is working fine, but here we are just following Polling mechanism means, we are not expecting any data or response from Slave, so MISO pin is not required.

                            As per sample code which you referred, MISO is not required and it is configured to some GPIO. we want to use same GPIO for some other purpose.

                            i tried to delete the pin from top design but its throughout an error.

                            please help us, if anything is possible as per our requirement.

                             

                             

                             

                            Deepthi

                            • 11. Re: How to configure SCB_SPI clock to 24MHZ in CY8CKIT-042 poineer Kit?
                              MoTa_728816

                              Hi,

                               

                              I tried following two cases, both could be compiled.

                              May be (1) uses less resource, I suppose.

                               

                              (1) Connect logic '0'

                              001-grounded.JPG

                              (2) Loop back MOSI to MISO

                              002-looped.JPG

                               

                              moto

                              • 12. Re: How to configure SCB_SPI clock to 24MHZ in CY8CKIT-042 poineer Kit?
                                TaH_4345166

                                Hi Tanaka,

                                Thanks for the reply.

                                 

                                In both the cases mentioned above, MISO pin will be configured but only the input varies.

                                 

                                But, is it possible to remove the MISO pin completely from the design so that we can use that pin for some other purpose instead of SPI data.

                                 

                                We require only 2 line CLK & MOSI for this SPI. IS it possible? If so, then how to remove this MISO form design?

                                • 13. Re: How to configure SCB_SPI clock to 24MHZ in CY8CKIT-042 poineer Kit?
                                  MoTa_728816

                                  Hi,

                                   

                                  > In both the cases mentioned above, MISO pin will be configured but only the input varies.

                                  That is odd.

                                   

                                  In my project, the pin list showed

                                  003-pin-list.JPG

                                   

                                  Have you tried to Clean and Build?

                                  Or at least "generate application" again?

                                   

                                  moto

                                  • 14. Re: How to configure SCB_SPI clock to 24MHZ in CY8CKIT-042 poineer Kit?
                                    TaH_4345166

                                    Even in my project, I can see MISO is deleted in pin sections. But Getting below error.

                                     

                                    Here is my Top design.

                                    Errors getting:

                                    I am suspecting that, below configuration from SPI block is throwing the error.

                                     

                                    Is it possible to overcome this error?

                                    1 2 Previous Next