cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G030F6 I2C2 set to slave mode, it can not work fine.

RSun.1
Associate

I am newer in STM32G030 develop.

I tried to set STM32G030F6 I2C2 slave mode with PC.

Q1.Using "HAL_I2C_Slave_Transmit(); it seems Master (PC) read 8 bytes later and stop. The

other data will not read.

Q2. If used HAL_I2C_Slave_Transmit_IT(), It only write the address +ACK then stop.

The major code is as below. System clock, I2C2 and GPIO setting are base on STM32CubeIDE.

The Slave address is 0xA0. I2C clock 100-400K has the same result.

  1. uint32_t i;
  2.  
  3.  HAL_Init();
  4.  
  5.  SystemClock_Config();
  6.  
  7.  /* Initialize all configured peripherals */
  8.  MX_GPIO_Init();
  9.  MX_I2C2_Init();
  10.  /* USER CODE BEGIN 2 */
  11.  
  12. /* Ram_Table[256], Page_Start=0x800F800 */
  13. for(i=0;i<256;i++)
  14. {
  15. Ram_Table[i] = *((__IO uint8_t *)(Page_Start+i));
  16. }
  17.  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
  18.  HAL_Delay(1000);
  19.  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
  20.  
  21.  while (HAL_I2C_Slave_Transmit(&hi2c2, (uint8_t *)Ram_Table, 256, 100) != HAL_OK); <-Q1
  22.  
  23. /* HAL_I2C_Slave_Transmit_IT(&hi2c2, (uint8_t *)Ram_Table, 256); */ <-Q2
  24.  /* USER CODE END 2 */
  25.  
  26.  static void MX_I2C2_Init(void)
  27. {
  28.  hi2c2.Instance = I2C2;
  29.  hi2c2.Init.Timing = 0x00303D5B;
  30.  hi2c2.Init.OwnAddress1 = 0x00A0;
  31.  hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  32.  hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
  33.  hi2c2.Init.OwnAddress2 = 0;
  34.  hi2c2.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
  35.  hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
  36.  hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
  37.  if (HAL_I2C_Init(&hi2c2) != HAL_OK)
  38.  {
  39.   Error_Handler();
  40.  }
  41.  /** Configure Analogue filter
  42.  */
  43.  if (HAL_I2CEx_ConfigAnalogFilter(&hi2c2, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
  44.  {
  45.   Error_Handler();
  46.  }
  47.  /** Configure Digital filter
  48.  */
  49.  if (HAL_I2CEx_ConfigDigitalFilter(&hi2c2, 0) != HAL_OK)
  50.  {
  51.   Error_Handler();
  52.  }
  53. }

cheers,

0 REPLIES 0