# How to set registers of accelerometer BMA220?

I first wrote my problem in Arduino Stack exchange (https://arduino.stackexchange.com/questions/68438/how-to-manage-interrupt-from-accelerometer-bma220) but I was told that I might get a better help here.

I would like to use the interrupt register from the BMA220 accelerometer in order to detect high-g shock. I am using an Arduino Mega2560 as microcontroller. The memory map concerning the registers is shown below In the datasheet the section concerning high-g registers is as followed : It is written that whenever a condition is met for the interrupt controller "an interrupt (logic '1') is issued through the INT pin of the sensor."

However after initializing the necessary registers (in I2C):

• 0xC for high_th
• 0xA for high_hy and high_dur
• 0x1C for en_high_x/y/z

I managed to get my interrupt working by latching it during 0.5s but I have problem to understand the threshold level parameter.

Here is the code I am using :

#include <BMA220.h>
#include "SEN0168.h"

BMA220 bma;
byte interruptPin = 2;
byte count = 0;
const uint8_t HIGH_SET = 0xA;
const uint8_t HIGH_LOW_TH = 0xC;
const uint8_t INTERRUPT_REG = 0x18; // to get the bit indicating an interrupt was detected, not used because of the INT pin
const uint8_t ENABLE = 0x1C;

void setup() {
Serial.begin(74880);
pinMode(interruptPin, INPUT);
init_SEN0168(R4); // set sensitivity to 4G
bma.setRegister(ENABLE, 0b10110111); // enable high-g-detection, reset interrupt bit control and latch permanently
bma.setRegister(HIGH_LOW_TH, 0x4); // Threshold of 2G
bma.setRegister(HIGH_SET, 0x1); // No hysteresis and 2 signals needed to trigger
attachInterrupt(digitalPinToInterrupt(interruptPin),counter, HIGH);
}

void loop() {
if (count==1){
Serial.print("x-axis: ");
Serial.println(accel_range_SEN0168(X,R4));
Serial.print("y-axis: ");
Serial.println(accel_range_SEN0168(Y,R4));
Serial.print("z-axis: ");
Serial.println(accel_range_SEN0168(Z,R4));
count =0;
bma.setRegister(INTRP_RES_REG, 0b10110111); // enable high-g-detection, reset interrupt bit control and latch permanently
}
else{
Serial.println("No shock");
count =0;
}
}

void counter(){
count +=1;
}


As you can see from the table about high-g, writing a certain number of g in the threshold register is equivalent to the double measured by the sensor so in my code it should be 2G of threshold with 0x4 written. However it gets waking up abnormally just by moving it around... Writing 0x8 is much better but I still don't think I give it 4g when it wakes up.

Do you know how to set the threshold properly and use the hysteresis wisely ?

Thank you for your help !

• read page 15 of the datasheet ... section 5.1 Latched vs. non-latched modes ... if the interrupt signal is always asserted, then the likely cause is that it is not being cleared after an interrupt condition .... perhaps you need to read a register to cause the pin to reset – jsotola Sep 9 '19 at 7:52
• Hi ! I just saw something strange on my voltmeter link to the interrupt pin. According to the orientation of my accelerometer I don't get the same behaviour from the interrupt PIN. If it is oriented with axis Z facing up I always get HIGH but for the other axes it gives me LOW... I set the latch to 0.5s but it doesn't change this – JamesONeil Sep 9 '19 at 8:08
• maybe you set a threshold of less than one G .... that would probably trigger the interrupt due to earth's gravity – jsotola Sep 9 '19 at 8:14
• I updated the code sorry... My actual Threshold is of 2G (0x2) so it is not normal to have it triggered. I am not sure I understand this in the table : "1 LSB is 2*(LSB of acc_data)" Does it mean that if I put 2G for example I get 4G or the contrary ? – JamesONeil Sep 9 '19 at 8:22
• I desactivated the (enable high z) so it stops triggering for no reason. However what is not normal is that when I orient other axes face up I don't get the trigger... – JamesONeil Sep 9 '19 at 9:24