2020-12-05 12:33 AM
Hello
I Have stm32f107vct6 And I Want to send data from master to slave I2C Protocol . I Wrote Some code But it didn't work.
Do you Have complete Example for i2c?
this is my code
Master:
while(1){
while(!__HAL_I2C_GET_FLAG(&hi2c1,I2C_FLAG_BUSY))
HAL_I2C_Master_Transmit(&hi2c1, 0x80, buffer,20, 10);
HAL_Delay(500);
}
Slave:
hi2c1.Instance = I2C1;
hi2c1.Init.ClockSpeed = 400000;
hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
hi2c1.Init.OwnAddress1 = 0x80;
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hi2c1.Init.OwnAddress2 = 0;
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
if (HAL_I2C_Init(&hi2c1) != HAL_OK)
{
Error_Handler();
}
HAL_I2C_EnableListen_IT(&hi2c1);
void I2C1_EV_IRQHandler(void)
{
/* USER CODE BEGIN I2C1_EV_IRQn 0 */
HAL_I2C_Slave_Receive(&hi2c1,buffer,20,10000);
/* USER CODE END I2C1_EV_IRQn 0 */
HAL_I2C_EV_IRQHandler(&hi2c1);
/* USER CODE BEGIN I2C1_EV_IRQn 1 */
/* USER CODE END I2C1_EV_IRQn 1 */
}
on my code I2C1_EV_IRQHandler call success but data doesn't receive anything.
Solved! Go to Solution.
2020-12-05 06:25 AM
There are several examples in the CubeMX repository. Here is one of them:
2020-12-05 06:25 AM
There are several examples in the CubeMX repository. Here is one of them: