接前一篇文章:ICM-20948芯片详解(7)
ICM-20948共有user bank 0~3共4组寄存器。
USER BANK 0所包含的寄存器如下图所示:
USER BANK 1所包含的寄存器如下图所示:
USER BANK 2所包含的寄存器如下图所示:
USER BANK 3所包含的寄存器如下图所示:
(1)WHO_AM_I
此寄存器向用户指示正在访问哪个设备。
ICM-20948的值为0xEA。
参考代码(节选自https://github.com/listout/icm20948_driver,下同):
- #define ICM20948_WHO_AM_I 0x00
-
- esp_err_t
- icm20948_get_deviceid(icm20948_handle_t sensor, uint8_t *const deviceid)
- {
- return icm20948_read(sensor, ICM20948_WHO_AM_I, deviceid, 1);
- }
- static esp_err_t
- icm20948_configure(icm20948_acce_fs_t acce_fs, icm20948_gyro_fs_t gyro_fs)
- {
- esp_err_t ret;
-
- ……
- uint8_t device_id;
- ret = icm20948_get_deviceid(icm20948, &device_id);
- if (ret != ESP_OK)
- return ret;
- ESP_LOGI(TAG, "0x%02X", device_id);
- if (device_id != ICM20948_WHO_AM_I_VAL)
- return ESP_FAIL;
- ……
-
- return ret;
- }
(2)USER_CTRL
参考代码:
无。
(3)LP_CONFIG
参考代码:
无。
(4)PWR_MGMT_1
参考代码:
- #define ICM20948_PWR_MGMT_1 0x06
-
- esp_err_t
- icm20948_wake_up(icm20948_handle_t sensor)
- {
- esp_err_t ret;
- uint8_t tmp;
- ret = icm20948_read(sensor, ICM20948_PWR_MGMT_1, &tmp, 1);
- if (ESP_OK != ret) {
- return ret;
- }
- tmp &= (~BIT6);
- ret = icm20948_write(sensor, ICM20948_PWR_MGMT_1, &tmp, 1);
- return ret;
- }
-
- esp_err_t
- icm20948_sleep(icm20948_handle_t sensor)
- {
- esp_err_t ret;
- uint8_t tmp;
- ret = icm20948_read(sensor, ICM20948_PWR_MGMT_1, &tmp, 1);
- if (ESP_OK != ret) {
- return ret;
- }
- tmp |= BIT6;
- ret = icm20948_write(sensor, ICM20948_PWR_MGMT_1, &tmp, 1);
- return ret;
- }
-
- esp_err_t
- icm20948_reset(icm20948_handle_t sensor)
- {
- esp_err_t ret;
- uint8_t tmp;
-
- ret = icm20948_read(sensor, ICM20948_PWR_MGMT_1, &tmp, 1);
- if (ret != ESP_OK)
- return ret;
- tmp |= 0x80;
- ret = icm20948_write(sensor, ICM20948_PWR_MGMT_1, &tmp, 1);
- if (ret != ESP_OK)
- return ret;
-
- return ret;
- }
-
(5)PWR_MGMT_2
参考代码:
无。
USER BANK 0更多寄存器内容请看下回。