避坑之BMA425 |
您所在的位置:网站首页 › bmc056 › 避坑之BMA425 |
避坑之BMA425
最近有项目需要用到运动计步,因此选用了博士BMA425,按照官方的文档编写好程序后遇到了一个大坑。 配置完这个芯片后,发现计算出的步数一直没有更新,开启计步中断后,发现也无法进入到中断。 上面的配置流程基本就是 先去读芯片ID 看是否型号为对应的IC。然后写入对应的配置参数。 我的代码流程也是按照官方的来的,为什么一直就没有步数更新呢。 后来发现这个芯片上电是需要软复位的。这个坑踩的真头大。折腾了好久。 直接上代码 uint8_t Configure_Bma423_pro(void) { uint16_t rslt=0x00; /* Assign device I2C address based on the status of SDO pin (GND for PRIMARY(0x18) & VDD for SECONDARY(0x19)) */ bma.dev_addr = BMA4_I2C_ADDR_PRIMARY; bma.interface = BMA4_I2C_INTERFACE; bma.bus_read = i2c_reg_read; bma.bus_write = i2c_reg_write; bma.delay = delay_ms; /* To enable SPI interface: comment the above 4 lines and uncomment the below 4 lines */ /* * bma.dev_addr = 0; * bma.bus_read = spi_reg_read; * bma.bus_write = spi_reg_write; * bma.interface = BMA4_SPI_INTERFACE; */ /* Configure max read/write length (in bytes) ( Supported length depends on target machine) */ bma.read_write_len = 8; bma.resolution = 12; bma.feature_len = BMA425_FEATURE_SIZE;//下面这里的软复位是我添加上去的,不执行则无法计步 /* Soft-reset / rslt = bma4_set_command_register(0xB6, &bma); print_rslt(“bma423_reset”, rslt); bma.delay(10); printf("\n\n***************bma423_reset ok 0**************\n");** /* Sensor initialization */ rslt= bma425_init(&bma); print_rslt("bma423_init", rslt); printf("\n\n****************configure ok 1**************\n"); if (rslt != BMA4_OK) return rslt; Delay_Ms(20); /* Upload the configuration file to enable the features of the sensor. */ rslt= bma425_write_config_file(&bma); print_rslt("bma423_write_config", rslt); printf("\n\n****************configure ok 2**************\n"); if (rslt != BMA4_OK) return rslt; /* Enable the accelerometer */ rslt = bma4_set_accel_enable(1, &bma); print_rslt("bma4_set_accel_enable status", rslt); printf("\n\n****************configure ok 3**************\n"); if (rslt != BMA4_OK) return rslt;坑之二,如果要实现走一步就进一次中断则需要加上 bma425_step_detector_enable(BMA4_ENABLE, &bma); 如果要实现走20步再进一次中断则按如下配置,当然就不需要加上detector enable了 rslt = bma425_map_interrupt(BMA4_INTR1_MAP, BMA425_STEP_CNTR_INT, 1, &bma); print_rslt("bma423_map_interrupt status", rslt); printf("\n\n****************configure ok 6**************\n"); /* Set water-mark level 1 to get interrupt after 20 steps. * Range of step counter interrupt is 0 to 20460(resolution of 20 steps). */ rslt = bma425_step_counter_set_watermark(1, &bma); print_rslt("bma423_step_counter status", rslt); printf("Move/perform the walk/step action with the sensor\n"); printf("\n\n****************configure ok 7**************\n");需要配置详细代码可以从这里下载 我的配置代码 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |