use both I2C Master DMA and UART DMA at once
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-26 10:44 PM
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
- Labels:
-
DMA
-
I2C
-
UART-USART
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-30 3:18 AM
Hi @Frogram​ ,
- Does Uart DMA work properly?
- 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-30 4:40 AM
Hi
- yes, UART DMA works well
- I used STM32CubeIDE for create .ioc and here is no HAL_DMA_Init() only MX_DMA_Init(). how could I add it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-30 4:46 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-30 5:01 AM
The code was already set as you said. TT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-30 5:32 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-31 12:31 AM
how should I set priority? one of them as higher?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-09-01 8:01 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-09-09 4:42 AM
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.
