搜索
bottom↓
回复: 5

关于MM8451Q配置中断的问题

[复制链接]

出0入0汤圆

发表于 2014-5-13 17:10:51 | 显示全部楼层 |阅读模式
飞思卡尔FRDM-KL05Z板子上的MM8451传感器如何配置,产生中断呢?
我按照手册给的寄存器进行的配置,配置的所有情况都产生中断,并设置中断为INT2脚,但是晃动板子用示波器未抓到INT2脚的中断信号。确实可以读取出三轴数据进行了变化。
请教是在配置中断的时候有什么地方需要注意吗?

阿莫论坛20周年了!感谢大家的支持与爱护!!

曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……

出0入0汤圆

 楼主| 发表于 2014-5-13 17:17:15 | 显示全部楼层
官方提供初始化的配置
void MMA8451_Initial(void)
{
    uint8    n, int_mask;
    uint8    CurrentReadMode;
    uint8    CurrentRange;
    uint8    CurrentDemo;
               
    CurrentReadMode = READ_MODE_14BITS;
    CurrentRange    = Full_Scale_Range_2g;
    CurrentDemo     = DEMO_TAP;
       
    /* Put MMA845xQ into Standby Mode */       
        MMA8451_Standby();  
   
    /* Configure sensor for:
         Sleep Mode Poll Rate of 1.56Hz (640ms) for maximum power saving
         System Output Data Rate (ODR) of 200Hz (5ms)
                 read mode 14-bit data
    */
//    n = ASLP_RATE_640MS + DATA_RATE_5MS;   
    n = ASLP_RATE_20MS + DATA_RATE_5MS;  
    if (CurrentReadMode == READ_MODE_8BITS)
        n |= FREAD_MASK;
    MMA8451WriteRegister(MMA8451_I2C_ADDRESS, CTRL_REG1, n);  
  
    /* Select user-specified sensitivity, 2g/4g/8g */
    MMA8451WriteRegister(MMA8451_I2C_ADDRESS, XYZ_DATA_CFG_REG, CurrentRange);
   
    /* Configure Sleep/Wake modes
        SMODS1:0   : 1 1    Low power mode when asleep
        SLPE       : 1      Sleep enabled
        MODS1:0    : 0 0    Normal mode when awake
    */
    MMA8451WriteRegister(MMA8451_I2C_ADDRESS, CTRL_REG2, 0x1c);         
    MMA8451WriteRegister(MMA8451_I2C_ADDRESS, ASLP_COUNT_REG, 15);      /* Sleep after 10 seconds of inactivity */         

    /* Disable the FIFO */
    MMA8451WriteRegister(MMA8451_I2C_ADDRESS, F_SETUP_REG, 0x00);

    switch (CurrentDemo)
    {
    case DEMO_TRANSIENT:
    case DEMO_SHAKE:
    case DEMO_ORIENTATION:
        /* In all three of these demo modes we configure the accelerometer to detect
           movement:
           
                DEMO_TRANSIENT   - We configure the accelerometer to detect small movements
                                   of > 0.063g                  
                                   
                DEMO_SHAKE       - We configure the accelerometer to detect movements
                                   of > 0.5g
                                                      
                DEMO_ORIENTATION - We don't care about the movement data itself, but
                                   we use transient detection so that the accelerometer
                                   can tell us when the board isn't being used. When
                                   it transitions to Sleep mode, we can put the main
                                   processor to sleep too.
                                   
          By using the high-pass filter we can remove the constant effect of gravity,
           and only detect changes in acceleration. See Application Note AN4071.
        */

        /* ELE = 1     : Event latch enabled
           ZTEFE = 1   : Raise event on any of Z, Y, X axes
           YTEFE = 1
           XTEFE = 1
           HBF_BYP = 0 : High-pass filter enabled
        */
            MMA8451WriteRegister(MMA8451_I2C_ADDRESS, TRANSIENT_CFG_REG, 0x1e);
        
        /* Set High-pass filter cut-off frequency for best sensitivity */
            MMA8451WriteRegister(MMA8451_I2C_ADDRESS, HP_FILTER_CUTOFF_REG, 0x03);   

        if (CurrentDemo == DEMO_SHAKE)
        {
            /* Transient is indicated when acceleration on one of the axes
               is above threshold 8 x 0.063g = 0.5g
             */   
                MMA8451WriteRegister(MMA8451_I2C_ADDRESS, TRANSIENT_THS_REG, 8);
        }
        else
        {
            /* Transient is indicated when acceleration on one of the axes
               is above threshold 1 x 0.063g - i.e. a small movement
            */   
                MMA8451WriteRegister(MMA8451_I2C_ADDRESS, TRANSIENT_THS_REG, 1);
        }

        /* Internal debounce counter. For an ODR of 200Hz in Normal mode,
           motion is indicated after 5 x 1 = 5ms.
        */
         MMA8451WriteRegister(MMA8451_I2C_ADDRESS, TRANSIENT_COUNT_REG, 1);

        /* Interrupt signalled on INT1 when transient detected */
        int_mask = INT_EN_TRANS_MASK;

        if (CurrentDemo == DEMO_ORIENTATION)
        {
            /* Interrupt also signalled when new data is ready */
             int_mask |= INT_EN_DRDY_MASK;
         
            /* Set up TPMs to produce edge-aligned PWM signals */
            //configure_LEDs_for_PWM ();   
        }
        break;
        
    case DEMO_TAP:
        /* Configure the accelerometer to detect single and double taps...
           (See Application Note AN4072)
        */

        /* Z configured for Single Tap and Double Tap with Latch enabled */
            MMA8451WriteRegister(MMA8451_I2C_ADDRESS, PULSE_CFG_REG, 0x70);   
        
        /* Enable low-pass filter */
            MMA8451WriteRegister(MMA8451_I2C_ADDRESS, HP_FILTER_CUTOFF_REG, PULSE_LPF_EN_MASK);   

        /* Set Z Threshold to 16 x 0.063g = 1.0g
           
           Note: In a more sophisticated application we could dynamically
           track the orientation and configure X, Y Z with changing thresholds
        */
            MMA8451WriteRegister(MMA8451_I2C_ADDRESS, PULSE_THSZ_REG, 16);  

        /* Set the Pulse Time Limit for 30 ms at 200 Hz ODR in Normal Mode with the LPF Enabled  
           30 ms/5 ms = 6 counts
        */
            MMA8451WriteRegister(MMA8451_I2C_ADDRESS, PULSE_TMLT_REG, 6);
        
        /* Set the Pulse Latency Timer to 100 ms, 200 Hz ODR Normal Mode, LPF Enabled  
           80 ms/10 ms = 8 counts
        */
            MMA8451WriteRegister(MMA8451_I2C_ADDRESS, PULSE_LTCY_REG, 8);
        
        /* Set the Pulse window to 400 ms, 200 Hz Normal Mode, LPF Enabled
           300 ms/10 ms = 30 counts
        */
            MMA8451WriteRegister(MMA8451_I2C_ADDRESS, PULSE_WIND_REG, 30);

        /* Interrupt signalled on INT1 when pulse detected */
        int_mask = INT_EN_PULSE_MASK;
        break;
        
    case DEMO_FREEFALL:
        /* Configure accelerometer for linear freefall detection...
           [Note that the accelerometer can also detect tumbling, as
            described in Application Note AN4070]
        */
        
        /* ELE = 1   : Event latch enabled
           OAE = 0   : Detect Freefall
           ZEFE = 1  : Raise event on any of Z, Y, X axes
           YEFE = 1
           XEFE = 1
        */
            MMA8451WriteRegister(MMA8451_I2C_ADDRESS, FF_MT_CFG_1_REG, 0xb8);   
        
        /* Freefall is indicated when acceleration on all three axes
           falls below threshold 3 x 0.063g = 0.19g
        */   
            MMA8451WriteRegister(MMA8451_I2C_ADDRESS, FT_MT_THS_1_REG, 3);
        
        /* Internal debounce counter. For an ODR of 200Hz in Normal mode,
           freefall is indicated after 5 x 20 = 100ms of falling - a drop
           of a few centimetres - See Application Note AN4070
        */
            MMA8451WriteRegister(MMA8451_I2C_ADDRESS, FF_MT_COUNT_1_REG, 20);

        /* Interrupt signalled on INT1 when Freefall detected */
        int_mask = INT_EN_FF_MT_1_MASK;
        break;
    }
   
    /* Configure interrupts */
    int_mask |= INT_EN_ASLP_MASK;                           /* Also generate interrupt on
                                                               Sleep <--> Wake transition
                                                            */
    MMA8451WriteRegister(MMA8451_I2C_ADDRESS, CTRL_REG4, int_mask);
    MMA8451WriteRegister(MMA8451_I2C_ADDRESS, CTRL_REG5, 0xfd);         /* All interrupts mapped to MMA_INT1 */
    MMA8451WriteRegister(MMA8451_I2C_ADDRESS, CTRL_REG3, 0x78);         /* Active-low interrupts, all functions
                                                                           wake system
                                                                        */  

    /* Throw away any stale interrupt info */
//    last_int_source_reg = 0;
   
    /* Put MMA845xQ into Active Mode */
        MMA8451_Active();

    /* Enable MMA_INTx interrupts */
//    KBI1_SC_KBIE  = 1;  
                 
}
但是也未产生中断信号

出0入0汤圆

 楼主| 发表于 2014-5-16 13:02:57 | 显示全部楼层
没人给解答下?

出0入0汤圆

发表于 2014-5-27 09:09:37 | 显示全部楼层
同样问题,可否有人回答?

出0入0汤圆

发表于 2014-5-27 18:28:22 | 显示全部楼层
问题解决了,原来是3轴的方向检测没有搞懂,设置了3个方向才激发中断
调整为Z轴检测到就出发中断,果然中断产生。
当然细节还需调整。

出0入0汤圆

发表于 2014-5-30 09:35:17 | 显示全部楼层
liren 发表于 2014-5-27 18:28
问题解决了,原来是3轴的方向检测没有搞懂,设置了3个方向才激发中断
调整为Z轴检测到就出发中断,果然中断 ...

感谢你的经验分享,如果可以的话,建议到外面飞思卡尔的全部主题里发个经验贴,并分享下代码。
这样你也能多赚点飞币,还方便了大家。
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-8-26 03:22

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表