Hi NXP team,
(1) application requirements is: in brief, using s32k344 to send data with arbitrary length to another s32k344 through SPI interface as fast as possible.
(2) However, the SPI slave can only receive data with fixed length. So, if we decide to send data in fixed length. For example, if we want to send 112bytes data, we ill send it in 50byte, 50bytes, 50bytes(=12bytes valid data+38bytes zero).
(3) Hardware enviroment:
We use two S32K3X4EVB-Q257 Evaluation Board. And it's connection is as following.
(4) Software enviroment:
(4-1) SDK: S32DS, RTD1.0.0, C language
(4-3) SPI2 is in master mode, disable DMA. SPI5 is in slave mode, enabled DMA, Both SPI5's DMA tx channel and rx channel are enabled.
(5) src code in EVB1 and EVB2 are the same, the code in main.c was attached.
(6) We need help in the problem that :
If we send data in steps: SyncSend 50, SyncSend 50, SyncSend 50, the spi5 slave will get into LPSPI_IP_EVENT_FAULT.
But if we send data in steps: SyncSend 50, delay 1m, SyncSend 50, delay 1ms, SyncSend 50, delay 1ms. The spi5 will always receive right.
Best regards,
autolan22
Solved! Go to Solution.
Hi @autolan22,
I think you just have to make sure that the transfer in the slave device is initialized before the master starts the transfer.
For example, a GPIO signal can be used to notify the master that the slave is ready.
BR, Daniel
P.S. This is the main.c code of my project.
```````````````````````````````````````main.c source code begin``````````````````````````````````````````````````````````````
// @brief SPI INIT CODE
void InitSpi2AsMasterAndSpi5AsSlave(void) {
Lpspi_Ip_Init(&Lpspi_Ip_PhyUnitConfig_SpiPhyUnit_2_BOARD_InitPeripherals);
Lpspi_Ip_UpdateTransferMode(RT1176_SPI_MASTER_INSTANCE, LPSPI_IP_INTERRUPT);
Lpspi_Ip_Init(&Lpspi_Ip_PhyUnitConfig_SpiPhyUnit_5_BOARD_InitPeripherals);
Lpspi_Ip_UpdateTransferMode(RT1176_SPI_SLAVE_INSTANCE, LPSPI_IP_INTERRUPT);
}
// @brief EVB1 spi master send code demo
#define SPI2_TX_LEN_PER_TIME 50
const char spi2_send[112] = "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy123456789012";
char spi2_txbuf[SPI2_TX_LEN_PER_TIME] ;
char spi2_rxbuf[SPI2_TX_LEN_PER_TIME] = {0};
void Spi2AsyncSendLongBytesData(void) {
for (uint8_t i = 0; i < 3; i++) {
uint8_t length = i == 2 ? 12 : SPI2_TX_LEN_PER_TIME;
memcpy(spi2_txbuf, spi2_send, length);
Lpspi_Ip_SyncTransmit(&Lpspi_Ip_DeviceAttributes_SpiExternalDevice_2_BOARD_InitPeripherals,spi2_txbuf, spi2_rxbuf, 50, 1000);
rt_thread_delay_ms(1); // !!!! if not delay 1ms, SPI5 slave receive irq will enter LPSPI_IP_EVENT_FAULT in Spi5SlaveDmaCallback
}
}
// @brief EVB2 spi slave receive code demo
char spi5_recv[50] = {0};
const char spi5x_send[50] = {0};
void Spi5SlaveDmaCallback(uint8 Instance, Lpspi_Ip_EventType Event) {
if (Instance == 5) {
switch (Event) {
case LPSPI_IP_EVENT_END_TRANSFER:
Lpspi_Ip_AsyncTransmit(&Lpspi_Ip_DeviceAttributes_SpiExternalDevice_5_BOARD_InitPeripherals, spi5x_send, spi5_recv, 32, Rt1176SpiAsyncRecvCallback);
break;
case LPSPI_IP_EVENT_FAULT://
rt_kprintf("e");
break;
default:
break;
}
}
}
void StartSpi5SlaveDmaRecvData(void) {
Lpspi_Ip_AsyncTransmit(&Lpspi_Ip_DeviceAttributes_SpiExternalDevice_5_BOARD_InitPeripherals, spi5x_send, spi5_recv, 32, Rt1176SpiAsyncRecvCallback);
}
void main()
{
InitSpi2AsMasterAndSpi5AsSlave();
StartSpi5SlaveDmaRecvData()
//Create a RTOS thread that call fuction Spi2AsyncSendLongBytesData(); in every 1ms.
}
`````````````````````````````main.c source code end``````````````````````````````````````````
New progress.
I tried to use only one S32K344 and make it send by SPI2 while receive from SPI5.
A little Iike loopback mode.
And in this way, the SPI5 slave won't get into LPSPI_IP_EVENT_FAULT = 1.
Emmmmmmm?
Hi @autolan22,
I think you just have to make sure that the transfer in the slave device is initialized before the master starts the transfer.
For example, a GPIO signal can be used to notify the master that the slave is ready.
BR, Daniel
Hi Daniel, @danielmartynek
Thank you very much. You always have good ideas!
For some reason, I plan to try this method you suggested in two months, and then sync the test results to you!
BR, Lan