FXLS8471Q - Accelerometer orientation detection function example code

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

FXLS8471Q - Accelerometer orientation detection function example code

FXLS8471Q - Accelerometer orientation detection function example code

Hi Everyone,

 

If you are interested in a simple bare metal example code illustrating the use of the FXLS8471Q orientation detection function, please find below one of my examples I created for the FXLS8471Q accelerometer while working with the NXP FRDM-KL25Z platform and FRDMSTBC-A8471 board.

 

This example code complements the code snippet from the  AN4068.

 

void FXLS8471Q_Init (void)
{
  FXLS8471Q_WriteRegister(CTRL_REG1, 0x00);  // Standby mode
      
  FXLS8471Q_WriteRegister(PL_CFG_REG, 0x40); // Enable orientation detection
  FXLS8471Q_WriteRegister(PL_BF_ZCOMP_REG, 0x43);  // Back/Front trip point set to 75°, Z-lockout angle set to 25°
  FXLS8471Q_WriteRegister(P_L_THS_REG, 0x14);  // Threshold angle = 45°, hysteresis = 14°
  FXLS8471Q_WriteRegister(PL_COUNT_REG, 0x05); // Debounce counter set to 100ms at 50Hz 
      
  FXLS8471Q_WriteRegister(CTRL_REG3, 0x00);  // Push-pull, active low interrupt
  FXLS8471Q_WriteRegister(CTRL_REG4, 0x10); // Orientation interrupt enabled
  FXLS8471Q_WriteRegister(CTRL_REG5, 0x10); // Route orientation interrupt to INT1 - PTD4
            
  FXLS8471Q_WriteRegister(CTRL_REG1, 0x21); // ODR = 50Hz, Active mode
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 

 

In the ISR, only the interrupt flag is cleared and the PL_STATUS (0x10) register is read in order to:

 

- Clear the SRC_LNDPRT flag in the INT_SOURCE register and deassert the INT1 pin, as shown on the screenshot below.

- Get orientation information. 0x82 in this example corresponds to "Portrait down" orientation.

 

void PORTD_IRQHandler()
{
  PORTD_PCR4 |= PORT_PCR_ISF_MASK; // Clear the interrupt flag 
  PL_Status = FXLS8471Q_ReadRegister(PL_STATUS_REG); // Read the PL_STATUS register to clear the SRC_LNDPRT flag in the INT_SOURCE register  
}‍‍‍‍‍‍‍‍‍‍

 

pastedImage_1.png

 

 

Attached you can find the complete source code. If there are any questions regarding this simple example code, please feel free to ask below. 

 

Regards,

Tomas

标签 (1)
附件
无评分
版本历史
最后更新:
‎09-11-2020 05:48 AM
更新人: