Showing results for 
Search instead for 
Did you mean: 

lis2de12 landscape/portrait interrupt

Associate III

I have this MEMS sensor on a custom board to detect landscape or portrait mode of my device.
The problem is that it doesn't generate an interrupt.

- 4D mode should be sufficient.
- Range 2g
- Tested different ODR settings.


My current code is now:






void tilt_init(void)

	dev_ctx.write_reg = platform_write;
	dev_ctx.read_reg = platform_read;
	dev_ctx.handle = &SENSOR_BUS;

	lis2de12_boot_set(&dev_ctx, PROPERTY_ENABLE);

	lis2de12_pin_sdo_sa0_mode_set(&dev_ctx, LIS2DE12_PULL_UP_DISCONNECT);
	lis2de12_high_pass_mode_set(&dev_ctx, LIS2DE12_NORMAL);

	lis2de12_device_id_get(&dev_ctx, &whoamI);

	/*Set Output Data Rate */
	lis2de12_data_rate_set(&dev_ctx,  LIS2DE12_ODR_400Hz );

	/*Set full scale */
	lis2de12_full_scale_set(&dev_ctx, LIS2DE12_2g);

	/* Enable Block Data Update */
	lis2de12_block_data_update_set(&dev_ctx, PROPERTY_ENABLE);

	/*Configure power mode */
	//lis2de12_power_mode_set(&dev_ctx, IIS2DLPC_CONT_LOW_PWR_LOW_NOISE_12bit);

	/* Apply high-pass digital filter on Wake-Up function
	   * Duration time is set to zero so Wake-Up interrupt signal
	   * is generated for each X,Y,Z filtered data exceeding the
	   * configured threshold
	lis2de12_int1_gen_duration_set(&dev_ctx, 1);

	/*LPF2 on 6D function selection. */
	//lis2de12_6d_feed_data_set(&dev_ctx, IIS2DLPC_LPF2_FEED);

	/*Enable interrupt generation 6D & double tab on INT1 pin. */
	//lis2de12_pin_int1_route_get(&dev_ctx, &int_route.ctrl4_int1_pad_ctrl);

	lis2de12_int1_cfg_t lis2de12_int1_cfg = {0};
	lis2de12_int1_cfg._6d  = PROPERTY_ENABLE;
	lis2de12_int1_cfg.xhie = PROPERTY_ENABLE;
	lis2de12_int1_cfg.xlie = PROPERTY_ENABLE;
	lis2de12_int1_cfg.yhie = PROPERTY_ENABLE;
	lis2de12_int1_cfg.ylie = PROPERTY_ENABLE;

	lis2de12_int1_gen_conf_set(&dev_ctx, &lis2de12_int1_cfg);

	lis2de12_int1_pin_detect_4d_set(&dev_ctx, PROPERTY_ENABLE);

	lis2de12_ctrl_reg3_t lis2de12_ctrl_reg3 = {0};
	lis2de12_ctrl_reg3.i1_ia1 = PROPERTY_ENABLE;

	lis2de12_pin_int1_config_set(&dev_ctx, &lis2de12_ctrl_reg3);

	//Set temp measuring
	lis2de12_temperature_meas_set(&dev_ctx, LIS2DE12_TEMP_ENABLE);

	 *  Latched interrupt
	//iis2dlpc_int_notification_set(&dev_ctx, IIS2DLPC_INT_LATCHED);








Am I missing something crucial?


Auch!, apparently the tilt interrupt pin number matched this wrong OR operation of other interrupt pins
Of all the pins you can choose as a designer!


Still wondering how Tilt pin 0x0020 validates as true for if(GPIO == 0x4000 || 0x2000) 

Although this fixed the problem of handling interrupts correctly, it is still not generated bij the MEMS.
I only tested the interrupt pin manually


How can I setup the portrait/landscape threshold angle and rigger an interrupt?

Federica Bossi
ST Employee

Hi @WSpar.1 ,

Have you already look at our PID examples on github?

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

you mean 

 if(GPIO == 0x4000 || 0x2000) 


 if((GPIO == 0x4000) || (GPIO == 0x2000)) ?