0

I would like to use the interrupt register from the BMA220 accelerometer in order to detect high-g shock. I am using a Mega2560 and the sensor is powered by 3.3 V. I use a voltage divider to convert the 5V from the card to 3.3V because the 5V pin gives more current. The memory map concerning the registers is shown below Memory map for registers In the datasheet the section concerning high-g registers is as followed : High-g detection registers 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 don't get my interrupt working. Using a voltmeter I always get a high value (3.3V) on the INT pin of my accelerometer eventhough it stays still and I wrote a threshold of 2G...

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, 0xF7); // enable high-g-detection, reset interrupt bit control and latch permanently
   bma.setRegister(HIGH_LOW_TH, 0x1); // Threshold of 1G
   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, 0xF7); // enable high-g-detection, reset interrupt bit control and latch permanently
    }
    else{
      Serial.println("No shock");
      count =0;
    }
}

void counter(){
  count +=1;
}

Am I missing something to clear in one register ? Or maybe since the card is in 5V and the sensor 3.3V logic there is a problem to detect change on the interrupt pin ? Also I don't know if I understand properly the "logic 1". For me it means it puts the pin to "HIGH".

I use a part of the library written by Sönke Carstens-Behrens to set the registers from here : https://github.com/scbrac/BMA220.

I really need this interrupt pin to work...

Thank you for your help !

21
  • 1
    I use a voltage divider to convert the 5V from the card to 3.3V because the 5V pin gives more current. errr.... NO! majenko.co.uk/blog/why-you-cant-use-resistors-voltage-regulator – Majenko Sep 5 '19 at 14:05
  • Ok thank you for the article it answers simply the problem of voltage divider ! So it means I just cannot make my device work properly without a voltage regulator ? However I used to record some data that way and it was working. Appart from this, is there something in my code that shouldn't work ? – JamesONeil Sep 5 '19 at 14:48
  • I am not too familiar with that unit, so I can't be sure. However, you don't need a voltage regulator. Just use the 3.3V pin to power it. On modern Arduinos the 3.3V pin can provide plenty of power. The old rumour that 3.3V is limited to 50mA is wrong, and has been for many years. – Majenko Sep 5 '19 at 14:50
  • Ok I will use the 3.3V then, thank you ! Has anybody an idea about the logic 1 interrupt ? – JamesONeil Sep 5 '19 at 15:13
  • You should, at least for testing, set lat_int to 0b111 so it latches the interrupt on the pin until you manually reset it by setting reset_int to 1. At the moment you have such a brief interrupt that you'll be hard pressed to see it even if it does trigger. – Majenko Sep 5 '19 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.