2020-12-16 05:27 AM
Hi,
I am currently working on DMA combined with I2C bus. I want to read acceleration data from IKS01A3 with HAL function HAL_I2C_Mem_Read_DMA(). I want to read at 6 different memory registers. How can I use that function to get it work properly? Can I queue read calls one after another? Is there any option to differ read i2c callbacks between reads (just to rise a flag that memory read from particular region was successful)?
Thanks in advance.
Lukasz
2020-12-17 07:35 AM
Hi Lukasz @Community member ,
not an expert, so I'm adding the DMA topic for more technical support.
For configuring the I2C communication for the sensor via DMA, you could refer to this thread on a similar argument.
For the reading of the sensor data from the DMA with the VCOM, you taking for example the com.c file function in the X-CUBE_MEMS1 project at folder: \Projects\STM32L476RG-Nucleo\Applications\IKS01A3\DataLogFusion\STM32CubeIDE, drawn here below:
void UART_StartReceiveMsg(void)
{
hcom_uart[COM1].pRxBuffPtr = (uint8_t *)UartRxBuffer; /* MISRA C-2012 rule 11.8 violation for purpose */
hcom_uart[COM1].RxXferSize = UART_RxBufferSize;
hcom_uart[COM1].ErrorCode = (uint32_t)HAL_UART_ERROR_NONE;
/* Enable the DMA transfer for the receiver request by setting the DMAR bit
in the UART CR3 register */
/* MISRA C-2012 rule 11.8 violation for purpose */
(void)HAL_UART_Receive_DMA(&hcom_uart[COM1], (uint8_t *)UartRxBuffer, UART_RxBufferSize);
}
Let me know if these indications can be of some help for your application.
-Eleon
2020-12-18 01:44 AM
Hello Eleon,
Unfortunately my problem is slightly more complex. As I mentioned I want to use HAL_I2C_Mem_Read_DMA() function. Reading UART is easier due to one device and bus. Problem appears when you are using bus with few devices. How to differ DMA transfer complete callback from i2c for different devices - or even memory address?
Thanks for your replay though.
-Lukasz
2020-12-21 08:27 AM
Hi Lukasz,
unfortunately I'm not an expert on this point... I've added also the STM32 topic for more help.
I might check internally and I'll get back to you in case I'll be able to find a solution.
-Eleon
2020-12-22 02:58 AM
Hi Eleon,
If you could check it internally that would be great =) To be clear I want to run following, non-blocking, code:
...
// hi2c1 - i2c handle, DEV_ADDR - device i2c addres, MEM_ADDR_x - memory address
// SIZE - memory size, data_x - my data container
HAL_I2C_Mem_Read_DMA(hi2c1, DEV_ADDR, MEM_ADDR_1, SIZE, &data_1, sizeof(data_1));
HAL_I2C_Mem_Read_DMA(hi2c1, DEV_ADDR, MEM_ADDR_2, SIZE, &data_2, sizeof(data_2));
...
According to the documentation, when DMA completes transfer data it will call function:
HAL_I2C_MemTxCpltCallback ( I2C_HandleTypeDef * hi2c)
My question is, how do I know which memory read was complete?
Thanks a lot!
Lukasz
2021-02-01 01:39 AM
Bump. Anyone able to help?
2021-02-05 04:58 AM
Unfortunately, I didn't found the right person internally :(
You could try with the OLS support form st.com Contact page...
-Eleon