I am trying to connect an 18-bit SPI ADC to the S32K144(W) for continuous sampling between 40 kSPS up to 400kSPS. For that speed, I need DMA data collection. I implemented it with two Rx buffers.
The DMA TX Data Ready Interrupt occurred when the last 4 bytes were loaded to the SPI TX buffer, as seen in Figure 1.
The "LPSPI_DRV_MasterTransfer" instruction does not affect if the transmission is in progress.
To overcome this future of "LPSPI_DRV_MasterTransfer" I introduced some delay. Figure 2 shows a delay that is not long enough.
Figure 3 shows a "continuous transmission but with gaps between the packages. The gaps are 15.2 us long. The packages are 256 bytes long, which correspond to 64 ADC samples.
The measured signal is a communication signal, and the gaps are not acceptable.
What is the solution?
The IRQ is:
static void delayDbg(volatile int cycles)
{
/* Delay function - do nothing for a number of cycles */
while(cycles--);
}
int32_t rxADCdata, counter, *xp;
int8_t iBufSelect;
/******************************************************************************'
*
* DMA 5 TX Interrupt Handler
*
****************************************************************************/
static void DMA5_IRQnHandler(void)
{
BLUE_ON; /* LED On */
DMA->CINT = DMA_CINT_CINT(DMA5_IRQn); /** Clear the interrupt flag! */
delayDbg(145); /* Required Delay ? */
if( continuousSPI == true)
{
iBufSelect = (iBufSelect +1) & 0x01; /* Switch buffer */
LPSPI_DRV_MasterTransfer(INST_LPSPI_1, uTx.b,uRx[iBufSelect].b, SPI_BYTE_BUFFER_LNGH);
}
BLUE_OFF; /* LED Off */
}
Hi,
instead of fixed delay you can try to call LPSPI_DRV_MasterGetTransferStatus function in loop to know driver is ready to call new LPSPI_DRV_MasterTransfer.
However the additional delay you see can be simply due to driver overhead, you can refer to its code.
You can try to use some nonSDk code, e.g. https://community.nxp.com/t5/S32K-Knowledge-Base/Example-S32K144-LPIT-DMA-LPSPI/ta-p/1108628, but you need to tailor it for your needs.
BR, Petr