1 2 Previous Next 18 Replies Latest reply on Feb 14, 2014 12:45 PM by florian.braun

    SPI Master doesn't work correctly.

    florian.braun

      Hello everybody,

         

      At the moment I try out to send a SPI message (Projekt "testendesDAC")

         

      I want to use SPI in my current Projekt. But I have Problems to send out a full 16-Bit message. At the moment I send out only 4-Bit. See picture 004.png.

         

      Far days away I controlled an ADC with SPI and everthing work fine. See picture 001.png.

         

      My hardware: I have develped my own board. The board have got the size of "mbed". It have got an external 24-MHZ Crystal. 

         

      Thanks everybody for your help.

         

      Regards,

         

      Flo 

         

       

         

      Scope pics:

         

      CH1 - Yellow = CS

         

      CH2 - Green = SCLK

         

      CH3 - Pink   = MOSI

         

      CH4 - Blue  = MISO

        • 1. Re: SPI Master doesn't work correctly.
          user_14586677

          If you go to the start page, "File", "Example Project", you can pick

             

          a working SPIM project to try out. And modify as you wish.

             

           

             

          Regards, Dana.

             

           

             

           

          • 2. Re: SPI Master doesn't work correctly.
            ki.leung

            Try using the IMO and PLL to generate the 24M required, see if this helps.

               

            you can also try to write the ouput in a endless loop as well. this would make it easier to check. 

            • 3. Re: SPI Master doesn't work correctly.
              ki.leung

              I mean continously outputing with the SPI inside a loop, of couse, all some delay inside some can capture the pulses easier.

              • 4. Re: SPI Master doesn't work correctly.
                florian.braun

                Hello,

                   

                first thanks to everybody for your replies. I think I have got a general problem because the UART doesnt't work correctly, too.

                   

                I implemented a UART and send out data with UART_1_PutArray(). But the device sending out the data correctly. See the picture 004. The UART should put more databits out. So I don`t know where´s the mistake is. A few days ago it was very easy to implemented a UART/SPI.

                   

                In the attach is the scope picture 005. And the programm to testing  UART. This project was the SPI example projekt. The SPI didn't work today, too. I tried out your answers: For example I changed the clock to PLL/Internal Clock. But I get the same results as yesterday.

                   

                Regards,

                   

                Flo

                • 6. Re: SPI Master doesn't work correctly.
                  florian.braun

                  *And I test the program with different hardware. For example CY(CKIT-050 PSoC 5LP Development Board.

                  • 7. Re: SPI Master doesn't work correctly.
                    user_1377889

                    What makes you think that none of the components uses interrupts?

                       

                    Generally speaking: I suggest you to enable global interrupts as a standard and only disable them when explicitely wanted.

                       

                     

                       

                    Bob

                    • 8. Re: SPI Master doesn't work correctly.
                      florian.braun

                      Hello.

                         

                      That is correct, in my posted project I don't use CyGlobalInterruptEnable.

                         

                      But normally I had use this function. So I don´t think that is the problem.

                         

                      A few minutes ago I add the function to a simple UART projekt. transmit with: UART_1_PutChar(0xAA); (And UART ony send out 3 bits. (002.jpf). And I got the same bad result as before.

                         

                      Thanks everbody for your help!

                         

                      flo

                      • 9. Re: SPI Master doesn't work correctly.
                        user_14586677

                        I modified your project as follows -

                           

                         

                           

                        1) uart array declared as "const", PutArray wants array to be that

                           

                        2) uart pin to P4_0, initial output state to 0

                           

                        3) Enabled global interrupts

                           

                        4) Eliminated 2'ond for(;;) loop

                           

                        5) Eliminated your startup delay

                           

                         

                           

                        Works fine on my -050 board.

                           

                         

                           

                        Regards, Dana.

                        • 10. Re: SPI Master doesn't work correctly.
                          florian.braun

                          Hi,

                             

                          okay thanks everybody für your help. I don't know where the problem is. At the moment I try out the UART again and everything works fine. But I have got another Hardware:

                             

                          - Cy8CKIT-042 PSoC 4 Pioneer Kit

                             

                          - Annother Computer

                             

                          See Attach there is my program I had wrote a few minutes ago. UART work. I try this programm tommorow with the previous hardware

                             

                          I want be snooty but:

                             

                          At the moment I do a internship...

                             

                          I work the last weeks with UART every day, from monday to friday and minimum six hours. I wrote a program to listen a Bus and send it out to CAN. I wrote a program to send out UART messages include change the clock of UART. I controlled an ADC with SPI. I controlled a DAC with SPI. Everything works.

                             

                          But from one moment to the other: I couldn't send out UART messages. I couldn't send out SPI messages. And I used the same programs as before.

                             

                          (Receive UART Messages works :-))

                             

                          So, yes I'm not a expert but I think that the problem is not a easy. 

                             

                          - Maybe something with the clock.

                             

                          I know that I did mistakes in my example projects. But I have time at work so normally I find issus like:

                             

                          - Forget CyGlobalInterruptEnable.

                             

                          - Forget to start the Component.

                             

                          So, I try it out tomorrow again and I will post my results.

                             

                          Thanks Dana for your time to modified my program.

                             

                          Regards,

                             

                          Flo

                          • 11. Re: SPI Master doesn't work correctly.
                            ki.leung

                            Hi flo,

                               

                            you mentioned in you previous post

                               

                            "A few minutes ago I add the function to a simple UART projekt. transmit with: UART_1_PutChar(0xAA); (And UART ony send out 3 bits. (002.jpf). And I got the same bad result as before."

                               

                            the waveforrm is correct. If you draw the waveform on a piece of paper, you should be able confirm that. Or if you change the  UART to have the tx_clk/rx_clk output and sent it out to a output pin on the psoc. you should be able to see the uart clock together with the serial data. remember that LSB frist. There are 4 ONE in the packet, the last ONE(MSB) is joined with the stop bit. so you should only see 3 pulse.

                            • 12. Re: SPI Master doesn't work correctly.
                              user_14586677

                              I tried this out on PSOC 4, some changes -

                                 

                               

                                 

                              1) Variables that either were single letters or looked like potential reserved

                                 

                              words I changed their name.

                                 

                               

                                 

                              2) The Rx flag was declared volatile

                                 

                               

                                 

                              3) The Tx data sent restricted to ascii chars

                                 

                               

                                 

                              I got it to work, by monitoring my var charrecv,  except I cannot see Tx data on pin, really strange.

                                 

                               

                                 

                              Regards, Dana.

                              • 13. Re: SPI Master doesn't work correctly.
                                florian.braun

                                Hello everybody again,

                                   

                                I think my mistake was that I'm to dummy to control a scope. And maybe I´m to dummy to write a correct UART program, too.

                                   

                                Today I try my last posted project (or look at danaaknight post before this post) with my own Cypress 5LP board. Everythink looks good include the scope pictures. So I create a simular project with SPI. And everythink look include scope picture.

                                   

                                See picture 007.png with yellow = ss (chip select), green = clock, blue = MOSI. 

                                   

                                In this picture I sent out 0x01.

                                   

                                @HL thanks for your answer maybe I lose the track of at trying out the UART yesterday. But I got some scope pictures who look wrong, too. But it could be a scope error (I maybe controlled scope false). In my newest project I read my send out data back with an SPI Slave or an UART RX compment. So I could check my sending out data with scope and the read back compoment.

                                   

                                @Dana thank you very much. Maybe it is better to work with two connected input and output ports. And split the direct intern connection between UART TX and UART RX. 

                                   

                                Thanks that you modified my project. But I have one question:

                                   

                                Why have you changed the flag variable to volatile. What is the advantage? This question I had asked me weeks ago, too. Without an result.

                                   

                                Thank you everybody again!

                                   

                                Regards,

                                   

                                Flo

                                   

                                Attach file: Working SPI project and the scope result of one cicle 007.png

                                • 14. Re: SPI Master doesn't work correctly.
                                  user_1377889

                                  @Dana

                                     

                                  Didn't work for me as well. I deleted the pin and inserted a new one, now working.

                                     

                                   

                                     

                                  Bob

                                  1 2 Previous Next