You need to check for the HAL status for what the possible error could be.
If it returns HAL_ERROR, you'll need to debug and find out which of the 3 functions within HAL_I2C_Master_Transmit that can return an error.
- I2C_WaitOnFlagUntilTimeout
- I2C_WaitOnTXISFlagUntilTimeout
- I2C_WaitOnSTOPFlagUntilTimeout
HAL_StatusTypeDef hal_status;
while(icdata_flg==0){
HAL_GPIO_WritePin(GPIOA, ANNTENA_SW_Pin,GPIO_PIN_SET);
HAL_Delay(10);
tdata[0]=0x01;//Read
hal_status = HAL_I2C_Master_Transmit(&hi2c1,0xaa,tdata,1,100);
if(hal_status != HAL_OK)
{
if(hal_status == HAL_BUSY)
{
printf("I2C HAL BUSY");
}
else if(hal_status == HAL_ERROR)
{
printf("I2C HAL ERROR");
}
break;
}
hal_status = HAL_I2C_Master_Receive(&hi2c1,0xab,rdata,8,100);
if(hal_status != HAL_OK)
{
if(hal_status == HAL_BUSY)
{
printf("I2C HAL BUSY");
}
else if(hal_status == HAL_ERROR)
{
printf("I2C HAL ERROR");
}
break;;
}
HAL_GPIO_WritePin(GPIOA, ANNTENA_SW_Pin,GPIO_PIN_RESET);
}
If it's just one master and slave, then it's unlikely it'll return HAL_BUSY. But if it does, then you may need to check if the SDA line is held down by the slave.
HAL_I2C_Master_Receive has 3 possible return errors as well.
- I2C_WaitOnFlagUntilTimeout
- I2C_WaitOnRXNEFlagUntilTimeout
- I2C_WaitOnSTOPFlagUntilTimeout
Having the correct pull-ups resistors on the I2C bus is also crucial. Hopefully you are not using the internal pull-ups as that won't work reliably.
You should provide diagram of how you've connected the NT3H2211W0FT1 to the STM32 including the pull-up resistors and values.
As @TDK mentions, use an logic analyzer or oscilloscope to see what is happening on the I2C bus.
Either of those tools are your best friend.
If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source