cancel
Showing results for 
Search instead for 
Did you mean: 

HAL I2C timeout flag

Filipx.87
Associate II

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;
}

1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III
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?

View solution in original post

2 REPLIES 2
Pavel A.
Evangelist III
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?

Piranha
Chief II
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...