lpspi_dma_slave cant't communicate continously with master

cancel
Showing results for 
Search instead for 
Did you mean: 

lpspi_dma_slave cant't communicate continously with master

147 Views
Faker
Contributor II

Hi,
I encounter a question about the example of lpspi_dma_slave_s32k116.I want to use s32k116 as slave to continously communicate with master which is the other device.
Here are my steps:
1.using EDMA_DRV_Init(),LPSPI_DRV_SlaveInit() init lpspi,dma and LPSPI_DRV_SlaveTransfer(LPSPICOM1, NULL, slaveDataReceive, 5) only receive master's messages.
2.using LPSPI_DRV_SlaveGetTransferStatus(LPSPICOM1, &remainBytes) obtains lpspi's state. If the return value is STATUS_SUCCESS, LPSPI_DRV_SlaveTransfer(LPSPICOM1, data, NULL, slaveDataReceive[4]) will be called to send messages to master.we want to use this half duplex mode to communicate with each other.But the question is that it fails to receive messages using the above method in second times. So I need to call EDMA_DRV_Init() every time when I want to receive messages.Then the function LPSPI_DRV_SlaveTransfer(LPSPICOM1, NULL, slaveDataReceive, 5) can receive messages and LPSPI_DRV_SlaveTransfer(LPSPICOM1, data, NULL, slaveDataReceive[4]) can send messages one time.
3.Using the above method could solve continuous sending problem.The slave sometimes has received messages successfully,But it sending messages fail.The master receives "0xffff",and it needs to send messages again. After that, the salve can send messages successfully.In short, using 2's method need to resend several times from master,then the slave can send messages successfully.
Pseudocode as following:
PINS_DRV_Init;
EDMA_DRV_Init;
LPSPI_DRV_SlaveInit;
LPSPI_DRV_SlaveTransfer(LPSPICOM1, NULL, slaveDataReceive, 5);
while(1)
{
ret = LPSPI_DRV_SlaveGetTransferStatus(LPSPICOM1, &remainBytes);
if(ret == STATUS_SUCCESS && ...)//receive messages
{
EDMA_DRV_Init(&dmaController1_State, &dmaController1_InitConfig0, edmaChnStateArray, edmaChnConfigArray, EDMA_CONFIGURED_CHANNELS_COUNT);
LPSPI_DRV_SlaveTransfer(LPSPICOM1, NULL, slaveDataReceive, 5);
}
if(ret == STATUS_SUCCESS && ...)//send messages
{
LPSPI_DRV_SlaveTransfer(LPSPICOM1, data, NULL, slaveDataReceive[4]);
}
}

0 Kudos
1 Reply

133 Views
Faker
Contributor II

I have solved it by searching "LPSPI_DRV_SlaveTransfer" in Forums. This function's Tx, Rx buffers need to be used together.