Hi Thanks for you explanation! I already fill the functions user_i2c_read() and user_i2c_write() but something isn't right. My code doesn't advance from function bme680_init() (return always NULL) and I think that those functions are reason that didn´t work. This is the code that I used: int8_t user_i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len) {
int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
HAL_StatusTypeDef status = HAL_OK;
uint8_t array[I2C_RX_SIZE_BUFF] = { 0 };
uint8_t stringpos = 0;
array[0] = reg_addr;
while (HAL_I2C_IsDeviceReady(&hi2c1, (uint8_t) (dev_id << 1), 3, 100)
!= HAL_OK) {
}
status = HAL_I2C_Mem_Read(&hi2c1, // i2c handle
(uint8_t) (dev_id << 1), // i2c address, left aligned
(uint8_t) reg_addr, // register address
I2C_MEMADD_SIZE_8BIT, // bme280 uses 8bit register addresses
(uint8_t*) (&array), // write returned data to this variable
len, // how many bytes to expect returned
100); // timeout
if (status != HAL_OK) {
rslt = (-1);
}
for (stringpos = 0; stringpos < len; stringpos++) {
*(reg_data + stringpos) = array[stringpos];
}
return rslt;
} int8_t user_i2c_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len) {
int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
HAL_StatusTypeDef status = HAL_OK;
while (HAL_I2C_IsDeviceReady(&hi2c1, (uint8_t) (dev_id << 1), 3, 100)
!= HAL_OK) {
}
status = HAL_I2C_Mem_Write(&hi2c1, // i2c handle
(uint8_t) (dev_id << 1), // i2c address, left aligned
(uint8_t) reg_addr, // register address
I2C_MEMADD_SIZE_8BIT, // bme280 uses 8bit register addresses
(uint8_t*) (®_data), // write returned data to reg_data
len, // write how many bytes
100); // timeout
if (status != HAL_OK) {
rslt = (-1);
}
return rslt;
} best regards!
... View more