cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 I2C only transmits and receives once

HamzaBeder
Associate

MCU: STM32L476RGT6

Hello,

I am able to communicate with the MPU6050 via I2C with DMA and read the WHO_AM_I register, but only one transmit and receive transaction occurs even though I put my transmission and receive code in a while loop.

When using regular I2C transmission (no DMA), multiple transactions are performed (as expected). This tells me that there may be some flags I need to reset or functions I need to call between transmission. However, when comparing my code to this example, I could not tell what I was missing.

My code is getting stuck on line 61 here. That tells me that an internal process is occurring, so the MCU is never ready for another transmission.

Below is my driver code. What am I missing?

Thanks.

#define MPU6050ADDR 0b11010010
int main(void)
{
uint8_t WHO_AM_I[1] = {0x75};
HAL_Init();
SystemClock_Config();
I2C_Init();
DMA_Init();
while (1)
{
if(HAL_I2C_Master_Transmit_DMA(&hI2C, MPU6050ADDR, WHO_AM_I, 1,100) != HAL_OK)
Error_Handler();
while (HAL_I2C_GetState(&hI2C) != HAL_I2C_STATE_READY);
while(HAL_I2C_GetError(&hI2C) == HAL_I2C_ERROR_AF);
if(HAL_I2C_Master_Receive_DMA(&hI2C, MPU6050ADDR, Buffer_Dest,1,100) != HAL_OK)
Error_Handler();
while (HAL_I2C_GetState(&hI2C) != HAL_I2C_STATE_READY);
while(HAL_I2C_GetError(&hI2C) == HAL_I2C_ERROR_AF); }
}

 

0 REPLIES 0