I'm trying to setup a mini OLED display I2C (SSD1306) with the STM32F411 (black pill). Sometimes it works, randomly. But always, after power off/on everything, it stops working and doesn't recover. If I reset or remove the power of only the display, it doesn't help.
Now I have just the board and and the display, and I have reduced the code to just sending 3 bytes, and checked with the logic analyzer.
...
MX_I2C1_Init();
HAL_Delay(100);
HAL_StatusTypeDef ret;
static const uint8_t TMP102_ADDR = 0x3C << 1;
uint8_t data = 0x69;
ret = HAL_I2C_Master_Transmit( &hi2c1, TMP102_ADDR, data, 1, HAL_MAX_DELAY);
ret = HAL_I2C_Master_Transmit( &hi2c1, TMP102_ADDR, data, 1, HAL_MAX_DELAY);
ret = HAL_I2C_Master_Transmit( &hi2c1, TMP102_ADDR, data, 1, HAL_MAX_DELAY);
The first byte is lost, I suppose that because the bus was in a wrong state. And then I get always NACK. With the SSD1306 driver code it's the same behavior.
I have also tried to send many clock pulses before, but it doesn't work most of the times. I have been reading that this could be a problem of the slave stuck in some conditions. Actually in the image right after restart, both SCL and SCK are low.
The address is correct, because when the display works I can check it with the analyzer. Then it works all the time until I remove the power or recompile. I'm not sure what's going on. I don't know what could I try to find the reason or some work around. Thanks!
Edit: I add more details. This is the SCL signal in the oscilloscope:
I also tried with 2 pullup resistor of 1KΩ, from the SCL and SDA to VCC, and it looks the same.
And this the simple setup that I have now:
There is additionally the ST-Link debugger and the board is powered by the usb connector. I tried also to power the display with the bench power supply, just in case, but it's the same.
The error that I get debugging the HAL functions is HAL_I2C_ERROR_AF, so ACK Failure.

