STM32L031 I2C (SHT40) driver help
Hello. I have STM32L031 nucleo board: https://www.st.com/resource/en/user_manual/um1956-stm32-nucleo32-boards-mb1180-stmicroelectronics.pdf
And I am trying to write SHT40 driver for it. I have Adafruit SHT40 I2C temperature/humidity sensor:
https://www.adafruit.com/product/4885
I follow simple steps to setup my STM32 board for I2C:
- Enable I2C peripheral on STM32CubeMX:

- Connect the Adafruit board to the STM32L031 Nucleo board:

- Write function to read temperature/humidity data from the SHT40 sensor:
static void SHT40_measure(){
HAL_StatusTypeDef ret;
uint8_t data_tx[1] = {0xFD};
uint8_t data_rx[6];
ret = HAL_I2C_Master_Transmit(&hi2c1, 0x44, data_tx, 1, 1000);
if ( ret != HAL_OK ) {
printf("Error Tx\r\n");
}
else{
//read bytes
HAL_Delay(10);
ret = HAL_I2C_Master_Receive(&hi2c1, 0x44, (uint8_t*)&data_rx, 6,1000);
if ( ret != HAL_OK ) {
printf("Error Rx\r\n");
}
else{
for(int i = 0; i < 6 ; i++){
printf("data_rx[%i] = %u \n",i,data_rx[i]);
}
float t_ticks = data_rx[0] * 256 + data_rx[1];
float rh_ticks = data_rx[3] * 256 + data_rx[4];
float t_degC = -45 + 175 * t_ticks/65535;
float rh_pRH = -6 + 125 * rh_ticks/65535;
printf("t_degC = %.2d \n",t_degC);
printf("rh_pRH = %.2d \n",rh_pRH);
}
}
}
The results are as following (Serial console):
Trying to read SHT40 sensor
Error Tx
And the logic analyzer shows the following:

I would appreciate any help. I have double checked everything and cannot spot a mistake.. What could be an issue with my I2C and why would it write such a garbage (when monitoring through logic analyzer?). It should write data 0xFD to the address 0x44
UPDATE
What I am confused about is why the I2C does not work as it supposed to. I have even disconnected SH40 sensor from my board and trying to send a dummy I2C command such as:
uint8_t test_data = 0x88;
HAL_I2C_Master_Transmit(&hi2c1, 0xf0, &test_data, 1, 0xff);
And from what I understand, it should send 2 bytes of data via I2C bus. First byte contains the device address, in this case (0xF0) and then 2nd byte the actual data, in this case (0x88).
Monitoring through logic analyzer:

This looks like a total garbage. The I2C line does not even have 16 clock cycles. What could cause this? It feels like I2C clock is cutting off early and not able to send all the required data.
