cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_I2C_mem_read_dma return error

Icont.1
Associate II

I'm connecting to a nucleo144 through configured pins and i2c connection a melexis 90640 (thermal scanner) I initially tried through Hal functions to call the device on the default address I had from the datasheet (0x33) but did not find it so I solved by doing a for from 1 to 128 to find the address once returned HAL_Ok by the function I try to read the data with the function HAL_Mem_Read_DMA but returns error. place below the code. What could be the problem?

//funzione I2C per vedere l'indirizzo a cui è attaccato per poi procedere alla ricezione dei dati
  for(i=0;i<128;i++){
	  err_I2C = HAL_I2C_IsDeviceReady(&hi2c1,(uint8_t)(i<<1), 3, 10);
	  if (err_I2C== HAL_OK){
		  printf("is ready");
		  while (HAL_I2C_GetState(&hi2c1) != HAL_I2C_STATE_READY)
		  {
          }
		  if(HAL_I2C_Mem_Read_DMA(&hi2c1,(uint8_t)(i<<1), MEM_ADDRESS, I2C_MEMADD_SIZE_8BIT, data, 192)!=HAL_OK){
			  Error_Handler();
		  }
		  while (HAL_I2C_GetState(&hi2c1) != HAL_I2C_STATE_READY)
		     {
		     }
	  }
  }

8 REPLIES 8
Imen.D
ST Employee

Hello @Icont.1​ ,

Maybe it's due to CubeMX problem: Incorrect DMA initialization order.

So, try to place the DMA init before I2C init.

If your issue is solved, please select the answer as “Best�? as this will help other users to find answers faster.

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Icont.1
Associate II

this is my init order

 HAL_Init();
 
  /* USER CODE BEGIN Init */
 
  /* USER CODE END Init */
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* USER CODE BEGIN SysInit */
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART3_UART_Init();
  MX_ADC1_Init();
  MX_LTDC_Init();
  MX_USART1_UART_Init();
  MX_USART2_UART_Init();
  MX_I2C4_Init();
  MX_DMA_Init();
  MX_I2C1_Init();
  /* USER CODE BEGIN 2 */
 
  HAL_Delay(1000);

There is an issue with the DMA initialization MX_DMA_Init();, which should be before any other peripheral initialization, and this limitation will be fixed in the next release of CubeMx.

So, please update the DMA init before any other peripheral initialization.

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Icont.1
Associate II

I moved DMA_Init above all initializations, but the problem is not solved. Now I HAL_ ERROR to the call of both HAL_I2C_Mem_Read_DMA and the attempt that I tried later with the function HAL_I2C_Master_Receive_DMA since I had the doubt it was a problem with the memory address

TDK
Guru

Does the non-DMA version of the function work? What is the error reported in ErrorCode?

If you feel a post has answered your question, please click "Accept as Solution".
Icont.1
Associate II

no the version without DMA has not been tested, I will try to implement it today. I know that I have an error because I read the variable that is returned by the function itself so I do not have a specific error but only HAL_ERROR. Possibly how do I know what the specific error is?

Icont.1
Associate II

even using the function HAL_I2C_Mem_read normal returns me error

TDK
Guru

What is the value in hi2c1.ErrorCode?

If you feel a post has answered your question, please click "Accept as Solution".