LIS3DH双击测试

LIS3DH双击测试

双击检测

  1. 参考官方代码:链接
/*
   * Set full scale to 2 g.
   */
  lis3dh_full_scale_set(&dev_ctx, LIS3DH_2g);

  /*
   * Set click threshold to 12h -> 0.281 g
   * 1 LSB = full scale/128
   *
   * Set TIME_LIMIT to 20h -> 80 ms
   * Set TIME_LATENCY to 20h -> 80 ms
   * Set TIME_WINDOW to 30h -> 120 ms
   * 1 LSB = 1/ODR
   */
  lis3dh_tap_threshold_set(&dev_ctx, 0x12);
  lis3dh_shock_dur_set(&dev_ctx, 0x20);
  lis3dh_quiet_dur_set(&dev_ctx, 0x20);
  lis3dh_double_tap_timeout_set(&dev_ctx, 0x30);

  /*
   * Enable Click interrupt on INT pin 1
   */
  lis3dh_pin_int1_config_get(&dev_ctx, &ctrl_reg3);
  ctrl_reg3.i1_click = PROPERTY_ENABLE;
  lis3dh_pin_int1_config_set(&dev_ctx, &ctrl_reg3);
  lis3dh_int1_gen_duration_set(&dev_ctx, 0);

  /*
   * Enable double click on all axis
   */
  lis3dh_tap_conf_get(&dev_ctx, &click_cfg);
  click_cfg.xd = PROPERTY_ENABLE;
  click_cfg.yd = PROPERTY_ENABLE;
  click_cfg.zd = PROPERTY_ENABLE;
  lis3dh_tap_conf_set(&dev_ctx, &click_cfg);

  /*
   * Set device in HR mode.
   */
  lis3dh_operating_mode_set(&dev_ctx, LIS3DH_HR_12bit);

  /*
   * Set Output Data Rate.
   * The recommended accelerometer ODR for single and
   * double-click recognition is 400 Hz or higher.
   */
  lis3dh_data_rate_set(&dev_ctx, LIS3DH_ODR_400Hz);
  1. 初始化寄存器:可以触发但是很容易误触;
		LIS3DH_Write(CTRL_REG4, 0x00);		// Set full scale to 2 g.(1 LSB = full scale/128)
		
		LIS3DH_Write(TAP_THS, 0x32);		//  Set click threshold to 12h -> 0.281 g
		LIS3DH_Write(TIME_LIMIT, 0x10);		// "Set TIME_LIMIT to 20h -> 80 ms"		
		LIS3DH_Write(TIME_LATENCY, 0x20);	// "Set TIME_LATENCY to 20h -> 80 ms"
		LIS3DH_Write(TIME_WINDOW, 0x30);	// "Set TIME_WINDOW to 30h -> 120 ms"
	   /*
		*  Enable Click interrupt on INT pin 1
		*/
		LIS3DH_Write(CTRL_REG3, 0x80);		// ctrl_reg3.i1_click = PROPERTY_ENABLE;
		LIS3DH_Write(INT1_DURATION, 0x00);	// lis3dh_int1_gen_duration_set(&dev_ctx, 0);
	   /*
		*  Enable double click on all axis
		*/
		LIS3DH_Write(INT1_CFG, 0x10);		// Enable interrupt generation on all axis low event on Direction;
		
	   /*
		*  Set device in HR mode.
		*/
		LIS3DH_Write(CTRL_REG4, 0x08);		// lis3dh_operating_mode_set(&dev_ctx, LIS3DH_HR_12bit);
		
		/*
		 * Set Output Data Rate.
		 * The recommended accelerometer ODR for single and
		 * double-click recognition is 400 Hz or higher.
		 */
		LIS3DH_Write(CTRL_REG1, 0x77);		//

你可能感兴趣的:(LIS3DH双击测试)