This is also a question of mine! did you got your answer? My code returns strange values of Temp/Press/Hum for example 0.5 deg or 130 deg temp!! I think this is for I2C read/Write function Can you please share your experience /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ int8_t user_i2c_read (uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len) { if (HAL_I2C_Master_Transmit(&hi2c4, (dev_id << 1), reg_addr, 1, 10) != HAL_OK) return -1; if (HAL_I2C_Master_Receive (& hi2c4, (dev_id << 1), reg_data, len, 10) != HAL_OK) return -1; return 0; } //int8_t user_i2c_read (uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len) { // if (HAL_I2C_Mem_Read(& hi2c4, dev_id<<1, reg_addr,1, reg_data, len, 5000) == HAL_OK) // return 0; // else // return 1;} void user_delay_ms (uint32_t period) { HAL_Delay (period); } int8_t user_i2c_write (uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len) { int8_t * buf; buf = malloc (len + 1); buf [0] = reg_addr; memcpy (buf + 1, reg_data, len); if (HAL_I2C_Master_Transmit (& hi2c4, (dev_id << 1), (uint8_t *) buf, len + 1, HAL_MAX_DELAY)!= HAL_OK) return -1; free(buf); return 0; }
... View more