I am attempting to see the step counter output or if the interrupt triggers but it seems it doesn't as when reading either register they are always 0.
I would love to hear any ideas of how to modify my code or even if you think perhaps the Grove step counter may be to blame. Thank you for any help.
/**\
* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
**/
#include <stdio.h>
#include "bma456h.h"
#include "common.h"
#include <zephyr/drivers/uart.h>
/******************************************************************************/
/*! Function */
/* This function starts the execution of program. */
int main(void)
{
/* Variable to store the status of API */
int8_t rslt;
int8_t enable_rslt;
/* Sensor initialization configuration */
struct bma4_dev bma = { 0 };
/* Variable to store step counter interrupt status */
uint16_t int_status = 0;
/* Variable to store step counter output */
uint32_t step_out = 0;
/* Variable to store activity status */
uint8_t activity_output = 0;
/* Interface reference is given as a parameter
* For I2C : BMA4_I2C_INTF
* For SPI : BMA4_SPI_INTF
* Variant information given as parameter - BMA45X_VARIANT
*/
printf("\nStart new step counter example\n");
rslt = bma4_interface_init(&bma, BMA4_I2C_INTF, BMA45X_VARIANT);
bma4_error_codes_print_result("bma4_interface_init", rslt);
printf("bma4_interface_init status %d\n", rslt);
/* Sensor initialization */
rslt = bma456h_init(&bma);
bma4_error_codes_print_result("bma456h_init status", rslt);
printf("bma456h_init status %d\n", rslt);
/* Upload the configuration file to enable the features of the sensor. */
rslt = bma456h_write_config_file(&bma);
bma4_error_codes_print_result("bma456h_write_config status", rslt);
printf("bma456h_write_config status %d\n", rslt);
/* Enable the accelerometer */
rslt = bma4_set_accel_enable(BMA4_ENABLE, &bma);
bma4_error_codes_print_result("bma4_set_accel_enable status", rslt);
printf("bma4_set_accel_enable status %d\n", rslt);
// rslt = bma4_get_accel_enable(&enable_rslt, &bma);
// bma4_error_codes_print_result("bma4_get_accel_enable status", rslt);
// printf("bma4_get_accel_enable status %d\n", enable_rslt);
// rslt = bma456h_feature_enable(BMA456H_STEP_COUNTER_EN, BMA4_ENABLE, &bma);
// bma4_error_codes_print_result("bma456h_feature_enable status: step counter enabled", rslt);
// printf("bma456h_feature_enable status: step counter enabled %d\n", rslt);
if (rslt == BMA4_OK)
{
/* Map the interrupt pin 1 for step counter */
rslt = bma456h_map_interrupt(BMA4_INTR1_MAP, BMA456H_ACTIVITY_INT, BMA4_ENABLE, &bma);
bma4_error_codes_print_result("bma456h_map_interrupt status", rslt);
printf("bma456h_map_interrupt status %d\n", rslt);
rslt = bma456h_map_interrupt(BMA4_INTR2_MAP, BMA456H_STEP_CNTR_INT, BMA4_ENABLE, &bma);
bma4_error_codes_print_result("bma456h_map_interrupt status", rslt);
printf("bma456h_map_interrupt status %d\n", rslt);
rslt = bma456h_map_interrupt(BMA4_INTR1_MAP, BMA456H_STEP_CNTR_INT, BMA4_ENABLE, &bma);
bma4_error_codes_print_result("bma456h_map_interrupt status", rslt);
printf("bma456h_map_interrupt status %d\n", rslt);
if (rslt == BMA4_OK)
{
/* By setting watermark level 1, the output step resolution is 20 steps.
* By setting watermark level 0, it provides output for each step for step detection.
*/
rslt = bma456h_step_counter_set_watermark(1, &bma);
bma4_error_codes_print_result("bma456h_step_counter_set_watermark status", rslt);
printf("set watermark status %d\n", rslt);
if (rslt == BMA4_OK)
{
/* Enabling step counter feature */
rslt = bma456h_feature_enable(BMA456H_STEP_COUNTER_EN, BMA4_ENABLE, &bma);
bma4_error_codes_print_result("bma456h_feature_enable status: step counter enabled", rslt);
printf("bma456h_feature_enable status: step counter enabled %d\n", rslt);
// rslt = bma456h_feature_enable(BMA456H_STEP_DETECTOR_EN, BMA4_ENABLE, &bma);
// bma4_error_codes_print_result("bma456h_feature_enable status: step detector enabled", rslt);
// printf("bma456h_feature_enable status: step detector enabled %d\n", rslt);
// rslt = bma456h_feature_enable(BMA456H_STEP_ACTIVITY_EN, BMA4_ENABLE, &bma);
// bma4_error_codes_print_result("bma456h_feature_enable status: step activity enabled", rslt);
// printf("bma456h_feature_enable status: step activity enabled %d\n", rslt);
}
}
if (rslt == BMA4_OK)
{
printf("Step counter feature is enabled\n");
printf("Step counter watermark level is 1 (Output resolution is 20 steps)\n");
printf("Move the board in steps to perform step counter\n");
for (;;)
{
/* Read the interrupt status (After 20 steps, generates interrupt) */
rslt = bma456h_read_int_status(&int_status, &bma);
bma4_error_codes_print_result("bma456h_read_int_status", rslt);
if (int_status != 0){
printf("bma456h_read_int_status status %d\n", int_status);
}
/* Enters only if the obtained interrupt is step counter */
if ((rslt == BMA4_OK) && (int_status & BMA456H_STEP_CNTR_INT))
{
//printf("Step counter interrupt received when watermark level is reached (20 steps)\n");
rslt = bma456h_step_counter_output(&step_out, &bma);
bma4_error_codes_print_result("bma456_step_counter_output status", rslt);
if (step_out != 0){
printf("The step counter output is %lu\n", (long unsigned int)step_out);
}
}
int_status = 0;
}
}
}
return rslt;
}