2020-08-07 12:33 AM
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:
2020-08-07 07:03 AM
That plot doesn't look right. You have a low level, a high level, and a mid level. Almost like two things are trying to drive the bus at the same time. Maybe something is configured in push-pull instead of open-drain. What else is connected to SDA/SCL?
2020-08-10 12:49 AM
@TDK Only the master, which is a STM32H743 based board. I probably should mention that on the F301-Slave-Board there is a ISO1540 to isolate the bus. But this design has work in previous projects.
However, I have not changed my code to wait for ready state before sending and receiving.
while(HAL_I2C_Slave_Receive(&hi2c1, i2c_rx_buf, I2C_RX_SIZE, 200) != HAL_OK);
while(HAL_I2C_Slave_Transmit(&hi2c1, i2c_tx_buf, I2C_TX_SIZE, 200) != HAL_OK);
Now is sometimes works for some seconds before hanging with the same problem (clock line on mid/low level).
2020-08-10 01:07 AM
The problem seems to be with the F301-Slave-Board. As soon as I press the reset button the clock line goes high again and the master starts trying to write.