Skip to main content
Graduate
October 20, 2025
Question

DMA SPI need 2 read S2LP Module

  • October 20, 2025
  • 3 replies
  • 285 views

Hi everyone,
I'm currently working on project witch use SPi with DMA and S2LP Module

I have a function that initializes the DMA portion :
image_2025-10-20_110824548.png

In my code I try to read information in DMA through the SpiritDeviceVersion and SpiritReadnbinfifo functions:

image_2025-10-20_105908658.png

 

 

However, I get my data, but only when I call a DMA read 2 times :

nbOctetRecuB = the value I should read from nbOctetRecuA (0xC1)

nbOctetRecuB2 = the value I should read from nbOctetRecuB (0x0A, my FIFO element count)

nbOctetRecuC = the value I should read from nbOctetRecuB2 (0x0A, my FIFO element count) => whereas I expect 0xC1.

 

Below are one of those function:

image_2025-10-20_110759326.png

I don't understand witch element is missing, why i need to perform another DMA operation to get my data ?

Just a heads-up, a double DMA operation is needed : so if I read S2LP register with DMA, and after Reread DMA without using SPI (ex no CS command) i get my data, this is what it tell me the problem isen't from the SPI ?

Is anyone get tis issue ?

Tanks for your time, Regards.

    This topic has been closed for replies.

    3 replies

    Technical Moderator
    October 20, 2025

    Hello @Quentin_27 ,

    Please use </> button to share your code instead of pasting screenshots. Please read How to insert source code.

    Thank you for your understanding.

    Super User
    October 20, 2025

    Does it work OK without DMA ?

    Have you used an oscilloscope or logic analyser to see what's actually happening on the SPI wires?

    Graduate
    October 20, 2025

    Hi,

    Yes it works without DMA,

    All is correct on SPI Wires as you can see below  (Last ligne is CS#, Frequency 1MHz, and I have try 4MHz):
    image_2025-10-20_133518917.png

    Tanks for your time, Regards.

    Super User
    October 20, 2025

    Thanks for the LA screenshot.

    Does it show the DMA or non-DMA case?

    Do you see any differences?

    Graduate
    October 20, 2025

    That's the problem, I havent any differences on SPI bus..
    The Screenshot show the DMA-case , so when i'm using DMA actually, i need to do that to get my data and not the previous (SPI 1 time and DMA read 2 times):

    //-----------------------------------------------------------------------------
    uint8_t SpiritDeviceVersion (void)
    //-----------------------------------------------------------------------------
    {
    	volatile uint8_t	toto;
    
    	g_SPI_DMA_TxBuffer[0] = (HEADER_READ | HEADER_ADDRESS);
    	g_SPI_DMA_TxBuffer[1] = (S2LP_REG_DEVICE_INFO0); 		// 0xF1
    	g_SPI_DMA_TxBuffer[2] = (0x00);
    
    
    	S2LP_CS_DEBUT;
    	DMA1_Channel2->CNDTR = 0x03;			//3 data
    	DMA1_Channel1->CNDTR = 0x03;			//3 data
    
    
    	//Activation des 2 canaux
    	DMA1_Channel2->CCR |= DMA_CCR_EN;
    	DMA1_Channel1->CCR |= DMA_CCR_EN;
    
    
    
    
    	while(DMA1_Channel1->CNDTR != 0) asm("nop");
    	while(DMA1_Channel2->CNDTR != 0) asm("nop");
    
    	//	S2LP_SpiReadWrite (HEADER_READ | HEADER_ADDRESS);
    	//	S2LP_SpiReadWrite (0xF1);
    	//	toto=S2LP_SpiReadWrite (0x00);
    	S2LP_CS_FIN;
    
    	//Activation des 2 canaux
    	DMA1_Channel1->CCR &= ~DMA_CCR_EN;
    	DMA1_Channel2->CCR &= ~DMA_CCR_EN;
    
    
    
    
    	//==========================2eme lecture==========================
    	DMA1_Channel2->CNDTR = 0x03;			//3 data
    	DMA1_Channel1->CNDTR = 0x03;			//3 data
    
    	DMA1_Channel2->CCR |= DMA_CCR_EN;
    	DMA1_Channel1->CCR |= DMA_CCR_EN;
    
    //	while(DMA1_Channel1->CNDTR != 0) asm("nop");
    //	while(DMA1_Channel2->CNDTR != 0) asm("nop");
    
    	while (!(DMA1->ISR & DMA_ISR_TCIF2))
    	{
    	 // NOP ou rien
    	 asm("nop");
    	}
    	DMA1->IFCR = DMA_IFCR_CTCIF2; // clear flag
    
    	DMA1_Channel1->CCR &= ~DMA_CCR_EN;
    	DMA1_Channel2->CCR &= ~DMA_CCR_EN;
    
    	//==========================Fin 2eme lecture=======================
    
    
    
    	toto = g_SPI_DMA_RxBuffer[2];
    	return toto;	//**** Spirit1 : 0x30 attendu *****
    	//**** S2LP : 0x91 attendu *****
    
    }

    I have try another flag to check DMA here but no difference.
    Tanks for your time, Regards.