ARDUINO + ADXL345 Interrupt Clear Problem Solution

To Everyone;

I have been integration a project with Arduino with atMega328p & ADXL345. I got a Free Fall interrupt from INT1(Connected to D3) however was not able to clear it. I discovered that reading INT_SOURCE does not help totally, you should first disable interrupt from INT_ENABLE & INT_MAP then read INT_SOURCE & enable it again for repetitive interrupts.

I add the functions below to ADXL345 library.(using I2C)

void ADXL345::EnableInterrupt()

{

Write(THRESH_FF, 0x0A);

Write(TIME_FF , 0x10);

uint8_t interruptsr = Read(INT_ENABLE,1)[0];

interruptsr |= FREE_FALL; //interruptsr = FREE_FALL;

Write(INT_ENABLE,interruptsr);

Write(THRESH_FF, 0x07);

Write(TIME_FF , 0x10);

interruptsr = Read(INT_MAP,1)[0];

interruptsr &= ~FREE_FALL;

Write(INT_MAP,interruptsr);

}

void ADXL345::DisableInterrupt()

{

uint8_t interruptsr = Read(INT_ENABLE,1)[0];

interruptsr &= ~FREE_FALL; //clear

Write(INT_ENABLE,interruptsr);

interruptsr = Read(INT_MAP,1)[0];

interruptsr |= FREE_FALL;

Write(INT_MAP,interruptsr);

}

Hope to help you…

Hello fantastic,

that is a problem that affected virtually everybody using the ADXL345.

I would love to merge your changes into a full library like this:

https://github.com/jenschr/Arduino-libr … er/ADXL345

but I have to ask you what i2c library have you been using:

Read(INT_ENABLE,1)[0]

does this indicate a 1 byte read and take the first bit?

Why are you changing the THRESH_FF before and after disabling the interrupt?

:smiley:

This is my understanding so far:

void ADXL345::EnableInterrupt()
{
  	byte _interruptsr;
	writeTo(ADXL345_THRESH_FF, 0x0A); 
	writeTo(ADXL345_TIME_FF, 0x10); 


  	readFrom(ADXL345_INT_ENABLE, 1, &_interruptsr);
	//uint8_t interruptsr = Read(INT_ENABLE,1)[0];

	_interruptsr |= ADXL345_INT_FREE_FALL_BIT; //interruptsr = FREE_FALL;

	writeTo(ADXL345_INT_ENABLE,_interruptsr);
	writeTo(ADXL345_THRESH_FF, 0x07); 
	writeTo(ADXL345_TIME_FF, 0x10); 

	readFrom(ADXL345_INT_MAP, 1, &_interruptsr);
	_interruptsr &= ~ADXL345_INT_FREE_FALL_BIT;

	writeTo(ADXL345_INT_MAP, 0x10); 
}

void ADXL345::DisableInterrupt()
{
	byte _interruptsr;
	readFrom(ADXL345_INT_ENABLE, 1, &_interruptsr);
	//uint8_t interruptsr = Read(INT_ENABLE,1)[0];
	_interruptsr &= ~ADXL345_INT_FREE_FALL_BIT; //clear
	writeTo(ADXL345_INT_ENABLE,_interruptsr);
	readFrom(ADXL345_INT_MAP, 1, &_interruptsr);
	_interruptsr |= ADXL345_INT_FREE_FALL_BIT;
	writeTo(ADXL345_INT_MAP, _interruptsr); 

}

going to test it on my panstamp setup (Arduino 3.3V)