LIS3DH Interrupt generation

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello, I am currently trying to configure the LIS3DH Interrupt to wake up atmega 2560 to a shock over +-2g. The problem i am having is that the INT pin will not activate. Anyone have any suggestions? 

I would imagine that this should work: 

void I2C_Write(Reg_Address,num_bytes,Data);

{

...

}

Initialize:

 

I2C_Write(0x21,3,0x00);   //Turn on the sensor and enable X, Y,and Z and ODR = 100 Hz

I2C_Write(0x21,3,0x00);    // High-pass filter disabled

I2C_Write(0x22,3,0x40);    // Interrupt activity 1 driven to INT1 pad:

I2C_Write(0x23,3,0x00); // FS = ±2 g

I2C_Write(0x24,3,0x08);  // Interrupt 1 pin latched

I2C_Write(0x32,3,0x16);  // Threshold = 350 mg 

I2C_Write(0x33,3,0x03); // Duration = minimum

I2C_Write(0x30,3,0x95); // Configure free-fall recognition

 

 

 

Literature:

https://cdn-shop.adafruit.com/da...

https://www.st.com/content/ccc/r...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I2C_Write() looks suspicious. Num_bytes =3 but only one byte is provided.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Its not optimal, but the problem is not in the I2C communication. I can see how it looks suspicious:S

void I2C_Write(int address,int num_bytes, int data)
{  

    unsigned char messageBuf[4];
    unsigned char TWI_targetSlaveAddress=rgSystems->Address;
    messageBuf[0] = (TWI_targetSlaveAddress<<TWI_ADR_BITS) | (FALSE<<TWI_READ_BIT); // 0x40<<1|0x00; (SA+write)
    messageBuf[1] =  address;                        
    messageBuf[2] = data;
    TWI_Start_Transceiver_With_Data( messageBuf, num_bytes);
}
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok, but it seems you write to register 0x21 twice. I've not checked the datasheet, so it may not be an issue. Is the first write meant to be to register 0x20?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for noticing, actually i misspelled in the post:

I2C_Write(0x20,3,0x57); // Turn on the sensor and enable X, Y,and Z

is what i actually do.

 

more detailed:

1. Write 57h into CTRL_REG1 // Turn on the sensor, enable X, Y, and Z // ODR = 100 Hz

2. Write 00h into CTRL_REG2 // High-pass filter disabled

3. Write 40h into CTRL_REG3 // Interrupt activity 1 driven to INT1 pad

4. Write 00h into CTRL_REG4 // FS = ±2 g

5. Write 08h into CTRL_REG5 // Interrupt 1 pin latched

6. Write 16h into INT1_THS // Set free-fall threshold = 350 mg

7. Write 03h into INT1_DURATION // Set minimum event duration

8. Write 95h into INT1_CFG // Configure free-fall recognition

 

After each write I read the same register to dobbelcheck that I set the register to the correct value. So there must be something wrong with the settings i choose, maybe  i shouldnt Write 95h into INT1_CFG but some-other value instead. It seams like i have tried out alot of combinations but havent been able to activate the Interrupt pin...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

this does not seem to be an atmel issue, you should contact ST about this!

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh, please! I use the LIS3DSH, which is pretty similar. But, that is nearly unreadable. 

 

Make your self a header file and use  #define to name those registers with names that mimic the data sheet. Then, add bit names. Sure, its work, but if you want help, hardly anyone is going to go through (expletive deleted) like that. 

 

Here is a partial example of what I did (for LIS3DSH):

 


//Status register, mostly for StateMachines but includes DRDY & DOR
#define LIS_STAT	0x18	//READ ONLY REGISTER
#define LIS_LONG	7	//state machine long counter interrupt flag
#define LIS_SYNCW	6	//not sure
#define LIS_SYNC1	5	//StateMachine1 status
#define LIS_SYNC2	4	//StateMachine2 status
#define LIS_INT_SM1	3	//StateMachine1 interrupt flag
#define LIS_INT_SM2	2	//StateMachine2 interrupt flag
#define LIS_DOR		1	//data over-run error flag
#define LIS_DRDY	0	//data ready flag

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Fri. Feb 8, 2019 - 08:29 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Mr_logger wrote:
Thanks for noticing, actually i misspelled in the post:

Please do not post "re-typed" code.  You see what happens.  People spend time, aha!, and then find out the typo was in the post and not in the code.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.