cancel
Showing results for 
Search instead for 
Did you mean: 

Stream to FIFO mode and WTM interrupt generation

Marco Pappalardo
Associate II
Posted on October 10, 2017 at 12:36

Hi,

I'm using IIS2DH in my application and I am in the need of reading FIFO values registered after a threshold has been reached. For this reason using Stream-to-FIFO mode seemed perfect. But I tried it and I had some problems and doubts.

What I was trying to do was to use this configuration:

INT2_CFG = 0b00101000; //OR Event enabled, High Z, Y axes enabled

INT2_THS = 0b00011000; //24LSB = 1.488 g

CTRL_REG_1 = 0b01001110, //LP 50 Hz X axis disabled

CTRL_REG_2

 = 0b00001011, //Filter: normal mode HPM = 00, ft = 0.2 Hz, FDS = 1, HPIS = 1

CTRL_REG_3

 = 0b00000010, //OVR on INT1

CTRL_REG_4

 = 0b00100000, //Normal MODE, FS=+-8g

CTRL_REG_5 

= 0b01000010, //FIFO enabled with latch on INT2 pin

CTRL_REG_6 

= 0b00100000, //Int function 2 on INT2 pin

FIFO_CTRL_REG

 = 0b10000000,//Stream mode

The idea was to use the INT function 2 (I guess it is referret to the OR the I set in the INT2_CFG register) to toggle the INT2 pin and switch from to Stream mode to the FIFO mode, then read the FIFO overrun interrupt on the INT1 pin, read all FIFO elements through a multiple byte read command and in the end clear the INT2 pin by reading the INT2_SRC register.

In practice after reading the INT2 pin I can't see any FIFO overrun in the INT1 and I cannot know when to read the FIFO ('cause it's full-filled). I've noticed that after the initialization of accelerometer registers I get an interrupt on INT1 pin and I think it's due to the fact that FIFO overrun it's generated also in Stream mode and in FIFO mode, so when the accelerometer starts in Stream mode it will fire a overrun interrupt when FIFO is full-filled. The problem is I don't want to read any value from the accelerometer since the threshold is reached and the FIFO is filled, because this will cause my microcontroller a waste of clock operations and keeps busy the I2C bus.

I also made I try activating another threshold using:

INT1_CFG = 0b00101010; //OR Event enabled, High axes event enabled

INT1_THS = 0b00001100; //12LSB = 192 mg

and enabling AOI1 on CTRL_REG_3, but I've seen that no interrupt is fired on INT1 pin after the INT2 event toggles the INT2 pin.

So my doubts are:

1) Do the latch set on INT2 function locks the entire accelerometer and not only the INT2 pin/function?

2) I also tried to unset the latch on int2 function but what I had is that the FIFO mode where never toggled. Is It because INT2 pin needs to stay at logic level 1 to make the toggle, not just a spike?

3) There is a configuration which I can set to use the accelerometer the way I need?

Thanks,

Marco

#iis2dh
10 REPLIES 10
Miroslav BATEK
ST Employee
Posted on October 10, 2017 at 13:20

Hi Marco,

what is the name of the sensor?

Posted on October 10, 2017 at 15:02

Yes, sorry. I forgot to mention, just tagged it: IIS2DH

Marco Pappalardo
Associate II
Posted on October 16, 2017 at 16:07

Ok listen, let's make things simpler.

I would like the IIS2DH to have this behaviour:

1) no interrupt until the threshold on one INTx_

THS is reached;

2) after the threshold is reached the FIFO will be filled with data until it is full-filled;

3) an interrupt is fired on a INTx pin;

4) so I can read the full FIFO data to see how acceleration data evolved after the event.

Can I do it? Which is the working configuration for the device to follow this behaviour?

One last thing: is it necessary to set the INTx_DURATION or can I leave it in the default value: 0?

Thanks,

Marco

Miroslav BATEK
ST Employee
Posted on October 16, 2017 at 20:29

Hi Marco,

I'm sorry for the late reply, I think your requirements can be fulfiled. Tommorow I will try it and let you know.

DURATION can be 0, it means only one sample is enough to trigger the threshold.

Posted on October 17, 2017 at 11:07

Hi Marco,

unfortunately the Stream-to-FIFO mode is not suitable mode for you needs, because in the stream mode the FIFO will be quickly filled and when the interrupt occurs only one sample will be added into the FIFO and it will stop capturing the data. So in this mode you are able to analyze the history before the interrupt.

