Skip to main content
deep_rune
Associate III
October 19, 2020
Question

I2C driver always busy after first use

  • October 19, 2020
  • 2 replies
  • 1099 views

I'm using the HAL_I2C_Master_Transmit_DMA driver on an STM32L412. I am transmitting 8 bytes of data to an external 4 channel I2C DAC - I have only one device on the bus. The first use of the driver works fine as confirmed by using an oscilloscope on i2c bus, the DAC updates and there is a stop condition. From then on the driver always returns a busy status - specifically at the point where the driver uses HAL_DMA_Start_IT .

Ive read other people mention the same (or very similar) problems when using the I2C HAL drivers, is there a fix for this?

 setup for i2c

static void MX_I2C2_Init(void)
{
 hi2c2.Instance = I2C2;
 hi2c2.Init.Timing = 0x00610611;
 hi2c2.Init.OwnAddress1 = 192;
 hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
 hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
 hi2c2.Init.OwnAddress2 = 0;
 hi2c2.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
 hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
 hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
 if (HAL_I2C_Init(&hi2c2) != HAL_OK)
 {
 Error_Handler();
 }
 /** Configure Analogue filter 
 */
 if (HAL_I2CEx_ConfigAnalogFilter(&hi2c2, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
 {
 Error_Handler();
 }
 /** Configure Digital filter 
 */
 if (HAL_I2CEx_ConfigDigitalFilter(&hi2c2, 0) != HAL_OK)
 {
 Error_Handler();
 }
 
}

 setup for DMA

static void MX_DMA_Init(void) 
{
 
 /* DMA controller clock enable */
 __HAL_RCC_DMA1_CLK_ENABLE();
 
 /* DMA interrupt init */
 /* DMA1_Channel4_IRQn interrupt configuration */
 HAL_NVIC_SetPriority(DMA1_Channel4_IRQn, 0, 0);
 HAL_NVIC_EnableIRQ(DMA1_Channel4_IRQn);
 
}

This topic has been closed for replies.

2 replies

MIerv.1
Associate
November 10, 2020

Did you found a solution for this? I'm having problems with I2C + DMA too...

deep_rune
deep_runeAuthor
Associate III
November 23, 2020

I found that I had the circular mode turned on. I turned that off and everything was fine