sign extension is a pain
Some checks failed
Some checks failed
This commit is contained in:
@ -126,9 +126,9 @@ static int bmx055_sample_fetch(const struct device *dev,
|
||||
LOG_ERR("Failed to read acceleration registers!");
|
||||
return ret;
|
||||
}
|
||||
data->accel_x = sys_get_be16(&accel[0]) >> 4;
|
||||
data->accel_y = sys_get_be16(&accel[2]) >> 4;
|
||||
data->accel_z = sys_get_be16(&accel[4]) >> 4;
|
||||
data->accel_x = ((int16_t)sys_get_le16(&accel[0])) >> 4;
|
||||
data->accel_y = ((int16_t)sys_get_le16(&accel[2])) >> 4;
|
||||
data->accel_z = ((int16_t)sys_get_le16(&accel[4])) >> 4;
|
||||
|
||||
ret = i2c_burst_read_dt(&config->bus, REG_ACCD_TEMP, &data->temperature, sizeof(data->temperature));
|
||||
if (ret < 0)
|
||||
@ -211,11 +211,20 @@ static int bmx055_init(const struct device *dev)
|
||||
LOG_ERR("Chip ID read from %s incorrect. Read 0x%02X, expected 0x%02X", dev->name, chip_id, CHIP_ID);
|
||||
}
|
||||
|
||||
// Reset the sensor
|
||||
uint8_t reset_val = BGW_SOFTRESET;
|
||||
i2c_burst_write_dt(&config->bus, REG_BGW_SOFTRESET, &reset_val, sizeof(reset_val));
|
||||
// // Reset the sensor
|
||||
// uint8_t reset_val = BGW_SOFTRESET;
|
||||
// i2c_burst_write_dt(&config->bus, REG_BGW_SOFTRESET, &reset_val, sizeof(reset_val));
|
||||
|
||||
// Wait for device to reset
|
||||
// // Wait for device to reset
|
||||
|
||||
uint8_t lpw;
|
||||
ret = i2c_burst_read_dt(&config->bus, REG_PMU_LPW, &lpw, sizeof(lpw));
|
||||
if (ret < 0)
|
||||
{
|
||||
LOG_ERR("Failed to read LPW register!");
|
||||
return ret;
|
||||
}
|
||||
LOG_INF("LPW register: 0x%02X", lpw);
|
||||
|
||||
// Write configuration
|
||||
uint8_t accel_range = PMU_RANGE_2G;
|
||||
@ -224,6 +233,9 @@ static int bmx055_init(const struct device *dev)
|
||||
uint8_t accel_bw = PMU_BW_8HZ;
|
||||
i2c_burst_write_dt(&config->bus, REG_PMU_BW, &accel_bw, sizeof(accel_bw));
|
||||
|
||||
uint8_t hbw = (1 << 7); // data_high_bw (read filtered data) and enable lsb/msb shadowing
|
||||
i2c_burst_write_dt(&config->bus, REG_ACCD_HBW, &hbw, sizeof(hbw));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user