cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Reception Issue with DMA in HAL Library

MHuan.18
Associate

Hello

I am implementing I2C transfer with DMA in stm32.

Processor: stm32l152rdt6

DMA Configuration:

I would like to continuously receive 3 bytes from master, so I use circular mode.

0690X00000AA9vBQAT.png

NVIC Configuration:

0690X00000AA9vLQAT.png

I2C Initialization Code:

  hi2c1.Instance = I2C1;
  hi2c1.Init.ClockSpeed = 400000;
  hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
  hi2c1.Init.OwnAddress1 = I2C_ADDRESS*2;
  hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
  hi2c1.Init.OwnAddress2 = 0;
  hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
  hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
  if (HAL_I2C_Init(&hi2c1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN I2C1_Init 2 */
  HAL_I2C_Slave_Receive_DMA( &hi2c1, ucRxbuffer_obc, 3);

I use HAL_I2C_SlaveRxCpltCallback to check transfer condition.

However, it seems the callback function only triggered in first time.

void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *hi2c)
 {
 
   if(hi2c->Instance == I2C1)
   {
       sprintf(cMessage, "message[0]: %u\n\r", ucRxbuffer_obc[0]);
       debugprintf(cMessage);
   }
 
  
 }

I trace the condition and I found DMA state of RX kept busy but I have no idea how to deal with it.

Is there anything I miss?

0 REPLIES 0