/*connect the I2C SCL and SDA sigals to port pins(P0.10-P0.11)*/ regVal = LPC_SWM ->PINASSIGN7 & ~(0xFFUL << 24); LPC_SWM ->PINASSIGN7 = regVal | (10 << 24); /* P0.10 is I2C SDA, ASSIGN0(31:24) */ regVal = LPC_SWM ->PINASSIGN8 & ~(0xFF << 0); LPC_SWM ->PINASSIGN8 = regVal | (11 << 0); /* P0.11 is I2C SCL. ASSIGN0(7:0) */ LPC_SYSCON ->CLKOUTDIV = 120; /* CLKOUT = 60E6 / 120 = 500 kHz */ LPC_SYSCON ->CLKOUTSEL = 0x03; /* CLKOUT = Main clock */ LPC_SYSCON ->CLKOUTUEN = 0x01; /* Update CLKOUT Source */ LPC_GPIO_PORT ->DIR0 |= (1 << 5); regVal = LPC_SWM ->PINASSIGN8 & ~(0xFF << 16); LPC_SWM ->PINASSIGN8 = regVal | (0x0F << 16); /* P0.15 is CLKOUT. ASSIGN8(23:16) */ LPC_GPIO_PORT ->DIR0 |= (1 << 7); SysTick_Config(SystemCoreClock / 2); /* Enable I2C clock */ LPC_SYSCON ->SYSAHBCLKCTRL |= (1 << 5); /* Toggle peripheral reset control to I2C, a "1" bring it out of reset. */ LPC_SYSCON ->PRESETCTRL &= ~(0x1 << 6); LPC_SYSCON ->PRESETCTRL |= (0x1 << 6); I2C_SlvInit(LPC_I2C, SLAVE_ADDR, CFG_SLVENA, I2C_FMODE_PRE_DIV); /* Ready to receive the slave address, interrupt(SLAVE ADDR STATE) if match occurs. */ LPC_I2C ->SLVCTL = CTL_SLVCONTINUE; LPC_I2C ->INTENSET = STAT_SLVPEND; /* Enable wake from power down using I2C */ LPC_SYSCON ->STARTERP1 |= (1 << 8); |
/***************************************************************************** ** Function name:PMU_Sleep ** ** Descriptions:Put some of the peripheral in sleep mode. ** ** parameters:SleepMode: 2 is power down, 1 is deep sleep, 0 is sleep, Sleep peripheral module(s) ** Returned value:None ** *****************************************************************************/ void PMU_Sleep( uint32_t SleepMode, uint32_t SleepCtrl ) { LPC_SYSCON->PDAWAKECFG = LPC_SYSCON->PDRUNCFG; LPC_SYSCON->PDSLEEPCFG = SleepCtrl; /* If normal sleep, not deep sleep, don't do anything to SCR reg. */ switch ( SleepMode ) { case MCU_POWER_DOWN: SCB->SCR |= NVIC_LP_SLEEPDEEP; #if __WKT LPC_PMU->DPDCTRL |= (0x1 << 2); init_wkt(1, 10000 * 10); #endif #if 1 LPC_PMU->PCON = 0x2; #else LPC_SYSCON->PDSLEEPCFG &= 0xFDFF; #endif break; case MCU_DEEP_SLEEP: SCB->SCR |= NVIC_LP_SLEEPDEEP; #if __WKT LPC_PMU->DPDCTRL |= (0x1 << 2); init_wkt(1, 10000 * 10); #endif #if 1 LPC_PMU->PCON = 0x1; #else LPC_SYSCON->PDSLEEPCFG &= 0xEFF9; #endif break; case MCU_SLEEP: default: break; } __WFI(); return; } |