Communication between two psocs with SPI

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
BUTA_1301626
Level 4
Level 4
50 replies posted 25 replies posted 10 replies posted

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.

0 Likes
1 Solution

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

Alakananda

View solution in original post

0 Likes
16 Replies
Alakananda_BG
Moderator
Moderator
Moderator
50 likes received 250 sign-ins 250 replies posted

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

Alakananda
0 Likes

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

0 Likes
lock attach
Attachments are accessible only for community members.

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

Alakananda
0 Likes

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.

0 Likes

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

Alakananda
0 Likes

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))

  // {};

0 Likes

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

Alakananda
0 Likes

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?

0 Likes
lock attach
Attachments are accessible only for community members.

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

0 Likes

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

Alakananda
0 Likes

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

0 Likes

Hi Burak,

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

Regards,

Alakananda

Alakananda
0 Likes

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

0 Likes

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

Alakananda
0 Likes

MASTER CODE "PSOC MASTER "==>"50 53 4f 43 20 4d 41 53 54 45 52"

SPIM_WriteTxData(0x50);

    SPIM_WriteTxData(0x53);

    SPIM_WriteTxData(0x4f);

    SPIM_WriteTxData(0x43); 

     SPIM_WriteTxData(0x4D); 

     SPIM_WriteTxData(0x41); 

     SPIM_WriteTxData(0x53); 

     SPIM_WriteTxData(0x54); 

     SPIM_WriteTxData(0x45); 

    SPIM_WriteTxData(0x52); "

When I write this code, I write the code below to the slave device.The slave device is not loading the first two data into the rfbuffer.if I change the code to "if (RFBuffer [0u] == (0x4f)").  lcd write "OSCMASTER" so the first character "p" is lost.

Slave code:

for(count=0; count < 10 ; count++)

{

RFBuffer[count] =SPIS_ReadRxData();

}

    /* SPI communication is complete so we can display received data */

     //LCD_ClearDisplay();

    LCD_Position(0u,0u);

    LCD_PrintString("SPI Slave:");

if(RFBuffer[0u]==(0x50) ){

LCD_Position(1u,0u);

LCD_PrintString(RFBuffer);

LED_Write(1u);

sendDataToMaster();}

else {

    LCD_ClearDisplay();

   // CyDelay(100);

    LCD_Position(1u,0u);

LCD_PrintString("BILGI YOK");

LED_Write(0u);}   

}

0 Likes

Hi Burak,

Can you please refer to the below thread and let us know if it would help to solve your issue

Strange behavior of SPIS_PutArray()

Regards

Alakananda

Alakananda
0 Likes