Example #1
0
/*
读取
 */
void EXTI9_5_IRQHandler( void )
{
	uint8_t value1,value2,value3;
	if( EXTI_GetITStatus( EXTI_Line5 ) != RESET )
	{
		IIC_RegRead( MMA845X_ADDR, INT_SOURCE_REG, &value1 );
		IIC_RegRead( MMA845X_ADDR, PL_STATUS_REG, &value2 );
		IIC_RegRead( MMA845X_ADDR, PULSE_SRC_REG, &value3 );
		//rt_kprintf("\nINT=%02x %02x %02x\n",value1,value2,value3); 
		//                                                          trigger  type    grade
             /*
                         Shake Trigger     
             */
             //-----------   碰撞判断--------------
             if(value3>0)
             	{
             	      ShakeSenor.Collision_Keeping=0;   // clear
		      ShakeSenor.Layingdown_Keeping=0; // clear  		     
		      if(firstrun==1)
	                              firstrun=0;      //上电 第一次触发不上报
		      else	   
	              {       
	                       Warn_Status[0]|=0x20; //bit29 	
	                       PositionSD_Enable();  
	                       Current_UDP_sd=1; 
	                       rt_kprintf("\r\n  碰撞触发!\r\n");  
		        }
             	}
             //----------    侧翻判断 --------------
             if((value2>0)&&(value3==0))
             	{    
             	       ShakeSenor.LayingdownCounter++;
		       if(ShakeSenor.LayingdownCounter>100) 
		       {
                          ShakeSenor.LayingdownCounter=0; // clear 
                          if(firstrun==1)
	                              firstrun=0;      //上电 第一次触发不上报
			      else	   
		              {       
		                     if((Warn_Status[0]&0x40)==0x00)   
		                      { 
		                          PositionSD_Enable();  
		                          Current_UDP_sd=1; 
					     rt_kprintf("\r\n  侧翻触发!\r\n");  		 			  
		                       }		
					   Warn_Status[0]|=0x40; //bit29 	   
					    ShakeSenor.Layingdown_Keeping=0; 
		   
			        }
		       }  
             	}		
	      // ---------------- Process ---------	
		EXTI_ClearITPendingBit( EXTI_Line5 );
	}
	else
		shaker_continueCounter=0; 
}
Example #2
0
/*********************************************************\
* Initialize MMA865xQ
\*********************************************************/
void MMA865x_Init (void)
{
  byte n;
  /*
  **  Reset sensor, and wait for reboot to complete
  */
  IIC_RegWrite(SlaveAddressIIC, CTRL_REG2, RST_MASK);
  do {
    n = IIC_RegRead(SlaveAddressIIC, CTRL_REG2);
  } while (n & RST_MASK);
  /*
  **  Configure sensor for:
  **    - Sleep Mode Poll Rate of 50Hz (20ms)
  **    - System Output Data Rate of 200Hz (5ms)
  **    - Full Scale of +/-8g
  */
  IIC_RegWrite(SlaveAddressIIC, CTRL_REG1, ASLP_RATE_20MS + DATA_RATE_5MS);
  /*
  **  Configure sensor data for:
  **    - Full Scale of +/-8g
  **
  **  XYZ Data Event Flag Enable
  */
  IIC_RegWrite(SlaveAddressIIC, XYZ_DATA_CFG_REG, FULL_SCALE_2G);
  full_scale = FULL_SCALE_2G;
}
Example #3
0
/*********************************************************\
* Put MMA865xQ into Active Mode
\*********************************************************/
void MMA865x_Active (void)
{
  /*
  ** Set the Active bit in System Control 1 Register.
  */
  IIC_RegWrite(SlaveAddressIIC, CTRL_REG1, (IIC_RegRead(SlaveAddressIIC, CTRL_REG1) | ACTIVE_MASK));
}
Example #4
0
/*
读取
 */
void EXTI9_5_IRQHandler( void )
{
    uint8_t value1, value2, value3;
    if( EXTI_GetITStatus( EXTI_Line5 ) != RESET )
    {
        IIC_RegRead( MMA845X_ADDR, INT_SOURCE_REG, &value1 );
        IIC_RegRead( MMA845X_ADDR, PL_STATUS_REG, &value2 );
        IIC_RegRead( MMA845X_ADDR, PULSE_SRC_REG, &value3 );
        //rt_kprintf("\nINT=%02x %02x %02x\n",value1,value2,value3);
        //                                                          trigger  type    grade
        /*
                   Shake Trigger
        */
        //--------------Process  -----------
        if((Warn_Status[0] & 0x20) == 0x00) // 如果没报警那么就让他报警
        {
            shaker_continueCounter++;
            if(shaker_continueCounter > 2600)
            {
                shaker_continueCounter = 0;
                //----------------------------------------
                if(firstrun == 1)
                    firstrun = 0;    //上电 第一次触发不上报
                else
                {
                    Warn_Status[0] |= 0x20; //bit29
                    PositionSD_Enable();  // 使能发送
                    Current_UDP_sd = 1;
                    if(GB19056.workstate == 0)
                        rt_kprintf("\r\n  碰撞侧翻触发!\r\n");
                }
                //------------------------------------------
            }
        }
        // ---------------- Process ---------
        EXTI_ClearITPendingBit( EXTI_Line5 );
    }
    else
    {
        shaker_continueCounter = 0;
    }
}
Example #5
0
/*********************************************************\
* Put MMA865xQ into Standby Mode
\*********************************************************/
byte MMA865x_Standby (void)
{
  byte n;
  /*
  **  Read current value of System Control 1 Register.
  **  Put sensor into Standby Mode by clearing the Active bit.
  **  Return with previous value of System Control 1 Register.
  */
  n = IIC_RegRead(SlaveAddressIIC, CTRL_REG1);
  IIC_RegWrite(SlaveAddressIIC, CTRL_REG1, n & (~ACTIVE_MASK));
  return (n & ACTIVE_MASK);
}
Example #6
0
/*********************************************************\
* Put MPL3115A2 into Standby Mode
\*********************************************************/
byte MPL3115A2_Standby (void)
{
  byte n;  
  /*
  **  Read current value of System Control 1 Register.
  **  Put sensor into Standby Mode.
  **  Return with previous value of System Control 1 Register.
  */
  n = IIC_RegRead(SlaveAddressIIC, CTRL_REG1);
  IIC_RegWrite(SlaveAddressIIC, CTRL_REG1, n & STANDBY_SBYB_0);

  return(n);
}          
Example #7
0
/*********************************************************\
* Put MPL3115A2 into Active Mode
\*********************************************************/
void MPL3115A2_Active (void)
{
  IIC_RegWrite(SlaveAddressIIC, CTRL_REG1, (IIC_RegRead(SlaveAddressIIC, CTRL_REG1) | ACTIVE_MASK));
}