AnsweredAssumed Answered

difference between HAL_I2C_Mem_Write() and HAL_I2C_Mem_Write_DMA()

Question asked by park.dongsoo on Jul 3, 2016
Latest reply on Apr 4, 2018 by Frank CA

 

Hello,
I generated the code using the STM32CubeMx.
I'm trying to I2C communication between STM32F4(master) and IC(slave, 7bit address).
I tested to two functions for I2C communication.

HAL_I2C_Mem_Write is OK, but HAL_I2C_Mem_Write_DMA is fail.
Test condition and setting parameters are same only except the function.
please let me know why HAL_I2C_Mem_Write_DMA() is didn't work.

thank you.

==================================================================
//test code

/* I2C1 init function */
static void MX_I2C1_Init(void)
{
  hi2c1.Instance = I2C1;
  hi2c1.Init.ClockSpeed = 100000;
  hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
  hi2c1.Init.OwnAddress1 = 0;
  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();
  }
}

static void MX_DMA_Init(void) 
{
  /* DMA controller clock enable */
  __HAL_RCC_DMA1_CLK_ENABLE();

  /* DMA interrupt init */
  /* DMA1_Stream0_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(DMA1_Stream0_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(DMA1_Stream0_IRQn);
  /* DMA1_Stream2_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(DMA1_Stream2_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(DMA1_Stream2_IRQn);
  /* DMA1_Stream4_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(DMA1_Stream4_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(DMA1_Stream4_IRQn);
  /* DMA1_Stream6_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(DMA1_Stream6_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(DMA1_Stream6_IRQn);
}

 



void main(void)
{
         uint8_t error;
         uint8_t data[3];
         data[0] = 0x47;

         error = HAL_I2C_Mem_Write(&hi2c1, 0x82, 0x3f, 1,  data, 1,100); //succeed
         error = LT_I2C_Write_DMA(&lt_i2c1_, 0x82, 0x3f, data, 1); //fail
}

success: HAL_I2C_Mem_Write(Dev Add: 0x82, Mem Add: 0x3f, data: 0x47)
HAL_I2C_Mem_Write_.jpg



FAIL: HAL_I2C_Mem_Write_DMA(Dev Add: 0x82, Mem Add: 0x3f, data: 0x47)
HAL_I2C_Mem_Write_DMA_.jpg

Attachments

Outcomes