2019-09-10 12:07 AM
Hello
I am using NUCLEO-G431KB to talk to a sensor using i2c.
Its working nicely using the 'HAL_I2C_Master_Transmit' HAL function.
I would like the system to generate an error if an ack is not received from the sensor.
This is the working code:
HAL_I2C_Master_Transmit(&hi2c1, 0xC8, data, 1, 100);
HAL_I2C_Master_Receive(&hi2c1, 0xC8, aRxBuffer, 2, 100);
st example code shows checking hal_ok, but i cant find any info on what hal_ok means.
Also when running this code it seems to endlessly transmit in the while loop. which I dont want.
I would really appreciate any help :)
while (HAL_I2C_Master_Transmit(&hi2c1, (uint16_t)I2C_ADDRESS, (uint8_t *)aTxBuffer, TXBUFFERSIZE, 10000) != HAL_OK)
{
/* Error_Handler() function is called when Timeout error occurs.
When Acknowledge failure occurs (Slave don't acknowledge its address)
Master restarts communication */
if (HAL_I2C_GetError(&hi2c1) != HAL_I2C_ERROR_AF)
{
Error_Handler();
}
}
2019-09-10 07:26 PM
Luckily, all source code is available, so you easily check the implementation of HAL_I2C_Master_Transmit()