08-18-2024 01:30 AM
I’m working with the BMA530 interfaced with I2C on the STM32 and trying to configure any-motion detection on one axis (X-axis specifically). I’ve been following the process from the datasheet, but I’m encountering some issues:
2. Interrupt Issue: The interrupt is constantly triggering, even though the motion detection parameters should be set to reasonable values, and the chip is stationary. This might have something to do with problem #1.
Below is the main part of the initialization code, BMA530_Init(), that is called from my main function. The printRegisterValues() function is used to check if the configuration was successful.
void BMA530_ConfigureGenericInt1(void)
{
uint8_t buf[3];
uint8_t regValues[2];
/// Configure GENERIC_INTERRUPT1_1 (0x04): axis selection, comb_sel, slope_thres
buf[0] = BMA530_REG_GENERIC_INT1_1;
uint16_t register_value = (BMA530_GENERIC_INT1_AXIS_SEL_X | BMA530_GENERIC_INT1_COMB_SEL_OR | BMA530_GENERIC_INT1_SLOPE_THRES(3500));
buf[1] = (register_value >> 😎 & 0xFF;
buf[2] = register_value & 0xFF;
HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 3, HAL_MAX_DELAY);
// Configure GENERIC_INTERRUPT1_2 (0x05): acc_ref_up, criterion_sel, hysteresis
buf[0] = BMA530_REG_GENERIC_INT1_2;
register_value = BMA530_GENERIC_INT1_ACC_REF_UP | BMA530_GENERIC_INT1_CRITERION_SEL | BMA530_GENERIC_INT1_HYSTERESIS(50);
buf[1] = (register_value >> 😎 & 0xFF;
buf[2] = register_value & 0xFF;
HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 3, HAL_MAX_DELAY);
// Configure GENERIC_INTERRUPT1_3 (0x06): duration and wait time
buf[0] = BMA530_REG_GENERIC_INT1_3;
uint16_t duration_value = DURATION_500MS;
uint16_t wait_time_value = WAIT_TIME_200MS;
uint16_t combined_value = (wait_time_value << 13) | duration_value;
buf[1] = (combined_value >> 😎 & 0xFF;
buf[2] = combined_value & 0xFF;
HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 3, HAL_MAX_DELAY);
// Configure GENERIC_INTERRUPT1_4 (0x07): minimal quiet time
buf[0] = BMA530_REG_GENERIC_INT1_4;
uint16_t quiet_time_value = QUIET_TIME_MIN;
buf[1] = (quiet_time_value >> 😎 & 0x1F; // Only 5 bits used (upper 3 bits are reserved)
buf[2] = quiet_time_value & 0xFF;
HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 3, HAL_MAX_DELAY);
}
void BMA530_Init(void)
{
uint8_t buf[2];
uint8_t reg_value;
HAL_StatusTypeDef ret;
// Step 1: Disable the accelerometer before performing the soft reset
buf[0] = BMA530_REG_ACC_CONF0;
buf[1] = 0x00; // Disable the accelerometer
ret = HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 2, HAL_MAX_DELAY);
HAL_Delay(10);
// Step 2: Perform Soft Reset (0x7E)
buf[0] = 0x7E; // Soft-reset register
buf[1] = 0xB6; // Soft-reset command
ret = HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 2, HAL_MAX_DELAY);
HAL_Delay(100); // Wait after reset
// Step 3: Configure ACC_CONF0 (0x30) - Enable the accelerometer
buf[0] = BMA530_REG_ACC_CONF0;
buf[1] = 0x0F; // Enable the accelerometer with default settings
ret = HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 2, HAL_MAX_DELAY);
HAL_Delay(10);
// Step 4: Configure ACC_CONF1 (0x31) - Set high performance, 200Hz ODR
buf[0] = BMA530_REG_ACC_CONF1;
buf[1] = HIGH_PERFORMANCE | AVG_2_SAMPLES | ODR_200HZ; // Set performance mode and ODR
ret = HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 2, HAL_MAX_DELAY);
HAL_Delay(10);
// Step 5: Configure ACC_CONF2 (0x32) - Noise mode, IIR rolloff, range
buf[0] = BMA530_REG_ACC_CONF2;
buf[1] = NOISE_MODE_LOWER | IIR_ROLLOFF_60DB | RANGE_2G;
ret = HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 2, HAL_MAX_DELAY);
HAL_Delay(10);
// Step 6: Configure INT1 (0x34): Edge-triggered, push-pull, active high
buf[0] = BMA530_REG_INT1_CONFIG;
buf[1] = 0x0B; // Edge-triggered, push-pull, active high
ret = HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 2, HAL_MAX_DELAY);
HAL_Delay(10);
// Step 7: Map Generic Interrupt 1 to INT1 (0x36)
buf[0] = BMA530_REG_INT_MAP_0;
buf[1] = 0x40; // Map Generic Interrupt 1 to INT1
ret = HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 2, HAL_MAX_DELAY);
HAL_Delay(10);
// Step 8: Enable Generic Interrupt 1 (0x55)
buf[0] = BMA530_REG_FEAT_ENG_GPR_0;
buf[1] = BMA530_ENABLE_GENERIC_INT1;
ret = HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 2, HAL_MAX_DELAY);
HAL_Delay(10);
// Step 9: Update Feature Engine (0x54)
buf[0] = BMA530_REG_FEAT_ENG_UPDATE;
buf[1] = 0x01; // Activate the feature engine
ret = HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 2, HAL_MAX_DELAY);
HAL_Delay(10);
// Step 10: Configure Generic Interrupt 1
BMA530_ConfigureGenericInt1();
snprintf(uart_buffer, sizeof(uart_buffer), "BMA530 Initialization Complete\r\n");
HAL_UART_Transmit(&huart2, (uint8_t*)uart_buffer, strlen(uart_buffer), HAL_MAX_DELAY);
printRegisterValues();
}
void printRegisterValues(void)
{
uint8_t regValues[2];
// Print ACC_CONF0 (0x30)
HAL_I2C_Mem_Read(&hi2c1, (BMA530_I2C_ADDR << 1), BMA530_REG_ACC_CONF0, I2C_MEMADD_SIZE_8BIT, regValues, 1, HAL_MAX_DELAY);
snprintf(uart_buffer, sizeof(uart_buffer), "ACC_CONF0 (0x30): 0x%02X\r\n", regValues[0]);
HAL_UART_Transmit(&huart2, (uint8_t*)uart_buffer, strlen(uart_buffer), HAL_MAX_DELAY);
// Print ACC_CONF1 (0x31)
HAL_I2C_Mem_Read(&hi2c1, (BMA530_I2C_ADDR << 1), BMA530_REG_ACC_CONF1, I2C_MEMADD_SIZE_8BIT, regValues, 1, HAL_MAX_DELAY);
snprintf(uart_buffer, sizeof(uart_buffer), "ACC_CONF1 (0x31): 0x%02X\r\n", regValues[0]);
HAL_UART_Transmit(&huart2, (uint8_t*)uart_buffer, strlen(uart_buffer), HAL_MAX_DELAY);
// Print ACC_CONF2 (0x32)
HAL_I2C_Mem_Read(&hi2c1, (BMA530_I2C_ADDR << 1), BMA530_REG_ACC_CONF2, I2C_MEMADD_SIZE_8BIT, regValues, 1, HAL_MAX_DELAY);
snprintf(uart_buffer, sizeof(uart_buffer), "ACC_CONF2 (0x32): 0x%02X\r\n", regValues[0]);
HAL_UART_Transmit(&huart2, (uint8_t*)uart_buffer, strlen(uart_buffer), HAL_MAX_DELAY);
// Print INT1_CONFIG (0x34)
HAL_I2C_Mem_Read(&hi2c1, (BMA530_I2C_ADDR << 1), BMA530_REG_INT1_CONFIG, I2C_MEMADD_SIZE_8BIT, regValues, 1, HAL_MAX_DELAY);
snprintf(uart_buffer, sizeof(uart_buffer), "INT1_CONFIG (0x34): 0x%02X\r\n", regValues[0]);
HAL_UART_Transmit(&huart2, (uint8_t*)uart_buffer, strlen(uart_buffer), HAL_MAX_DELAY);
// Print INT_MAP_0 (0x36)
HAL_I2C_Mem_Read(&hi2c1, (BMA530_I2C_ADDR << 1), BMA530_REG_INT_MAP_0, I2C_MEMADD_SIZE_8BIT, regValues, 1, HAL_MAX_DELAY);
snprintf(uart_buffer, sizeof(uart_buffer), "INT_MAP_0 (0x36): 0x%02X\r\n", regValues[0]);
HAL_UART_Transmit(&huart2, (uint8_t*)uart_buffer, strlen(uart_buffer), HAL_MAX_DELAY);
// Print FEAT_ENG_GPR_0 (0x55)
HAL_I2C_Mem_Read(&hi2c1, (BMA530_I2C_ADDR << 1), BMA530_REG_FEAT_ENG_GPR_0, I2C_MEMADD_SIZE_8BIT, regValues, 1, HAL_MAX_DELAY);
snprintf(uart_buffer, sizeof(uart_buffer), "FEAT_ENG_GPR_0 (0x55): 0x%02X\r\n", regValues[0]);
HAL_UART_Transmit(&huart2, (uint8_t*)uart_buffer, strlen(uart_buffer), HAL_MAX_DELAY);
// Print FEAT_ENG_UPDATE (0x54)
HAL_I2C_Mem_Read(&hi2c1, (BMA530_I2C_ADDR << 1), BMA530_REG_FEAT_ENG_UPDATE, I2C_MEMADD_SIZE_8BIT, regValues, 1, HAL_MAX_DELAY);
snprintf(uart_buffer, sizeof(uart_buffer), "FEAT_ENG_UPDATE (0x54): 0x%02X\r\n", regValues[0]);
HAL_UART_Transmit(&huart2, (uint8_t*)uart_buffer, strlen(uart_buffer), HAL_MAX_DELAY);
// Print GENERIC_INT1_1 (0x04)
HAL_I2C_Mem_Read(&hi2c1, (BMA530_I2C_ADDR << 1), BMA530_REG_GENERIC_INT1_1, I2C_MEMADD_SIZE_8BIT, regValues, 2, HAL_MAX_DELAY);
snprintf(uart_buffer, sizeof(uart_buffer), "GENERIC_INT1_1 (0x04): 0x%02X 0x%02X\r\n", regValues[0], regValues[1]);
HAL_UART_Transmit(&huart2, (uint8_t*)uart_buffer, strlen(uart_buffer), HAL_MAX_DELAY);
// Print GENERIC_INT1_2 (0x05)
HAL_I2C_Mem_Read(&hi2c1, (BMA530_I2C_ADDR << 1), BMA530_REG_GENERIC_INT1_2, I2C_MEMADD_SIZE_8BIT, regValues, 2, HAL_MAX_DELAY);
snprintf(uart_buffer, sizeof(uart_buffer), "GENERIC_INT1_2 (0x05): 0x%02X 0x%02X\r\n", regValues[0], regValues[1]);
HAL_UART_Transmit(&huart2, (uint8_t*)uart_buffer, strlen(uart_buffer), HAL_MAX_DELAY);
// Print GENERIC_INT1_3 (0x06)
HAL_I2C_Mem_Read(&hi2c1, (BMA530_I2C_ADDR << 1), BMA530_REG_GENERIC_INT1_3, I2C_MEMADD_SIZE_8BIT, regValues, 2, HAL_MAX_DELAY);
snprintf(uart_buffer, sizeof(uart_buffer), "GENERIC_INT1_3 (0x06): 0x%02X 0x%02X\r\n", regValues[0], regValues[1]);
HAL_UART_Transmit(&huart2, (uint8_t*)uart_buffer, strlen(uart_buffer), HAL_MAX_DELAY);
// Print GENERIC_INT1_4 (0x07)
HAL_I2C_Mem_Read(&hi2c1, (BMA530_I2C_ADDR << 1), BMA530_REG_GENERIC_INT1_4, I2C_MEMADD_SIZE_8BIT, regValues, 2, HAL_MAX_DELAY);
snprintf(uart_buffer, sizeof(uart_buffer), "GENERIC_INT1_4 (0x07): 0x%02X 0x%02X\r\n", regValues[0], regValues[1]);
HAL_UART_Transmit(&huart2, (uint8_t*)uart_buffer, strlen(uart_buffer), HAL_MAX_DELAY);
}
This is from my header file:
// Macros for register configuration
#define HIGH_PERFORMANCE (0x1 << 7)
#define AVG_4_SAMPLES (0x2 << 4)
#define AVG_2_SAMPLES (0x1 << 4)
#define NO_AVERAGING (0x0 << 4)
#define ODR_200HZ (0x7 << 0)
#define ODR_400HZ (0x8 << 0)
#define ODR_800HZ (0x9 << 0)
#define ODR_1600HZ (0xA << 0)
#define ODR_6400HZ (0xC << 0)
#define RANGE_2G (0x0 << 0)
#define IIR_ROLLOFF_MINUS_40DB (0x2 << 2)
#define LOWER_NOISE_MODE (0x0 << 4)
#define IIR_ROLLOFF_MINUS_60DB 0x03
#define NOISE_MODE_LOWER (0x01 << 4) // Lower noise level (default)
#define IIR_ROLLOFF_60DB (0x03 << 2) // IIR filter roll-off -60dB
// Register addresses
#define BMA530_REG_CHIP_ID 0x00 // Chip ID register
#define BMA530_REG_ACC_X_LSB 0x18 // LSB of X-axis acceleration data
#define BMA530_REG_ACC_X_MSB 0x19 // MSB of X-axis acceleration data
#define BMA530_REG_ACC_Y_LSB 0x1A // LSB of Y-axis acceleration data
#define BMA530_REG_ACC_Y_MSB 0x1B // MSB of Y-axis acceleration data
#define BMA530_REG_ACC_Z_LSB 0x1C // LSB of Z-axis acceleration data
#define BMA530_REG_ACC_Z_MSB 0x1D // MSB of Z-axis acceleration data
// Configuration registers
#define BMA530_REG_ACC_CONF0 0x30 // Accelerometer configuration register 0
#define BMA530_REG_ACC_CONF1 0x31 // Accelerometer configuration register 1 (e.g., power mode, bandwidth)
#define BMA530_REG_ACC_CONF2 0x32 // Accelerometer configuration register 2 (e.g., noise mode, range)
#define BMA530_I2C_ADDR 0x18 // I2C address for BMA530
// Motion Detection Configuration Registers
#define BMA530_REG_GENERIC_INT1_1 0x04 // Generic Interrupt 1 Configuration register 1
#define BMA530_REG_GENERIC_INT1_2 0x05 // Generic Interrupt 1 Configuration register 2
#define BMA530_REG_GENERIC_INT1_3 0x06 // Generic Interrupt 1 Configuration register 3
#define BMA530_REG_GENERIC_INT1_4 0x07 // Generic Interrupt 1 Configuration register 4
#define BMA530_REG_INT_MAP_1 0x37 // Interrupt mapping register 1
#define BMA530_REG_INT_MAP_2 0x38 // Interrupt mapping register 2
#define BMA530_REG_INT1_CONFIG 0x34 // Register for configuring INT1 behavior
#define BMA530_REG_FEAT_ENG_UPDATE 0x54 // Register to update the feature engine
#define BMA530_REG_FEAT_ENG_GPR_0 0x55 // Register to enable generic interrupt 1
// Macros for motion detection configurations
#define BMA530_CONF_FEAT_ENG_ENABLE (0x01 << 0)
//For GENERIC_INT1_1
#define BMA530_GENERIC_INT1_SLOPE_THRES(x) ((x) & 0xFFF)
#define BMA530_GENERIC_INT1_AXIS_SEL_X (0x01 << 13)
#define BMA530_GENERIC_INT1_COMB_SEL_OR (0x00 << 12)
//For GENERIC_INT1_2
#define BMA530_GENERIC_INT1_ACC_REF_UP (0x02 << 11) //sensor uses default reference value
#define BMA530_GENERIC_INT1_CRITERION_SEL (0x01 << 10) //evaluate condition for motion state of the device
#define BMA530_GENERIC_INT1_HYSTERESIS(x) ((x) & 0x3FF) // 10 bits (0x3FF is 1023 in decimal)
//For GENERIC_INT1_3
#define DURATION_500MS 25 // 500 ms duration (0.5 seconds * 50), scaling factor is 50
#define WAIT_TIME_200MS 10 // 200 ms wait time (0.2 seconds * 50), scaling factor is 50
//For GENERIC_INT1_4
#define QUIET_TIME_MIN 0 // Minimal quiet time, since it’s not needed in this application
//For INT_MAP_0 register
#define BMA530_REG_INT_MAP_0 0x36 //register address
#define BMA530_GEN_INT1_INT_MAP_INT1 (0x01 << 6) // Map Generic Interrupt 1 to INT1
// Macro for INT1 configuration (register 0x34)
#define INT1_CONFIG_EDGE_TRIGGERED (0x0B) // Edge-triggered, push-pull, active-high
// Macro for updating the feature engine (register 0x54)
#define FEATURE_ENGINE_ENABLE (0x01)
// Macro for enabling generic interrupt 1 (register 0x55)
#define BMA530_ENABLE_GENERIC_INT1 (0x01)
Are there any configuration steps or timing considerations I'm missing? I was able to verify the Chip ID is the expected value and accelerometer values are read correctly, so I2C is working as expected. I'm just trying to get motion detection to work so I can have the STM32 microcontroller in a low power mode and wake up when there is initial motion.
08-19-2024 06:47 PM
08-20-2024 07:37 AM
Thank you for the document. I implemented the logic and had these issues:
The INT1 interrupt was still constantly triggering, so I used my debugger to view the accelerometer values. They were not correct. The z-axis is the gravity axis and should be around 9.8 and it was 19.6. The chip is stationary and this is the result:
I reduced the initialization code down to only configuring registers 0x31 and 0x32, and the accelerometer readings were normal again:
This was my initialization code when the values were correct:
uint8_t buf[3];
// Soft reset the sensor
buf[0] = 0x7E;
buf[1] = 0xB6;
HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 2, HAL_MAX_DELAY);
HAL_Delay(10); // Stabilization delay after reset
// Configure common control registers
buf[0] = BMA530_REG_ACC_CONF1; // Register 0x31
buf[1] = 0x04; // Set BMA530 to LPM with 25Hz ODR
HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 2, HAL_MAX_DELAY);
buf[0] = BMA530_REG_ACC_CONF2; // Register 0x32
buf[1] = 0x0C; // Set ±2g full scale range
HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 2, HAL_MAX_DELAY);
When I only added back in the configuration of register 0x34 (INT1_CONFIG), the accelerometer values became bad again:
// Soft reset the sensor
buf[0] = 0x7E;
buf[1] = 0xB6;
HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 2, HAL_MAX_DELAY);
HAL_Delay(10); // Stabilization delay after reset
// Configure common control registers
buf[0] = BMA530_REG_ACC_CONF1; // Register 0x31
buf[1] = 0x04; // Set BMA530 to LPM with 25Hz ODR
HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 2, HAL_MAX_DELAY);
buf[0] = BMA530_REG_ACC_CONF2; // Register 0x32
buf[1] = 0x0C; // Set ±2g full scale range
HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 2, HAL_MAX_DELAY);
buf[0] = BMA530_REG_INT1_CONFIG; // Register 0x34
buf[1] = 0x0B; // Push-pull, active high, pulse-long (10us width)
HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 2, HAL_MAX_DELAY);
I’ve ensured that the STM32 GPIO configuration is set to disable the interrupt during initialization and only enable it after initialization is complete.
Do you know what could be wrong?
08-22-2024 07:28 AM
I did some more testing and noticed something interesting. I should mention I'm using the BMA530 Shuttle Board. After I wrote 0x09 to register 0x34 (INT1 configuration), which should be active high,push-pull, latched interrupt, I accidentally touched the chip and it was very hot. I also noticed the accelerometer values were wrong (Z-axis reads ~19.6 m/s² instead of ~9.8 m/s²) when this setting was implemented. Is there something specific about the INT1 pin behavior that could cause issues when using active high with push-pull? I reverted to writing 0x01 to register 0x34, and the chip immediately cooled down and the accelerometer values were correct. I tried other configurations of register 0x34 and they all did not cause the chip to heat up, and the accelerometer values read were all correct.
In my previous message I said the interrupt was constantly triggering, but I actually had INT1 connected to the wrong pin, and after correcting that, now the result is that the interrupt never triggers no matter what configuration I set for register 0x34. I set the STM32 to trigger on both rising and falling edges. I tested that the STM32 interrupt was configured correctly because I manually connected the STM32 interrupt pin to ground and 3.3V, and it triggered as expected.
This is my initialization function based on the document you sent me.
void BMA530_Init(void)
{
uint8_t buf[3];
// Soft reset the sensor
buf[0] = 0x7E;
buf[1] = 0xB6; // Soft-reset BMA530 to default settings
HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 2, HAL_MAX_DELAY);
HAL_Delay(10); // Wait after reset
// Configure common control registers
buf[0] = BMA530_REG_ACC_CONF1; // Register 0x31
buf[1] = 0x04; // LPM mode, 25Hz ODR for low power consumption
HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 2, HAL_MAX_DELAY);
buf[0] = BMA530_REG_ACC_CONF2; // Register 0x32
buf[1] = 0x0C; // ±2g range (maximum sensitivity), low noise
HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 2, HAL_MAX_DELAY);
HAL_Delay(100); // Stabilization delay after configuration
// Configure INT1 pin to be push-pull, active low, latched interrupt
buf[0] = BMA530_REG_INT1_CONFIG; // Register 0x34
buf[1] = 0x01; // Active low, push-pull, latched interrupt
HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 2, HAL_MAX_DELAY);
// Map the generic interrupt to INT1 pin
buf[0] = BMA530_REG_INT_MAP_0; // Register 0x36
buf[1] = 0x40; // Map gen1 signal to INT1 pin
HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 2, HAL_MAX_DELAY);
HAL_Delay(10); // Stabilization delay
// Configure generic interrupt 1 (gen1) parameters for high sensitivity
// Access feature engine register x04 in extended memory map (register 0x5E)
buf[0] = 0x5E;
buf[1] = 0x04;
buf[2] = 0x00; // Add the second byte for the 16-bit address
HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 3, HAL_MAX_DELAY);
// Set gen1 slope threshold to a very low value (e.g., 0.01g)
buf[0] = 0x5F;
buf[1] = 0x00; // MSB
buf[2] = 0x01; // LSB (slope threshold for high sensitivity)
HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 3, HAL_MAX_DELAY);
// Access feature engine register 0x05
buf[0] = 0x5E;
buf[1] = 0x05;
buf[2] = 0x00;
HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 3, HAL_MAX_DELAY);
// Set gen1 hysteresis and reference
buf[0] = 0x5F;
buf[1] = 0x02; // MSB
buf[2] = 0x00; // LSB (minimal hysteresis for maximum sensitivity)
HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 3, HAL_MAX_DELAY);
// Access feature engine register 0x06 in extended memory map (register 0x5E)
buf[0] = 0x5E;
buf[1] = 0x06;
buf[2] = 0x00; // Add the second byte for the 16-bit address
HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 3, HAL_MAX_DELAY);
// Set gen1 duration and wait time
buf[0] = 0x5F;
buf[1] = 0x01; // Short duration for quick motion detection
buf[2] = 0x00;
HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 3, HAL_MAX_DELAY);
// Enable generic interrupt 1
buf[0] = 0x55;
buf[1] = 0x01;
HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 2, HAL_MAX_DELAY);
// Update feature engine for settings to take effect
buf[0] = 0x54;
buf[1] = 0x01;
HAL_I2C_Master_Transmit(&hi2c1, (BMA530_I2C_ADDR << 1), buf, 2, HAL_MAX_DELAY);
// Optional: Print register values for debugging
printRegisterValues();
}
Any insights or guidance on what might be causing these issues would be appreciated.
08-22-2024 08:58 PM
Hi,
Your code looks ok and we could not reproduce the issue on our eval. boards. Could you please follow the document and try on your STM32 MCU to see the same issue?
Thanks.