title: CubeMX - I2C DMA - help needed - ST32F1
body: <p>HAL_I2C_Mem_Write_DMA / HAL_I2C_Mem_Read_DMA what is the problem ?</p>
  
  <p>Hi I'm trying to run I2C in DMA mode with LIS35 (accelerometer). I wrote simple code as below but each time when I try to run or debug it I'm getting back return "LIS35_ERROR;" which means that LIS35_I2C_Init(void) function goes wrong.</p>
  
  <p>Previously (I mean yesterday) I wrote two similarly projects:</p>
  
  <p>First was based on HAL_I2C_Mem_Write / HAL_I2C_Mem_Read  functions
  - and all works properly (return LIS35_OK;)</p>
  
  <p>Second was based on HAL_I2C_Mem_Write_IT / HAL_I2C_Mem_Read_IT functions
  - and all works properly(return LIS35_OK;)</p>
  
  <p>Environment:</p>
  
  <ul>
  <li>STM32CubeMX - updated today,</li>
  <li>Board - Nucleo-F103RB</li>
  <li>CubeMX project added as attachment</li>
  <li>I2C configuration al on pictures below</li>
  </ul>
  
  <p><a href="https://i.stack.imgur.com/GDq2t.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GDq2t.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/rncvn.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rncvn.jpg" alt="enter image description here"></a></p>
  
  <pre><code>/* USER CODE BEGIN 4 */
  char LIS35_I2C_Init(void)
  {
  uint8_t Sett_Lis35_cr2_boot = LIS35_REG_CR2_BOOT;
  uint8_t RegVal, LIS35Settings; 
  HAL_StatusTypeDef state1, state2, state3;
  volatile long int i;
  
  
  
  //reset LIS35 settings
  if(HAL_I2C_Mem_Write_DMA(&amp;hi2c2, LIS35_Addr, LIS35_REG_CR2, 1, &amp;Sett_Lis35_cr2_boot, 1) != HAL_OK) {
     //led blink info
  }
  while (HAL_I2C_GetState(&amp;hi2c2) != HAL_I2C_STATE_READY){}
  
  
  
  //Write settings - activate all axis
  LIS35Settings = LIS35_REG_CR1_XEN | LIS35_REG_CR1_YEN | LIS35_REG_CR1_ZEN | LIS35_REG_CR1_ACTIVE; 
  
  //WRITE CONFIGURATION TO LIS35 CHIP
  if(HAL_I2C_Mem_Write_DMA(&amp;hi2c2, LIS35_Addr, LIS35_REG_CR1, 1, &amp;LIS35Settings, 1)!= HAL_OK) {
     //led blink info
  }
  while (HAL_I2C_GetState(&amp;hi2c2) != HAL_I2C_STATE_READY){} 
  
  //Read configuration - if OK, LIS35 is up and running
  if(HAL_I2C_Mem_Read_DMA(&amp;hi2c2, LIS35_Addr, LIS35_REG_CR1, 1, &amp;RegVal, 1) != HAL_OK) {
     //led blink info
  
  }
  while (HAL_I2C_GetState(&amp;hi2c2) != HAL_I2C_STATE_READY){}
  
  if (RegVal == LIS35Settings){
     HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);
     return LIS35_OK;
  }
  return LIS35_ERROR;
  }
  
  void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c){
  static uint8_t cntTx;
  cntTx++;
  }
  
  void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c){
  static uint8_t cntRx;
  cntRx++;
  }
  
  /* USER CODE END 4 */
  </code></pre>
  
  <p>Thanks in advance for any help :-) </p>
  
  <p>Farnk</p>