cancel
Showing results for 
Search instead for 
Did you mean: 

SPI Communication SPC58EC MCU

RSeba.2
Associate III

Hello,

Currently I am working with SPI communication in SPC58EC DISP Discovery board. I wanted to evaluate communication between  MS-SL and SL-MS. I have configured SPID1 as master and SPID2 as slave. I was able to send data from master to slave using  below functions. 
spi_lld_receive(&SPID2, TRANSFER_BUFFER_SIZE, &spihandler_rx_fifo);
spi_lld_send(&SPID1, TRANSFER_BUFFER_SIZE, transmitBuff);
But how can I transmit data from slave to master ? Can I use the same functions for it or should I use spi_lld_exchange?

Thanks and regards.

6 REPLIES 6
TDK
Guru

spi_lld_exchange is a two-way SPI transfer which can work. Note that the master has to initiate all transfers. That is to say, spi_lld_exchange/spi_lld_send on the slave must be called before spi_lld_exchange/spi_lld_receive is called on the master.

If you feel a post has answered your question, please click "Accept as Solution".
RSeba.2
Associate III

Thanks for this information. But I couldn't receive all the data that I sent out from slave in master. 
I have used the following configuration.

const SPIConfig spi_config_master = {
SPI_MASTER,
0,
PORT_E,
8,
0UL | SPC5_CTAR_FMSZ(8) |
SPC5_CTAR_PCSSCK_PRE1 | SPC5_CTAR_PASC_PRE1 |
SPC5_CTAR_PDT_PRE1 | SPC5_CTAR_PBR_PRE2 |
SPC5_CTAR_CSSCK_DIV4 | SPC5_CTAR_ASC_DIV4 |
SPC5_CTAR_DT_DIV2 | SPC5_CTAR_BR_DIV2,
0UL | SPC5_PUSHR_CONT | SPC5_PUSHR_CTAS(0) | SPC5_PUSHR_PCS(1)
};

/**
* @brief Structure defining the SPI configuration "slave".
*/
const SPIConfig spi_config_slave = {
SPI_SLAVE,
0,
PORT_A,
4,
0UL | SPC5_CTAR_FMSZ(8) ,
0
//0UL | SPC5_PUSHR_CONT | SPC5_PUSHR_CTAS(0) | SPC5_PUSHR_PCS(0)
};
 I have used the following functions.

spi_lld_send(&SPID2, TRANSFER_BUFFER_SIZE, transmitBuff); //slave transmit
spi_lld_receive(&SPID1, TRANSFER_BUFFER_SIZE, &spihandler_mrx_fifo);

Do you know what might be the problems?

 
TDK
Guru

How are you ensuring the slave calls its SPI transfer function before the master calls its SPI transfer function?

If you feel a post has answered your question, please click "Accept as Solution".
RSeba.2
Associate III

case 'a':

debug_print_string("Starting SPI frame transmission from master:");
debug_print_crlf();
debug_print_string("Test case for command: FRCMD_GET_STATUS ");
debug_print_crlf();

tfsend_prepare(&tfc_spihandler, TF_ID_COMMAND, FRCMD_GET_STATUS);
tfsend_flush(&tfc_spihandler);
spi_lld_send(&SPID1, TRANSFER_BUFFER_SIZE, transmitBuff);

/* Slave transmit */
for (int i = 0; i < TRANSFER_BUFFER_SIZE; i++) {
transmitBuff_test[i] = 0x11;
}
spi_lld_send(&SPID2, TRANSFER_BUFFER_SIZE, transmitBuff_test);  //slave

spi_lld_receive(&SPID1, TRANSFER_BUFFER_SIZE, &spihandler_mrx_fifo); //master

break;


Case 'a' is input from the keyboard. When I press 'a', above code is executed.
Here, spi_lld_send(&SPID2, TRANSFER_BUFFER_SIZE, transmitBuff_test) of slave is called                                     before master receive function spi_lld_receive(&SPID1, TRANSFER_BUFFER_SIZE, &spihandler_mrx_fifo);

RSeba.2
Associate III

Hello,
I am still stuck at spi slave to master communication. I did not received the same bytes that I sent out from slave. 
Could someone help me to solve the issue?