HAL_I2C_mem_read_dma return error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-05 2:45 AM
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)
{
}
}
}
- Labels:
-
DMA
-
I2C
-
STM32Cube MCU Packages
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-05 3:24 AM
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
Thanks
Imen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-05 3:27 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-05 3:49 AM
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
Thanks
Imen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-05 4:24 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-05 6:04 AM
Does the non-DMA version of the function work? What is the error reported in ErrorCode?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-07 11:22 PM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-08 1:11 AM
even using the function HAL_I2C_Mem_read normal returns me error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-08 6:05 AM
What is the value in hi2c1.ErrorCode?
