2025-04-25 12:31 AM - last edited on 2025-04-25 12:32 AM by Andrew Neil
HAL_I2C_Slave_Seq_Transmit_* and HAL_I2C_Slave_Seq_Receive_* functions
I have to program an I2C slave which during communication the transfer direction switch. The HAL driver manual does not go into too much details. Are there example code anywhere?
Thank in advance.
2025-04-29 2:03 AM
Hello @HoangHung ,
We recommend checking out the examples provided in the STM32CubeF1 package, specifically for the STM32F103RB-Nucleo board. There are examples demonstrating how to handle I2C data buffer transmission and reception between two boards in different modes, such as polling, DMA, and interrupt.
You can find these examples in the STM32CubeF1 in GitHub . Exploring these examples should give you a clearer understanding and help resolve your issue.
Br
2025-05-05 6:24 AM
Hello @HoangHung
It is possible to check the transfer direction on the HAL_I2C_AddrCallback() function.
HAL_I2C_EnableListen_IT(&hi2cx);
void HAL_I2C_AddrCallback(I2C_HandleTypeDef *hi2c, uint8_t TransferDirection, uint16_t AddrMatchCode)
{
if (TransferDirection == Tx)
{
HAL_I2C_Slave_Seq_Transmit_*();
}
else
{
HAL_I2C_Slave_Seq_Receive_*();
}
}