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