14 Replies Latest reply on Jun 25, 2015 6:31 AM by user_14586677

    PSOC5 SPI and AD7793

    user_279968365

      Dear all:

         

      I am trying to communicate with analog Devices part AD7793 using SPI with a PSOC5.

         

      I have CY8CKIT-050 and the AD7793 Evalutaion KIT (I need more ADC channels so I need AD7793 for these extra channels). I wired the signals mosi, miso, cs , clk and GND beween both EVK.

         

      AD support this devices with a generic diver that can be download from http://wiki.analog.com/resources/tools-software/uc-drivers/renesas/ad7793

         

      I also attach the project on PSOC with a vey simple main.c. I Just want to check the AD7793 is there using function AD7793_init();.

         

      I am not able to talk with AD7793. Can anyone have a look to the SPI communication function and check if there is any wrong.?

         

      Thanks in advance,

         

      Joaquin.

        • 1. Re: PSOC5 SPI and AD7793
          user_1377889

          In Communication.c, SPI_Write() you send your data using SPIM_WriteTxData(). This will put the data into the SPIM's FIFO and returns before the data has been actually sent. When you now remove your ss-signal the communication fails. Better is to wait until the FIFO is empty AND the last byte is transmitted before pulling the control-register high again.

             

           

             

          Bob

          • 2. Re: PSOC5 SPI and AD7793
            user_279968365

            Dear Bob:

               

            Thank you very much for your repply. After some trying  I added the following sentence after the for bucle SPIM_WriteTxData...:

               

            for(i=0u; i<bytesNumber; i++){
                            SPIM_WriteTxData(data[i]); // initiates data transmission
                        }
                    }
             while(!(SPIM_ReadTxStatus() & SPIM_STS_SPI_IDLE));

               

            On datasheet, figure on page 28/41, it seems that everything is finihed when SPI_IDLE is set, so I added the last sentence.

               

             

               

            Stll I have other problem on the SPI_Read function, I cant see the clock moving...any idea of the reason?

               

            Thanks in advance.

               

            Joaquin.

            • 3. Re: PSOC5 SPI and AD7793
              user_1377889

              Can you post your complete project, so that we all can have a look at all of your settings? To do so, use
              Creator->File->Create Workspace Bundle (minimal)
              and attach the resulting file.



              Bob
               

              • 5. Re: PSOC5 SPI and AD7793
                user_1377889

                Reading from an SPI slave takes a little bit of getting used to.

                   

                SPI is organized, so that for every bit written to the slave a bit is returned by the slave at the very same time.

                   

                So the usual procedure to read from a slave is:

                   

                 

                   
                      
                • Assert  ss
                •     
                • Write byte(s) to slave to indicate what the slave has to answer (commands).
                •     
                • When done (transmitted), clear the recieve buffer
                •     
                • Write as many dummy bytes to the slave as you want to read.
                •     
                • When done (transmitted), de-assert ss
                •     
                • Now your RX-buffer is filled with the required information which you can read out now.
                •    
                   

                 

                   

                Seems to be a bit (or byte) weired, but that's the way SPI works.

                   

                 

                   

                Happy coding

                   

                Bob

                • 6. Re: PSOC5 SPI and AD7793
                  user_279968365

                  Hi Bob,

                     

                  Thank you very much.

                     

                  It was clear that I did not understand SPI.... Still i dont understand what all the AD functions do, but at least I am able to detect the chip.

                     

                  Another small question: One of the AD functions need to detect when Dout/RDY pin of the chip AD7793 is low for the end of conversion. For my system,  it is miso signal pin...can I use miso_read() to read this pin and check when it is low ?

                     

                  Thank you very much for your help.

                     

                  Regards,

                     

                  Joaqui.

                  • 7. Re: PSOC5 SPI and AD7793
                    user_1377889

                    Since miso is an input pin with a given pin name you may use

                       

                    m_miso_pin_Read()

                       

                    to get its current value (0 or 1)

                       

                     

                       

                    Bob

                    • 8. Re: PSOC5 SPI and AD7793
                      user_279968365

                      Hello Bob:

                         

                      Still I am having sporadic problems with the SPI comunicating with AD7793. I mean , sometimes it goes right but  others go wrong. Not pretty sure if the problem comes from the SPI comunication or in the Analog Devices functions to interact with it.

                         

                      But just to be sure that SPI  subrutines (just only two, SPI_Write()  and SPI_read() )  are Ok, could you have a look to them and let me know if you see any problem?

                         

                      I left the whole project but only on comunication.c/h is where I would like you  have a look.

                         

                      Thanks in advance,

                         

                      Joaquin.

                      • 9. Re: PSOC5 SPI and AD7793
                        user_14586677

                        Just out of curiosity why are you using an external DelSig and not the DelSig in

                           

                        PSOC 5LP ? It has an onchip ref, buffer with G for A/D input, and muxes. It does not

                           

                        have an IA, you would need one external if you needed high G in the signal path as

                           

                        5LP is limited to G = 8, but the buffer is differential in case you need that.

                           

                         

                           

                           

                         

                           

                        Regards, Dana.

                        • 10. Re: PSOC5 SPI and AD7793
                          user_279968365

                          Yes, no problem.

                             

                          We are designing a kind of PLC measuring 6 different temperatures (PT100 and Thermocouple Type K) using the PSOC 5 ADC, 2 DA output , 16 Digital Inputs, 8 digital outputs and also we need 4 analog sensors (4-20mA, 0-5V and 0-10V)  for which we will use two external AD7793. All of processed by  a RaspberryPi....

                             

                          Joaquin.

                          • 11. Re: PSOC5 SPI and AD7793
                            user_279968365

                            Hello:

                               

                            I am tryng to find an Application Note  regarding communication with an external device usign SPI . Can someone recommend me one? All the examples I find are between PSOC devices.

                               

                            Thanks in advance,

                               

                            Joaquin.

                            • 12. Re: PSOC5 SPI and AD7793
                              user_14586677

                              This might help, although for PSOC 1, principles are same.

                                 

                               

                                 

                              www.cypress.com/

                                 

                               

                                 

                              Regards, Dana.

                              • 13. Re: PSOC5 SPI and AD7793
                                user_279968365

                                Hi Dana:

                                   

                                Thank you very much.

                                   

                                As it is for PSOC1 it is not fully applicable for PSOC5 and I get some confused because I havent work with PSoC 1 before. Any other suggestion? 

                                   

                                Thanks in advance,

                                   

                                Joaquín.

                                • 14. Re: PSOC5 SPI and AD7793
                                  user_14586677

                                  There is always the SPI examples in PSOC Creator, start page, "Find Example project".

                                     

                                   

                                     

                                  There is some stuff up on youtube for SPI training, in general, not PSOC specific.

                                     

                                   

                                     

                                  Regards, Dana.