1 2 Previous Next 16 Replies Latest reply on Aug 7, 2019 10:52 PM by AlakanandaB_86

    Communication between two psocs with SPI

    BUTA_1301626

      I have two psoc kits. I want these two kits to communicate with the SPI. I looked at the sample projects but I could not.

      the first psoc will send information "A" to the second psoc.

        After the second psoc receives "A" information, it will send "B" data to the first psoc and write it on the LCD.

        • 1. Re: Communication between two psocs with SPI
          AlakanandaB_86

          Hi Burak Tasci,

           

          We checked the project which you have attached and it is working at our side and we are receiving the data as per required.

          I have shared a screenshot of the ouput which we observed at our side.

          Can you please probe it and observe the waveforms at your side and let us know the isuue you are facing.

          screenshot.PNG

           

          Regards

          Alakananda

          • 2. Re: Communication between two psocs with SPI
            BUTA_1301626

            I want to see the information I sent on the LCD. but I cannot see it on lcds on the master or slave sides.

            • 3. Re: Communication between two psocs with SPI
              AlakanandaB_86

              Hi Burak Tasci,

               

              I have attached the modified code which is printing the information on the LCD.

              Please refer to the below code and let us know if you have any queries.

               

              Regards

              Alakananda

              • 4. Re: Communication between two psocs with SPI
                BUTA_1301626

                The LCD shows nothing. I checked the connections.

                I also want to ask something else. What command should I use if I want to write 0x14h to the slave's register at 35h.

                SPIM_WriteTxData(0x35,0x14); ==>I'm trying. it gives an error.

                • 5. Re: Communication between two psocs with SPI
                  AlakanandaB_86

                  Hi Burak Tasci,

                   

                  LCD port connection has been changed, please change the LCD port connections and please refer to the below screenshot and then try running the above code. The API LCD_PrintString("SPI MASTER:"); will print no matter your spi is running or not, so you can confirm the working of LCD by this.

                   

                  screenshot1.PNG

                   

                  For the second question, the API  SPIM_WriteTxData(); supports only one argument and hence it is showing an error.
                  If you want to try then you have to pass an two data elements, one for position and another for the data.
                  SPIM_WriteTxData(0x35); //denotes position of the element
                  SPIM_WriteTxData(0x14); //actual element that has to be stored in the particular position
                  The slave has to read the data twice i.e once for position and other for data and then the processing must be done
                  pos = SPIM_ReadRxData(0x35);
                  data = SPIM_ReadRxData(0x14);

                  Finally the array of position should be equal to data.
                  array[pos] = data;

                   

                   

                  Regards
                  Alakananda

                  • 6. Re: Communication between two psocs with SPI
                    BUTA_1301626

                    if the slave c opposite is another module (eg RF module), rather than the pleasure psoc, can it detect address and data separately?

                     

                    Screenshot_20190802_094654.jpgWhile komutunu silerken, köle "00" diyor.

                    silmezsem çalışmıyor.

                      // while (! (SPIS_ReadTxStatus () & SPIS_STS_SPI_DONE))

                      // {};

                    • 7. Re: Communication between two psocs with SPI
                      AlakanandaB_86

                      Hi Burak Tasci,

                       

                      Can you please probe and send the waveforms so that we can see what is happening in the spi bus.

                       

                      Regards

                      Alakananda

                      • 8. Re: Communication between two psocs with SPI
                        BUTA_1301626

                        Only the master logic output is as follows.

                        master.JPG

                        Only the slave logic output is as follows.

                        slave.JPG

                        slave and master  miso-->miso,mosi-->mosi,clk-->clk,en-->en  connection logic output state is as follows.

                        slave master together.JPG

                        IMG_20190805_151908_resized_20190805_031929859.jpg

                        The master writes 00.  The slave  writes 16. Doesn't the master have to type 42?

                        • 9. Re: Communication between two psocs with SPI
                          BUTA_1301626

                          Hi Alakananda;

                          I tried the file you sent. I made some changes. But SPIS does not work. I changed the PSoc to become a slave master. but again the same slave does not work.

                          I think we need to make changes for the slave?

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

                          * File Name: main.c

                          *

                          * Slave Code

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

                          #include <project.h>

                          void sendDataToMaster(){   

                              SPIS_WriteTxDataZero(0x50);

                              SPIS_WriteTxData(0x53);

                              SPIS_WriteTxData(0x4F);

                              SPIS_WriteTxData(0X43);

                          SPIS_WriteTxData(0X20);

                          SPIS_WriteTxData(0X53);

                          SPIS_WriteTxData(0X4C);

                          SPIS_WriteTxData(0X41);

                          SPIS_WriteTxData(0X56);

                          SPIS_WriteTxData(0X45);

                          }

                          int main()

                          {

                              uint8 i = 0u;

                                CyGlobalIntEnable;

                                 LCD_Start();

                                SPIS_Start();

                               LCD_ClearDisplay();

                              for(;;)

                              {

                              while(!(SPIS_ReadTxStatus() & SPIS_STS_SPI_DONE))

                              {};

                               LCD_Position(0u,0u);

                              LCD_PrintString("SPI Slave:");

                              LCD_Position(1u,0u);

                              LCD_PrintHexUint8(SPIS_ReadRxData());

                              sendDataToMaster();

                              }

                             }

                          /* [] END OF FILE */

                          slave master together.JPG

                          • 10. Re: Communication between two psocs with SPI
                            AlakanandaB_86

                            Hi Burak,

                             

                            We tried with your code and its working for us.

                            Can you please check the MISO coonection again and try sending single data and check if its working at your end.

                            Slave sends the data only when master sends out the data to the slave.

                             

                             

                            Regards

                            Alakananda

                            • 11. Re: Communication between two psocs with SPI
                              BUTA_1301626

                              Hi Alakananda;

                              SPI worked after changing MISO, MOSI, CLK, SS pins.

                              thank you very much.

                              now I have to experiment with register.

                              "     For the second question, the API  SPIM_WriteTxData(); supports only one argument and hence it is showing an error.
                              If you want to try then you have to pass an two data elements, one for position and another for the data.
                              SPIM_WriteTxData(0x35); //denotes position of the element
                              SPIM_WriteTxData(0x14); //actual element that has to be stored in the particular position
                              The slave has to read the data twice i.e once for position and other for data and then the processing must be done
                              pos = SPIM_ReadRxData(0x35);
                              data = SPIM_ReadRxData(0x14);

                              Finally the array of position should be equal to data.
                              array[pos] = data;   "

                              but I have a question. we have 1byte = 8 bits of data in a register. how to send them to registers.

                               

                              Regards...

                              Burak

                              • 12. Re: Communication between two psocs with SPI
                                AlakanandaB_86

                                Hi Burak,

                                 

                                Does the individual register mean you are using the control register?

                                 

                                Regards,

                                Alakananda

                                • 13. Re: Communication between two psocs with SPI
                                  BUTA_1301626

                                  register.JPG

                                  Hi Alakananda;

                                  I have an RF transceiver module. this module has registers at certain addresses as in the picture.I want to load the values I want to these registers.

                                  SPIM_WriteTxData(0x35,0x14); ==>when I try this way, it gives an error.  (for example, this code works in arduino.)                                           in this code   address: 0x35 data: 0x14

                                  " { pos = SPIM_ReadRxData(0x35);

                                  data = SPIM_ReadRxData(0x14);

                                  Finally the array of position should be equal to data.
                                  array[pos] = data; }  "==> rf module does not work when we do this way

                                   

                                  Regards...

                                  Burak

                                  • 14. Re: Communication between two psocs with SPI
                                    AlakanandaB_86

                                    Hi Burak,

                                     

                                    You can try using this API  void SPIM_PutArray(const uint8/uint16 buffer[], uint8 byteCount)

                                    where buffer[0] will be your address and buffer[1] will be your data

                                    Please try doing this if not send your waveforms we will recheck again.

                                     

                                    Regards

                                    Alakananda

                                    1 2 Previous Next