10 Replies Latest reply on Dec 14, 2018 5:23 AM by AnjanaM_61

    SPI issue with CYW920719

    georgepvs_3453826

      Hello,

      I have 2 boards: CYW920719Q40EVB-01 and I have set one as an SPI master and the second as an SPI slave following the examples from wiced studio 6.2. The SPI comms between the two boards worked..So far so good!

       

      Problem Description:

      Now I want to use one board as a master and to speak with real peripherals (sensors). I chose the bosch BMP280 which also works with SPI and wrote the simplest possible code to speak with it (just to read out the ID register (0XD0),which suppose to reply back with 0X58. No matter what I do the BMP280 does not reply back.

       

      Of course the first thing to do is suspect the sensor since the two cypress boards work together. So I have tested the sensor with an arduino and it works fine, it replies straight back no sweat!

       

      The setting up of the sensor is as correct as I can tell. The code is:

       

      /******************************************************************************

      *                                Constants

      ******************************************************************************/

      #define CS WICED_P07

      #define START_TIMER 100 /*100 ms timer for start and ack*/

       

      #define MASTER_P38_CLK_P28_MOSI_P01_MISO 0x00261C01 /* Macro for SPI master pin configurations */

      #define DEFAULT_FREQUENCY 1000000 /* 1 MHz */

      #define my_FREQUENCY 200000 /* 200 KHz */

      /******************************************************************************

      *                                Function Definitions

      ******************************************************************************/

        static void spi_master_driver( void );

       

      static void initialize_app( void );

      /******************************************************************************/

      /*

      *  Entry point to the application. Initialize the app

      *****************************************************************************/

      APPLICATION_START( )

      {

       

          wiced_set_debug_uart( WICED_ROUTE_DEBUG_TO_PUART );

       

          initialize_app();

      }

       

      /******************************************************************************

      * This functions initializes the SPI and GPIO as well as timer

      ******************************************************************************/

       

      void initialize_app( void )

      {

           wiced_hal_pspi_reset(SPI1);

          /*Initialize CS GPIO and SPI*/

          wiced_hal_gpio_configure_pin(CS, GPIO_OUTPUT_ENABLE, GPIO_PIN_OUTPUT_HIGH);

          wiced_hal_pspi_init(SPI1, SPI_MASTER, INPUT_PIN_PULL_UP, MASTER_P38_CLK_P28_MOSI_P01_MISO, my_FREQUENCY, SPI_MSB_FIRST, SPI_SS_ACTIVE_LOW, SPI_MODE_3, CS);

       

          /*Start a timer for 100 ms*/

          wiced_bt_app_start_timer(NULL, START_TIMER, NULL, spi_master_driver);

      }

      /****************************************************************************************

      * This function  exchanges data with the slave

      ***************************************************************************************/

      void spi_master_driver( void )

      {

          UINT8 MYRECBUFFER =0;

         UINT8 MYTRCBUFFER = 0xD0;

      wiced_hal_gpio_set_pin_output(CS, GPIO_PIN_OUTPUT_LOW);

      wiced_hal_pspi_exchange_data(SPI1, sizeof(MYTRCBUFFER), &MYTRCBUFFER, &MYRECBUFFER);

      wiced_hal_gpio_set_pin_output(CS, GPIO_PIN_OUTPUT_HIGH);

       

      // wiced_hal_pspi_tx_data(SPI1, sizeof(MYTRCBUFFER), &MYTRCBUFFER);

      //  wiced_hal_pspi_rx_data(SPI1,sizeof(MYRECBUFFER), MYRECBUFFER);

          WICED_BT_TRACE("Master Sent:%0X, Master Received:%0X, delayrep:%d\n",MYTRCBUFFER, MYRECBUFFER, delayrep);

      }

       

       

      As you can tell is a very concise code, can't do shorter than that, and as far as I can tell it should work. Needless to say that the BMP280 supports SPI_MODE_3

       

      So to find out what was going on, I have used a digital scope to see how the comms go about and compare the arduino comms with the sensor and the cypress comms with the sensor. It seems that the clock and data (cypress master) start almost together, with a very small difference the clock comes first but the data are raised right after it. When using the arduino as a master the cs, clock and data are more spacious. The waveforms are attached. In both cases 0XD0 is sent, but only when arduino served as a master the BMP280 replied back.

       

      So my question is this: is the BMP280 sensor compatible with the cypress CYW920719? or the cypress SPI is to fast for it and there are compatibility issues? Please let me know so I can choose other sensor if I need to.

       

      With regards,

      George.

        • 1. Re: SPI issue with CYW920719
          AnjanaM_61

          Hi,

           

          1. Could you please try reduce the SPI frequency (give half value of whatever you gave now) and try if it works?

          2. Can you please probe the CS pin or can you please provide logs of a SPI analyzer if possible for both working condition (sensor with aurdino) and non working condition (sensor with 20719)?

           

          Thanks & Regards,
          Anjana

          1 of 1 people found this helpful
          • 2. Re: SPI issue with CYW920719
            AbhishekK_31

            Looks like you are doing an 'exchange' instead of 'tx' followed by 'rx'. When you use the API wiced_hal_pspi_exchange_data you are sending only 8 clock pulses to the sensor and in those 8 pulses 8 bits of data is sent as well as received from the slave. But looking at the datasheet of BMP280 you need to first send the register address as the first 8 bits and then read the data in the next 8 bits. During these 2 operations your CS line should be asserted.

             

            So in your code you need to remove 'wiced_hal_pspi_exchange_data', uncomment 'wiced_hal_pspi_tx_data' and 'wiced_hal_pspi_rx_data' APIs and finally move 'wiced_hal_gpio_set_pin_output(CS, GPIO_PIN_OUTPUT_HIGH);' after 'wiced_hal_pspi_rx_data'

             

            Besides this you need to make sure that in the '/20719-B1_Bluetooth/platforms/CYW920719Q40EVB_01/wiced_platform_pin_config.c' file your CS pin (which is WICED_P07) is configures as 'WICED_GPIO and not as 'WICED_SPI_1_CS'. This is to make sure that the CS pin is not controlled by the SPI HW block but controlled by the application

            1 of 1 people found this helpful
            • 3. Re: SPI issue with CYW920719
              georgepvs_3453826

              Dear Anjana,

              I guess Icould reduce the freq, below 200kHZ, however, the SPI of the sensor (BMP280) goes up to 10MHz, and that of the CYW920719 is up to 12MhZ. However, the reason I went down to 200KhZ is because I found an answer from you in another forum stating that the SPI comms of the CYW920719 wouldn't work below 187KHZ  (20719 SPI Master Clock Configuration Problem ).

              Also in the pics that I have provided the cypress master is the non working condition, and the arduino master is the working condition. In both of those cases the CS is the redish line, the clk is the yellow and the data txed to the sensor is the blue line.

               

               

              • 4. Re: SPI issue with CYW920719
                AnjanaM_61

                Hi,

                 

                I suggest you to have a try on Abhishek's suggestion (Changing the SPI API as well as changing the CS pin configuration).

                 

                Thanks,
                Anjana

                • 5. Re: SPI issue with CYW920719
                  georgepvs_3453826

                  Dear AMKA,

                  Thanks for the reply, it does work when you use the tx, rx routines and you have the WICED_P07 set as WICED_GPIO.

                   

                  However, there are two more issues that I have with it:

                   

                  1) I do see the correct data on the scope (the sensor reply is 0x58) see attachment, but when I print them out through the serial port, I get random numbers?

                   

                  the new routine is as follows and the print out is simply done through: WICED_BT_TRACE.

                  void spi_master_driver( void )

                  {

                      UINT8 MYRECBUFFER = 0;

                     UINT8 MYTRCBUFFER = 0xD0; //1101 0000 = D0, 0X50; //

                   

                          wiced_hal_gpio_set_pin_output(CS, GPIO_PIN_OUTPUT_LOW);

                             wiced_hal_pspi_tx_data(SPI1, 1, &MYTRCBUFFER);

                             wiced_hal_pspi_rx_data(SPI1, 1, &MYRECBUFFER);

                          wiced_hal_gpio_set_pin_output(CS, GPIO_PIN_OUTPUT_HIGH);

                        //  wiced_rtos_delay_milliseconds(20, 1);

                      WICED_BT_TRACE("Master Sent:%0X, Master Received:%0X\n",MYTRCBUFFER, MYRECBUFFER);

                  }

                   

                  On the attached scope picture: Blue=data from master to sensor (0xD0), light blue = data from sensor to master (0x58), yellow = clk, redish = cs.

                   

                   

                  2) The second problem that I am facing is that. after one minute the master stops all comms/freezes and I have to press the reset to start it again. Why is that?

                   

                   

                  1. cypressMasterDoDi.jpg
                  • 6. Re: SPI issue with CYW920719
                    AbhishekK_31

                    Can you disconnect your oscilloscope from the board and check? Sometimes long wires can create problems. Also make sure you are using short wires to connect to your sensor. You can also try using Mode 0 instead of Mode 3

                    • 7. Re: SPI issue with CYW920719
                      georgepvs_3453826

                      Dear AMKA hi,

                       

                      I've tried with mode0 and 3 without the scope and short wiring, but the problem is still there. I must mention that with the scope connected and with original ( longer) wires the Arduino presents the data fine.

                      It seems that there is interference with the read buffers. What I mean is that I use the SPI to read the data and the peripheral UART to display the data on screen. Does the CYW920719 use the same read/write buffers for SPI and UART? So since I see the data clearly on the scope, could it be that the data are overitten (because of the common buffers) before the get to be displayed?

                      1 of 1 people found this helpful
                      • 8. Re: SPI issue with CYW920719
                        AbhishekK_31

                        Are you using HCI UART or PUART for printing? SPI1 and HCI UART use the same buffers. You can't use them together

                        • 9. Re: SPI issue with CYW920719
                          georgepvs_3453826

                          Hi AMKA,

                          I am using the PUART, I've set  as:

                           

                          APPLICATION_START( )

                          {

                              wiced_set_debug_uart( WICED_ROUTE_DEBUG_TO_PUART );

                               initialize_app();

                          }

                           

                           

                           

                           

                          And the data returned if you follow the:

                          WICED_BT_TRACE("ID-Master Sent:%0X, Master Received:%0X\n",MYTRCBUFFER, MYRECBUFFER);

                          should come back as 0x58 (as shown on the scope) but instead the data seen are a random sequence:

                           

                          ID-Master Sent:D0, Master Received:3

                          ID-Master Sent:D0, Master Received:3C

                          ID-Master Sent:D0, Master Received:C

                          ID-Master Sent:D0, Master Received:F0

                          ID-Master Sent:D0, Master Received:33

                          ID-Master Sent:D0, Master Received:C0

                          ID-Master Sent:D0, Master Received:0

                          ID-Master Sent:D0, Master Received:CF

                          ID-Master Sent:D0, Master Received:3

                          ID-Master Sent:D0, Master Received:3C

                          • 10. Re: SPI issue with CYW920719
                            AnjanaM_61

                            I had a similar issue were the receiving bytes were not matching.

                            But upon replacing the SPI lines with shorter wires, it fixed.

                            Are you still getting the wrong values?