5 Replies Latest reply on Oct 2, 2015 2:55 AM by user_1377889

    SPIM_WriteTxData() Usage CY8CKIT-050

    mnauss_1472621

      Greetings;

         

      I am using PSoC Creator 3.3 with the CY8CKIT-050. I am trying to communicate with a MPL115A1 Barometer via SPI 4-wire. I ran the example project of the SPI (Master, Slave) components and it worked just fine.

         

      So I tried to make my own file using what I gleaned from the example project to perform SPI communication with the MPL115A1 barometer breakout board. I have been doing hardware design for awhile, but am new to embedded code writing, so I am not real strong in that area.

         

      I have 4 components in this design (so far), SPI Master component (Ver 2_5) Tx and Rx Buffers set to 4, LCD component, and two control registers for debugging (because I have not learned the debugger yet). The LCD display works, the debug LED's work, but I have no data coming out of the MOSI pin, or any other SPI pin for that matter (Viewing pins with DSO). The hardware pins are set to strong drive, initial state low. I am not sure what the problem is as I am pretty much doing the same thing as in the example code. My code is below:

         

      /* MPL115 Memory Map
        Address Name      Description                 Size (bits)
          0x00 Padc_MSB 10-bit Pressure output value    MSB 8
          0x01 Padc_LSB 10-bit Pressure output value    LSB 2
          0x02 Tadc_MSB 10-bit Temperature output value MSB 8
          0x03 Tadc_LSB 10-bit Temperature output value LSB 2
          0x04 a0MSB a0 coefficient MSB 8
          0x05 a0LSB a0 coefficient LSB 8
          0x06 b1MSB b1 coefficient MSB 8
          0x07 b1LSB b1 coefficient LSB 8
          0x08 b2MSB b2 coefficient MSB 8
          0x09 b2LSB b2 coefficient LSB 8
          0x0A c12MSB c12 coefficient MSB 8
          0x0B c12LSB c12 coefficient LSB 8
      */

         

      #include <project.h>
      #include <cylib.h>
      #include <stdio.h>

         

      //======================//
      //          Macros            //
      //======================//

         


      //======================//
      //     Global Variables    //
      //======================//

         

       

         


      /* *******************
      MPL115A1 Functions
      **********************/

         

      /*******************************************************************************
      * Function Name: ControlReg1_Write
      ********************************************************************************
      * Function enables hardware to display value of register using two led's
      * Parameters ledZ
      ********************************************************************************/
      void ControlReg1_Write (uint8 ledZ); // declaring the function

         

      void CyDelay(uint32 milliseconds);

         

      int main()
      {
          // CyGlobalIntEnable; /* Enable global interrupts. */ Tried remarking out this as a test (no -effect)
      //********************************************************************
      //      This section of code is just for debug, remove when not needed  
      //********************************************************************
          uint8 ledZ = 0x01; //code debug
          ControlReg1_Write(ledZ);
          CyDelay(250);
          ledZ = 0x00;
          ControlReg1_Write(ledZ);
          CyDelay(250);
          ledZ = 0x01;
          ControlReg1_Write(ledZ);
          CyDelay(250);
          ledZ = 0x00;
          ControlReg1_Write(ledZ);
          CyDelay(250);
       //*******************************************************************
          
          /* Place your initialization/startup code here (e.g. MyInst_Start()) */
      // Start the LCD and Display
      LCD_Start ();
      LCD_Position(0u,0u);
      LCD_PrintString("Pressure->");
      LCD_Position(1u,0u);
      LCD_PrintString("Temp->");
      CyDelay(2000);
      ledZ = 0x01;
      ControlReg1_Write(ledZ);
      CyDelay(1000);

         

      //Start the SPI master component
      SPIM_Start();

         


          for(;;) //This loops forever, part of design template
          {
              /* Place your application code here. */
              SPIM_WriteTxData(0x24u);
              SPIM_WriteTxData(0x00u);
              SPIM_WriteTxData(0x00u);
              SPIM_WriteTxData(0x00u);
              
              ledZ = 0x02;
              ControlReg1_Write(ledZ);
              CyDelay (1000);
              ledZ = 0x03;
              ControlReg1_Write(ledZ);
              CyDelay (1000);
          }
      }

         

       

         

      // [] END OF FILE */

         

      Well let me know if anything obvious pops out at you, and I appreciate any help offered, oh and if you know of a good debugger tutorial let me know.

         

      Thanks

        • 1. Re: SPIM_WriteTxData() Usage CY8CKIT-050
          user_1377889

          It is always advisable so post your complete project with all of your settings, so that we can have a look at this. To do so, use
          Creator->File->Create Workspace Bundle (minimal)
          and attach the resulting file.

             

          There is not much to learn with the debugger, just set a breakpoint where you want to stop inspect your variables (there is some help in Creator).

             

           

             

          Bob

          • 2. Re: SPIM_WriteTxData() Usage CY8CKIT-050
            mnauss_1472621

            Okay, here is my project file.

               

            Thanks for the help.

            • 3. Re: SPIM_WriteTxData() Usage CY8CKIT-050
              user_1377889

              I built a loopback to prove that system is running as assumed. Small corrections made in source, see attached.

                 

               

                 

              Happy coding

                 

              Bob

              • 4. Re: SPIM_WriteTxData() Usage CY8CKIT-050
                mnauss_1472621

                Thanks a bunch for taking the time to look at my problem. I had just assumed I had a problem with my code, but after you mentioned that the code is working, I had to take a look at my hardware. I had a few issues. When I had my scope on the chip select line, I had no activity on ch 1 of my scope. Ch 2 was on MOSI and it was just putting out a low. Well I am somewhat a bonehead for not checking the hardware before posting my question, (but as I said I assumed it was my code). I pulled the little scope clip off my probe and put the probe directly on the MOSI pin and lo and behold I saw data on my scope, so it turns out my clip is very intermittent. I then check chip select pin again with scope and it was just logic high. I thought it must be the pin, so I moved the pin to P0[7], and I had chip select. just to be sure I rerouted back to p0[2] and again no chip select, so this pin appears to be faulty which is strange because I had used that pin for the last example project and it worked. I must of somehow damaged the pin. When I first got the board I ran some example code and found P0[4] to be faulty, so for some reason these pins are blowing. I do have a rev - CYKIT-050, is there any issues with that rev that could cause the pins to fail.

                   

                Well anyway, thanks for helping me and getting be back on track. One more question, I noticed in you code that you wrote the Tx buffer to a variable mydata, but I do not see how you viewed it?

                   

                Thank you very much

                • 5. Re: SPIM_WriteTxData() Usage CY8CKIT-050
                  user_1377889

                  Viewing "MyData" is quite easy: I set a breakpoint on the line with the "while" (by clicking on leftmost position in window) and when BP is reached single-stepping to read the 4 values from SPI while showing the local variables in debug window.

                     

                   

                     

                  Bob