I2C sending wrong and incomplete data
Hello,
I have a STM32F301K6 based board and it seems that the I2C HAL driver is not working properly. I have a little test software running which should receive one byte (0x00) and send back 5 bytes (0x01 to 0x05) periodically.
Receive works fine but transmit sends wrong data on the first transmit and only 4 bytes on the second transmit.
Here some captures from the oscilloscope:
Both rx/tx cycles. Clock line is kept low after 2nd tx because of the missing last byte I guess.
Data of first rx/tx. Notice the incorrect two bytes.
Data of second rx/tx.
My Code is quite simple:
#define I2C_RX_SIZE 1
#define I2C_TX_SIZE 5
uint8_t i2c_rx_buf[I2C_RX_SIZE] = {0};
uint8_t i2c_tx_buf[I2C_TX_SIZE] = {1,2,3,4,5};
//...
void main() {
//...
while(1) {
HAL_I2C_Slave_Receive(&hi2c1, i2c_rx_buf, I2C_RX_SIZE, 200);
HAL_I2C_Slave_Transmit(&hi2c1, i2c_tx_buf, I2C_TX_SIZE, 200);
}
//...
}Hardware configuration:

