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.
- uint32_t i;
-
- HAL_Init();
-
- SystemClock_Config();
-
- /* Initialize all configured peripherals */
- MX_GPIO_Init();
- MX_I2C2_Init();
- /* USER CODE BEGIN 2 */
-
- /* Ram_Table[256], Page_Start=0x800F800 */
- for(i=0;i<256;i++)
- {
- Ram_Table[i] = *((__IO uint8_t *)(Page_Start+i));
- }
-
- HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
- HAL_Delay(1000);
- HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
-
- while (HAL_I2C_Slave_Transmit(&hi2c2, (uint8_t *)Ram_Table, 256, 100) != HAL_OK); <-Q1
-
- /* HAL_I2C_Slave_Transmit_IT(&hi2c2, (uint8_t *)Ram_Table, 256); */ <-Q2
-
- /* USER CODE END 2 */
-
- static void MX_I2C2_Init(void)
- {
- hi2c2.Instance = I2C2;
- hi2c2.Init.Timing = 0x00303D5B;
- hi2c2.Init.OwnAddress1 = 0x00A0;
- hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
- hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
- hi2c2.Init.OwnAddress2 = 0;
- hi2c2.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
- hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
- hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
- if (HAL_I2C_Init(&hi2c2) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure Analogue filter
- */
- if (HAL_I2CEx_ConfigAnalogFilter(&hi2c2, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure Digital filter
- */
- if (HAL_I2CEx_ConfigDigitalFilter(&hi2c2, 0) != HAL_OK)
- {
- Error_Handler();
- }
- }
cheers,