cancel
Showing results for 
Search instead for 
Did you mean: 

use both I2C Master DMA and UART DMA at once

Frogram
Associate II

Hi all,

I am trying to use I2C DMA as Master and UART DMA

My code is

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim){
  if (c == 1)  {
	  HAL_UART_Transmit_DMA(&huart2, (uint8_t *)b, 8);
  } else {
	  /* I2C Transmit code */
  }
  c = 1 - c;
}

and which I tried are (instead of /* I2C Transmit code */) :

// 1. polling, it worked
	  HAL_I2C_Master_Transmit(~~, 50);
	  HAL_I2C_Master_Receive(~~, 50);
// 2. DMA, not worked
          HAL_I2C_Master_Transmit_DMA(~~);
          HAL_I2C_Master_Receive_DMA(~~);
// 3. Mem read dma, not worked
	  HAL_I2C_Mem_Read_DMA(~~);
// 4. Seq DMA, not worked
	  HAL_I2C_Master_Seq_Transmit_DMA(~~, I2C_FIRST_FRAME);
	  HAL_I2C_Master_Seq_Receive_DMA(~~, I2C_LAST_FRAME);

I have no Idea whats wrong and how to solve it

thanks

8 REPLIES 8
Amel NASRI
ST Employee

Hi @Frogram​ ,

  1. Does Uart DMA work properly?
  2. Is your initialization code generated with STM32CubeMX? If you are using latest STM32CubeMX version 6.3.0, please make sure to have correct order for HAL_DMA_Init() and peripheral init.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Frogram
Associate II

Hi

  1. yes, UART DMA works well
  2. I used STM32CubeIDE for create .ioc and here is no HAL_DMA_Init() only MX_DMA_Init(). how could I add it?

Yes it is MX_DMA_Init().

Please make sure that it is called after MX_I2C_Init().

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

The code was already set as you said. TT

I wanted to discard the fact that root cause of your issue is generated initialization code by STM32CubeMX.

Now it should be better to try to run I2C in DMA mode as a standalone application.

If it is working, then check interrupts priority.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

how should I set priority? one of them as higher?

I2C is time-sensitive. It is recommended to set higher priority for its interrupts.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi @Frogram​ ,

Sorry, what I said in my previous comment is wrong:

Yes it is MX_DMA_Init().

Please make sure that it is called after MX_I2C_Init().

In fact, I2C initialization modifies some DMA register and needs its clock to be activated (here an explanation provided by TDK).

That is why it is required to call MX_DMA_Init() first then MX_I2C_Init(). STM32Cub eMX has to do this for you, but it is a regression in 6.3.0 version.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.