Last active
August 21, 2020 13:55
-
-
Save goddade/99a85048b5bfd50567fff834195f17e4 to your computer and use it in GitHub Desktop.
P8b ATCwatch SC7A20 , no interrupt, no pedometer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define ACCL_ADDR (0x18) | |
| #define ACCL_REG_WHOAMI (0x0F) | |
| #define ACCL_REG_CTRL1 (0x20) | |
| #define ACCL_REG_CTRL3 (0x22) | |
| #define ACCL_REG_CTRL4 (0x23) | |
| #define ACCL_REG_CTRL5 (0x24) | |
| #define ACCL_REG_STATUS (0x27) | |
| #define ACCL_OUT_X_L (0x28) | |
| #define ACCL_OUT_X_H (0x29) | |
| #define ACCL_OUT_Y_L (0x2A) | |
| #define ACCL_OUT_Y_H (0x2B) | |
| #define ACCL_OUT_Z_L (0x2C) | |
| #define ACCL_OUT_Z_H (0x2D) | |
| #define ACCL_REG_INT1SRC (0x31) | |
| #define ACCL_REG_TEMPCFG (0x1F) | |
| #define ACCL_OUT_TEMP_L (0x0C) | |
| #define ACCL_OUT_TEMP_H (0x0D) | |
| #define ACCL_MAX_G (980) | |
| void init_accl() { | |
| pinMode(BMA421_INT, INPUT); | |
| // // Check device ID. | |
| // if (accl_read_reg(ACCL_REG_WHOAMI) == 0x11) { | |
| // } | |
| //Enable all axes, normal mode, 50Hz. | |
| accl_write_reg(ACCL_REG_CTRL1, 0x47); | |
| //BDU & BLE enabled. | |
| accl_write_reg(ACCL_REG_CTRL4, 0x80); | |
| //Enable temperature sensor. | |
| // accl_write_reg(ACCL_REG_TEMPCFG, 0x40); | |
| //Latch interrupt for INT1 | |
| // accl_write_reg(ACCL_REG_CTRL5, 0x08); | |
| } | |
| uint32_t get_accl_temperature() { | |
| uint32_t temp = 0; | |
| uint8_t dl = accl_read_reg(ACCL_OUT_TEMP_L); | |
| temp = (uint32_t)((accl_read_reg(ACCL_OUT_TEMP_H) << 8) | dl); | |
| //TODO: scale | |
| return temp; | |
| } | |
| void update_accl_data() { | |
| uint8_t dl; | |
| // check ACCL_REG_STATUS | |
| if (accl_read_reg(ACCL_REG_STATUS) & 0x0F == 0x0F) { | |
| dl = accl_read_reg(ACCL_OUT_X_L); | |
| accl_data.x = (int16_t)((accl_read_reg(ACCL_OUT_X_H) << 8) | dl); | |
| dl = accl_read_reg(ACCL_OUT_Y_L); | |
| accl_data.y = (int16_t)((accl_read_reg(ACCL_OUT_Y_H) << 8) | dl); | |
| dl = accl_read_reg(ACCL_OUT_Z_L); | |
| accl_data.z = (int16_t)((accl_read_reg(ACCL_OUT_Z_H) << 8) | dl); | |
| accl_data.x = accl_data.x >> 4; | |
| accl_data.y = accl_data.y >> 4; | |
| accl_data.z = accl_data.z >> 4; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment