HAL I2C DMA BUGS Why does this simple DMA code Not Work ???
Hello
Having real issues with the I2C DMA HAL code ???
Is it buggy.... very likely from what i'm reading on the web or is there something I am not understanding ??
I'm simply trying to read data back from a i2c flow sensor with minimal interruption to the processor thus why trying to use HAL I2C DMA
when I use use NON DMA I2C code everything is great and works well
HAL_I2C_Master_Receive( &hi2c1, Sensor_Adr << 1 | 0x01, I2C1_DATA , 9, HAL_MAX_DELAY );
Yet when I use the HAL I2C DMA code its broken ????
HAL_I2C_Master_Receive_DMA( &hi2c1, Sensor_Adr << 1 | 0x01 , I2C1_DATA, 9);this should work the same way the non DMA code work, but using the DMA hardware, but we can see it does not....
we can see it starts to initiate a DMA I2C session, but stops after dropping SDA & SCL line why ??????
It should continue to read back the data from the sensor the same way the Non DMA I2C code does. ??
Can someone please help and advise as I am totally lost, what am I missing or is there a bug, thank you in advance for any help
I found this on the internet, not sure if its relevant
I had been struggling with the same problem on STM32F407 and I2C1.
After searching for potential bugs in the program flow, i found out that the function HAL_I2C_Master_Transmit_DMA leads to following line:
dmaxferstatus = HAL_DMA_Start_IT(hi2c->hdmatx, (uint32_t)hi2c->pBuffPtr, (uint32_t)&hi2c->Instance->DR, hi2c->XferSize);
After the first transfer, this won't return HAL_OK, which is necessary for the transmission to continue.
So my solution was simply abort the previous DMA interrupt in the callback function which is called after the transmission has completed. The same can be implied with HAL_I2C_Master_Receive_DMA. To resolve the problem, i added the following callback functions in main.c:
void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c)
{if (hi2c->Instance==hi2c1.Instance)
{HAL_DMA_Abort_IT(hi2c->hdmatx);
}
}
void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c)
{if (hi2c->Instance==hi2c1.Instance)
{ HAL_DMA_Abort_IT(hi2c->hdmarx);
}
}I have tried adding these interrupt call backs but still does not work ??
can someone please advise a workaround for this bug or let me know what I am doing wrong
thank you for any help
regards
