2023-03-24 02:18 PM
I have a simple function that reads one byte from I2C and I need the RxdFlag variable to be cleared in case of unsuccessful transfer (timeout) and I don't know how to get it from the HAL_StatusTypeDef structure. Thanx for your help.
uint8_t GetSlaveInfo (uint8_t *value)
{
uint8_t RxdFlag = 1;
HAL_I2C_Master_Receive(&hi2c1, EE_I2C_ADDR << 1, value, 1, 50);
return RxdFlag;
}
Solved! Go to Solution.
2023-03-24 10:49 PM
uint8_t GetSlaveInfo (uint8_t *value)
{
uint8_t RxdFlag = 0;
HAL_StatusTypeDef st =
HAL_I2C_Master_Receive(&hi2c1, EE_I2C_ADDR << 1, value, 1, 50);
if (st == HAL_OK)
RxdFlag = 1;
return RxdFlag;
}
What should your function return in case of other errors besides of timeout?
2023-03-24 10:49 PM
uint8_t GetSlaveInfo (uint8_t *value)
{
uint8_t RxdFlag = 0;
HAL_StatusTypeDef st =
HAL_I2C_Master_Receive(&hi2c1, EE_I2C_ADDR << 1, value, 1, 50);
if (st == HAL_OK)
RxdFlag = 1;
return RxdFlag;
}
What should your function return in case of other errors besides of timeout?
2023-03-25 10:18 AM
uint8_t GetSlaveInfo(uint8_t *value)
{
HAL_StatusTypeDef st = HAL_I2C_Master_Receive(&hi2c1, EE_I2C_ADDR << 1, value, 1, 50);
return (st == HAL_OK);
}
uint8_t GetSlaveInfo(uint8_t *value)
{
return (HAL_I2C_Master_Receive(&hi2c1, EE_I2C_ADDR << 1, value, 1, 50) == HAL_OK);
}
Often I don't understand why people write so much useless code...