AnsweredAssumed Answered

STM32F103 I2C Problem

Question asked by mt.aveal on Mar 16, 2016
Latest reply on Mar 21, 2016 by leach.clark
Hello!

I'm trying to connect STM32F103RBT6 to LIS331DLH (accelerometer). LIS331 is connected to PB6/PB7 (I2C1) with pull-up resistors (4K7).

STM32CubeMX generated simple code and I added only HAL_I2C_Master_Transmit() function:


int main(void)
{
 
  /* USER CODE BEGIN 1 */
 
  /* USER CODE END 1 */
 
  /* MCU Configuration----------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_I2C1_Init();
 
  result = HAL_I2C_Master_Transmit(&hi2c1, 0x30, sendData, 1, 2000);
   
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  }
}


The problem is that BUSY flag is alwauys set, so the program can't pass the first while() in function HAL_I2C_Master_Transmit():

if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BUSY, SET, I2C_TIMEOUT_BUSY_FLAG) != HAL_OK)
{
  return HAL_BUSY;
}


How can I solve this problem?

Thank you in advance!

Outcomes