cancel
Showing results for 
Search instead for 
Did you mean: 

How to read multiple IKS01A03 memory register with DMA over i2c?

LZure.old
Associate II

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

6 REPLIES 6
Eleon BORLINI
ST Employee

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

LZure.old
Associate II

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

Eleon BORLINI
ST Employee

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

LZure.old
Associate II

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

LZure.old
Associate II

Bump. Anyone able to help?

Unfortunately, I didn't found the right person internally :(

You could try with the OLS support form st.com Contact page...

-Eleon