To analyze the data after the interrupt you would need an accelerometer with Bypass-to-Continuous mode.

The only solution I see is manually switch the FIFO mode by the microcontroller: The accelerometer FIFO will be in bypass mode, when the threshold is reached the accelerometer generates interrupt which will be captured by the microcontroller and the microcontroler switch the FIFO mode from bypass to FIFO mode. Then another interrupt can be generated by the accelerometer when the FIFO will be full.

Posted on October 17, 2017 at 15:39

Thank you Miroslav, I'll try it and evaluate the result.

Have a good day!

Marco

Posted on October 19, 2017 at 18:06

Hi Miroslav,

I tried you solution but there is something unexpected in the accelerometer behaviour. I paste here all the steps I took and what did happened.

I've set the registers (even in all tries):

const uint8_t INT1_CFG = 0b00101010; //OR Event enabled, High axes event enabled

const uint8_t INT1_THS = 0b00000100; //4LSB

const uint8_t INT2_CFG = 0b00101000; //OR Event enabled, High Z, Y axes enabled

const uint8_t INT2_THS = 0b00011000; //24LSB

** FIRST TRY **

1) I've set the registers in this way:

.ctrl_reg1 = 0b00101110, //LP 10 Hz X axis disabled

.ctrl_reg2 = 0b00001011, //Filter: HPM = 00, ft = 0.2 Hz, FDS = 1, HPIS2 = 1, HPIS1 = 1

.ctrl_reg3 = 0b00000010, //FIFO OVR

.ctrl_reg4 = 0b00100000, //FS=+-4g

.ctrl_reg5 = 0b01000000, //FIFO enabled

.ctrl_reg6 = 0b00100000, //I2_INT2 = 1

.fifo_ctrl_reg = 0b00000000, //Bypass MODE

2) Moving the board, I've received the interrupt on INT2 pin.

3) Then I changed the 

fifo_ctrl_reg = 0b01000000, //FIFO MODE

4) NO interrupt on INT1 pin.

5) I read the full fifo content with a burst read of 192 bytes

6) Just after the read command sent on the I2C bus I receive a INT1 interrupt.

7) Moving the board the second time

8) Still no interrupts

** SECOND TRY **

1) thinking it is related to the fact that FIFO OVR has been enabled before the change of the mode, I set

.ctrl_reg3 = 0b000000

0

0

2)

Moving the board, I've received the interrupt on INT2 pin.

3) Then I changed the 

fifo_ctrl_reg = 0b01000000, //FIFO MODE AND ctrl_reg3 = 0b000000

1

0, //FIFO OVR

4) NO interrupt on INT1 pin.

5) I read the full fifo content with a burst read of 192 bytes

6) Just after the read command sent on the I2C bus I receive a INT1 interrupt.

7) Moving the board the second time

8) Still no interrupts

So, same behaviour of last try.

** THIRD TRY **

3) Then I changed the 

fifo_ctrl_reg = 0b10000000, //STREAM MODE AND ctrl_reg3 = 0b000000

1

0, //FIFO OVR

4) NO interrupt on INT1 pin.

5) I read the full fifo content with a burst read of 192 bytes

6) Just after the read command sent on the I2C bus I receive a INT1 interrupt.

*NOTE*: the content of the fifo is practically blank (all samples are next to zero value) since, due to the fact that interrupt is not generated, all samples have been overwritten before reading.

7) No need to move the board, I receive an interrupt on INT1 just about 3 seconds after reading the full fifo content.

So, why no interrupt is generated after changing the working mode of the FIFO? Do I need to set/unset some bits in the registers to enable it?

Thanks, 

Marco

Miroslav BATEK
ST Employee
Posted on October 20, 2017 at 14:51

You configuration and procedures (

First Try, Second Try) are correct, it should work. I tested it and it works as I expected.

Do you wait enough time for the interrupt INT1 in step 4)?

I see the interrupt after about 3 seconds, which is correct, FIFO has 32 samples and the ODR is 10Hz.

Did you read the FIFO_SRC_REG before you read the FIFO in step 5)? What was the value?

Posted on October 20, 2017 at 16:57

Yes I read it just before the INT2 appear and it was 0x04 (correct) and after some seconds the INT2 fired and I read 0xdf (correct). The only thing do not appens is the FIFO OVR interrupt on INT1 pin (I wait for long).

If I read the FIFO content then an interrupt happens on INT1 pin after about 3 seconds (as set).

Have you set both INTx_CFG and INTx_THS and the other registers as mine?