void MEMSInit() { I2CInit(); writeRegister(MPU6050_ADDRESS_AD0_LOW, MPU6050_RA_SMPLRT_DIV, MPU6050_SMPLRT_DIV); writeRegister(MPU6050_ADDRESS_AD0_LOW, MPU6050_RA_GYRO_CONFIG, MPU6050_FS_SEL0); writeRegister(MPU6050_ADDRESS_AD0_LOW, MPU6050_RA_ACCEL_CONFIG, MPU6050_AFS_SEL0); writeRegister(MPU6050_ADDRESS_AD0_LOW, MPU6050_RA_INT_PIN_CFG, MPU6050_INT_LEVEL_LOW|MPU6050_LATCH_INT_ENABLE|MPU6050_INT_RD_SET); writeRegister(MPU6050_ADDRESS_AD0_LOW, MPU6050_RA_INT_EN, MPU6050_DATA_RDY_EN); writeRegister(MPU6050_ADDRESS_AD0_LOW, MPU6050_RA_PWR_MGMT_1, MPU6050_WAKE); /*Interrupt triggers when touched to ground*/ //Therefore it is a idle high, interrupt triggers when pin is low // use port0_5 as input event, interrupt test. GPIOSetDir(PORT0, 21, INPUT ); NVIC_SetPriority(FLEX_INT0_IRQn, GPIOINT0PRIORITY); // port2_1, single edge trigger, active high. //channel #, port #, bit position, sense, event(polarity) GPIOSetFlexInterrupt(CHANNEL0, PORT0, 21, 0, 0 ); }
/***************************************************************************** ** Function name: PMU_Init ** ** Descriptions: Initialize PMU and setup wakeup source. ** For Sleep and deepsleep, any of the I/O pins can be ** used as the wakeup source. ** For Deep Powerdown, only pin P1.4 can be used as ** wakeup source from deep powerdown. ** ** parameters: None ** Returned value: None ** *****************************************************************************/ void PMU_Init( void ) { #if Gint_Enable uint32_t bitPattern[2]; uint32_t eventPattern[2]; #endif /* Enable all clocks, even those turned off at power up. */ LPC_SYSCON->PDRUNCFG &= ~(WDT_OSC_PD | ADC_PD); #if 0 /* FLEX_INT0 source */ GPIOSetFlexInterrupt( CHANNEL0, PORT1, 1, 0, 0 ); /* FLEX_INT0 as wakeup source */ LPC_SYSCON->STARTERP0 = 0x1<<0; #endif #if 0 /* FLEX_INT1 source */ GPIOSetFlexInterrupt( CHANNEL1, PORT1, 2, 0, 0 ); /* FLEX_INT1 as wakeup source */ LPC_SYSCON->STARTERP0 = 0x1<<1; #endif #if 0 /* FLEX_INT2 source */ GPIOSetFlexInterrupt( CHANNEL2, PORT1, 3, 0, 0 ); /* FLEX_INT2 as wakeup source */ LPC_SYSCON->STARTERP0 = 0x1<<2; #endif #if 0 /* FLEX_INT3 source */ GPIOSetFlexInterrupt( CHANNEL3, PORT1, 4, 0, 0 ); /* FLEX_INT3 as wakeup source */ LPC_SYSCON->STARTERP0 = 0x1<<3; #endif #if 0 /* FLEX_INT4 source */ GPIOSetFlexInterrupt( CHANNEL4, PORT0, 2, 0, 0 ); /* FLEX_INT4 as wakeup source */ LPC_SYSCON->STARTERP0 = 0x1<<4; #endif #if 0 /* FLEX_INT5 source */ GPIOSetFlexInterrupt( CHANNEL5, PORT0, 3, 0, 0 ); /* FLEX_INT5 as wakeup source */ LPC_SYSCON->STARTERP0 = 0x1<<5; #endif #if 0 /* FLEX_INT6 source */ GPIOSetFlexInterrupt( CHANNEL6, PORT0, 4, 0, 0 ); /* FLEX_INT6 as wakeup source */ LPC_SYSCON->STARTERP0 = 0x1<<6; #endif #if 1 /* FLEX_INT7 source */ /* PIO 0_17 set as wake-up pin */ GPIOSetFlexInterrupt( CHANNEL7, PORT0, 17, 0, 0 ); /* FLEX_INT7 as wakeup source */ LPC_SYSCON->STARTERP0 = 0x1<<7; #endif #if Gint_Enable #if 0 bitPattern[0] = 0x00000020; /* PIO0_5 enabled */ bitPattern[1] = 0x00000004; /* PIO1_2 enabled */ eventPattern[0] = 0x00000020; /* PIO0_5 rising edge */ eventPattern[1] = 0x00000000; /* PIO1_2 falling edge */ /* GINT0_INT sources OR together */ GPIOSetGroupedInterrupt( GROUP0, &bitPattern[0], 0, 0, &eventPattern[0] ); /* GINT0_INT as wakeup source */ LPC_SYSCON->STARTERP1 = 0x1<<20; #endif #if 0 bitPattern[0] = 0x00000020; /* PIO0_5 enabled */ bitPattern[1] = 0x00000004; /* PIO1_2 enabled */ eventPattern[0] = 0x00000020; /* PIO0_5 rising edge */ eventPattern[1] = 0x00000000; /* PIO1_2 falling edge */ /* GINT0_INT sources AND together */ GPIOSetGroupedInterrupt( GROUP0, &bitPattern[0], 1, 0, &eventPattern[0] ); /* GINT0_INT as wakeup source */ LPC_SYSCON->STARTERP1 = 0x1<<20; #endif #if 0 bitPattern[0] = 0x00000020; /* PIO0_5 enabled */ bitPattern[1] = 0x00000004; /* PIO1_2 enabled */ eventPattern[0] = 0x00000000; /* PIO0_5 falling edge */ eventPattern[1] = 0x00000004; /* PIO1_2 rising edge */ /* GINT0_INT sources OR together */ GPIOSetGroupedInterrupt( GROUP1, &bitPattern[0], 0, 0, &eventPattern[0] ); /* GINT0_INT as wakeup source */ LPC_SYSCON->STARTERP1 = 0x1<<21; #endif #if 0 bitPattern[0] = 0x00000020; /* PIO0_5 enabled */ bitPattern[1] = 0x00000004; /* PIO1_2 enabled */ eventPattern[0] = 0x00000000; /* PIO0_5 falling edge */ eventPattern[1] = 0x00000004; /* PIO1_2 rising edge */ /* GINT0_INT sources OR together */ GPIOSetGroupedInterrupt( GROUP1, &bitPattern[0], 1, 0, &eventPattern[0] ); /* GINT0_INT as wakeup source */ LPC_SYSCON->STARTERP1 = 0x1<<21; #endif #endif return; }