Exemple #1
0
/* Board Debug UART Initialisation function */
STATIC void Board_UART_Init(void)
{
	/* Enable the clock to the Switch Matrix */
	Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);

	/* Connect the U0_TXD_O and U0_RXD_I signals to port pins(P0.07, P0.18) */
	Chip_SWM_DisableFixedPin(SWM_FIXED_ADC0);
	Chip_SWM_DisableFixedPin(SWM_FIXED_ADC8);

	/* Enable UART Divider clock, divided by 1 */
	Chip_Clock_SetUARTClockDiv(1);

	/* Divided by 1 */
	if (DEBUG_UART == LPC_USART0) {

		Chip_SWM_MovablePinAssign(SWM_U0_TXD_O, 7);
		Chip_SWM_MovablePinAssign(SWM_U0_RXD_I, 18);
	} else if (DEBUG_UART == LPC_USART1) {
		Chip_SWM_MovablePinAssign(SWM_U1_TXD_O, 7);
		Chip_SWM_MovablePinAssign(SWM_U1_RXD_I, 18);
	} else {
		Chip_SWM_MovablePinAssign(SWM_U2_TXD_O, 7);
		Chip_SWM_MovablePinAssign(SWM_U2_RXD_I, 18);
	}

	/* Disable the clock to the Switch Matrix to save power */
	Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);
}
Exemple #2
0
/* Initializes pin muxing for SPI1 interface - note that SystemInit() may
   already setup your pin muxing at system startup */
static void Init_SPI_PinMux(void)
{
#if (defined(BOARD_NXP_LPCXPRESSO_812) || defined(BOARD_LPC812MAX))
	/* Enable the clock to the Switch Matrix */
	Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
	/*
	 * Initialize SSP0 pins connect
	 * SCK1: PINASSIGN4[31:24]: Select P0.12
	 * MOSI1: PINASSIGN5[7:0]: Select P0.14
	 * MISO1: PINASSIGN5[15:8] : Select P0.6
	 * SSEL1: PINASSIGN5[23:16]: Select P0.13
	 */
	Chip_SWM_DisableFixedPin(SWM_FIXED_VDDCMP);

	Chip_SWM_MovablePinAssign(SWM_SPI0_SCK_IO, 12);
	Chip_SWM_MovablePinAssign(SWM_SPI1_SCK_IO, 7);

	Chip_SWM_MovablePinAssign(SWM_SPI0_MOSI_IO, 14);
	Chip_SWM_MovablePinAssign(SWM_SPI1_MOSI_IO, 9);
#if defined(BOARD_LPC812MAX)
	Chip_SWM_MovablePinAssign(SWM_SPI0_MISO_IO, 15);
	Chip_SWM_MovablePinAssign(SWM_SPI1_MISO_IO, 0);
#else
	Chip_SWM_MovablePinAssign(SWM_SPI0_MISO_IO, 6);
	Chip_SWM_MovablePinAssign(SWM_SPI1_MISO_IO, 1);
#endif
	Chip_SWM_DisableFixedPin(SWM_FIXED_ACMP_I1);
	Chip_SWM_MovablePinAssign(SWM_SPI0_SSEL_IO, 13);
	Chip_SWM_MovablePinAssign(SWM_SPI1_SSEL_IO, 10);

	/* Disable the clock to the Switch Matrix to save power */
	Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);
#elif defined(BOARD_NXP_LPCXPRESSO_824)
	/* Enable the clock to the Switch Matrix */
	Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);

	/* Master Pins for SPI0 */
	Chip_SWM_MovablePinAssign(SWM_SPI0_SSEL0_IO, 15);
	Chip_SWM_MovablePinAssign(SWM_SPI0_SCK_IO, 24);
	Chip_SWM_MovablePinAssign(SWM_SPI0_MISO_IO, 25);
	Chip_SWM_MovablePinAssign(SWM_SPI0_MOSI_IO, 26);

	/* Slave Pins for SPI1 */
	Chip_SWM_MovablePinAssign(SWM_SPI1_SSEL0_IO, 17);
	Chip_SWM_MovablePinAssign(SWM_SPI1_SCK_IO, 18);
	Chip_SWM_MovablePinAssign(SWM_SPI1_MISO_IO, 28);
	Chip_SWM_MovablePinAssign(SWM_SPI1_MOSI_IO, 16);

	/* Disable the clock to the Switch Matrix to save power */
	Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);
#else
	/* Configure your own SPI pin muxing here if needed */
#warning "No SPI pin muxing defined"
#endif
}
Exemple #3
0
/* Initialize the LEDs on the NXP_Quick_Jack board */
void Board_LED_Init(void)
{
	uint32_t i;
	
	Chip_SWM_DisableFixedPin(SWM_FIXED_XTALIN);			//pin 8
	Chip_SWM_DisableFixedPin(SWM_FIXED_XTALOUT);		//pin 9

	//heart beat on pin 13
	Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, LEDHEARTBEAT);
	Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, LEDHEARTBEAT, true);

}
Exemple #4
0
int __attribute__ ((noinline)) main(void)
{

  /* set systick and start systick interrupt */
  SysTick_Config(SYS_CORE_CLOCK/1000UL*(unsigned long)SYS_TICK_PERIOD_IN_MS);
  
  /* turn on GPIO */
  Chip_GPIO_Init(LPC_GPIO_PORT);

  /* disable SWCLK and SWDIO, after reset, boot code may activate this */
  Chip_SWM_DisableFixedPin(2);
  Chip_SWM_DisableFixedPin(3);
  
  /* turn on IOCON */
  Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON);
  
  /* turn on switch matrix */
  Chip_SWM_Init();
  
  /* activate analog comperator */
  Chip_ACMP_Init(LPC_CMP);

  /* let LED on pin 4 of the DIP8 blink */
  Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, 2);  
  
  for(;;)
  {
    Chip_GPIO_SetPinOutHigh(LPC_GPIO_PORT, 0, 2); 	
    delay_micro_seconds(500000UL);
    Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 0, 2);    
    delay_micro_seconds(500000UL);
  }

  
  /* enter sleep mode: Reduce from 1.4mA to 0.8mA with 12MHz */  
  while (1)
  {
    SCB->SCR |= (1UL << SCB_SCR_SLEEPONEXIT_Pos);		/* enter sleep mode after interrupt */ 
    Chip_PMU_SleepState(LPC_PMU);						/* enter sleep mode now */
  }
}
Exemple #5
0
/**
 * Configure the pinmuxing for the MultiSensor board.
 *
 * only the special functions are set here, default the pins are gpio.
 */
void PINMUX_Init()
{
	/* Enable the clock to the Switch Matrix */
	Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);

	/* DISconnect the XTALIN and XTALOUT signals to port pins(P0.8, P0.9), as these will be used for gpio purposes */
	/* these are fixed location pins */
	Chip_SWM_FixedPinEnable(SWM_FIXED_XTALIN, false);
	Chip_SWM_FixedPinEnable(SWM_FIXED_XTALOUT, false);

	/* connect the fixed reset_n pin to P0.5 */
	Chip_SWM_EnableFixedPin(SWM_FIXED_RST);

	/* Connect the I2C_SDA0 and I2C_SCL0 signals to port pins(P0.10, P0.11) */
	/* these are fixed location pins */
	Chip_SWM_EnableFixedPin(SWM_FIXED_I2C0_SDA);
	Chip_SWM_EnableFixedPin(SWM_FIXED_I2C0_SCL);

	/* Connect the ADC0 (P0.7) and ADC1 (P0.6) */
	/* these are fixed location pins */
	Chip_SWM_EnableFixedPin(SWM_FIXED_ADC0);
	Chip_SWM_EnableFixedPin(SWM_FIXED_ADC1);

	/* Connect the USART0 TX & RX signals to port pins(P0.16, P0.26) */
	/* these are movable location pins */
	Chip_SWM_MovablePinAssign(SWM_U0_TXD_O, 16);
	Chip_SWM_MovablePinAssign(SWM_U0_RXD_I, 26);

	/* Connect the USART1 RX signal to port pins(P0.25) */
	/* these are movable location pins */
	Chip_SWM_MovablePinAssign(SWM_U1_RXD_I, 25);


	/* Connect the SCT OUTPUT 1,2,3 (PWM : RGB)  signal to port pin(P0.1, P0.9, P0.8) --> this is the RGB led*/
	/* these are movable location pins */
	Chip_SWM_MovablePinAssign(SWM_SCT_OUT1_O, 1);
	Chip_SWM_MovablePinAssign(SWM_SCT_OUT2_O, 9);
	Chip_SWM_MovablePinAssign(SWM_SCT_OUT3_O, 8);

	/* make sure to disable fixed pin functionality for HUMIDITY dht22 data pin */
	Chip_SWM_DisableFixedPin(SWM_FIXED_ADC10);
	//Chip_SWM_MovablePinAssign(SWM_SCT_IN1_I, 13);


	/* Disable the clock to the Switch Matrix to save power */
	Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);
}
Exemple #6
0
void SensorSwitch_Init(void){
	Chip_SWM_DisableFixedPin(SWM_FIXED_XTALOUT);
	Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, DUALSWTCHINPUT);
}
Exemple #7
0
uint32_t SPI_ReadCh0(void){

	/* Disable clocks to SWM and IOCON to save power */
	Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
	Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON);

	// initialize pins
	Chip_SWM_DisableFixedPin(SWM_FIXED_XTALIN);
	Chip_SWM_MovablePinAssign(SWM_SPI1_SCK_IO, 8);
	Chip_SWM_MovablePinAssign(SWM_SPI1_MOSI_IO, 17);
	Chip_SWM_MovablePinAssign(SWM_SPI1_MISO_IO, 16);
	//TODO: do we need to set slave select if it's tied to ground?
	Chip_SWM_MovablePinAssign(SWM_SPI1_SSEL_IO, 4);


	ConfigStruct.Mode = SPI_MODE_MASTER;
	ConfigStruct.ClkDiv = Chip_SPI_CalClkRateDivider(LPC_SPI1, 100000);
	ConfigStruct.ClockMode = SPI_CLOCK_CPHA0_CPOL0;
	ConfigStruct.DataOrder = SPI_DATA_MSB_FIRST;		//enable MSB first option
	ConfigStruct.SSELPol = SPI_CFG_SPOL_LO;
	Chip_SPI_Init(LPC_SPI1, &ConfigStruct);


	DelayConfigStruct.FrameDelay = 0;
	DelayConfigStruct.PostDelay = 0;
	DelayConfigStruct.PreDelay = 0;
	DelayConfigStruct.TransferDelay = 0;
	Chip_SPI_DelayConfig(LPC_SPI1, &DelayConfigStruct);

	Chip_SPI_Enable(LPC_SPI1);


	//Chip_SPI_EnableLoopBack(LPC_SPI1);

	// init transmit buffer
	TxBuf[0] = 0x68;
	TxBuf[1] = 0x00;

	XfSetup.Length = BUFFER_SIZE;
	XfSetup.pTx = TxBuf;
	XfSetup.RxCnt = XfSetup.TxCnt = 0;
	XfSetup.DataSize = 8;
	XfSetup.pRx = RxBuf;


	Chip_SPI_RWFrames_Blocking(LPC_SPI1, &XfSetup);

	uint16_t value = ((RxBuf[0] & 0x03) << 8) + (RxBuf[1] & 0xFF);


	//Chip_SPI_DisableLoopBack(LPC_SPI1);

	/* DeInitialize SPI peripheral */
	Chip_SPI_DeInit(LPC_SPI1);

	/* Disable clocks to SWM and IOCON to save power */
	Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);
	Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_IOCON);

	return value;
}
Exemple #8
0
int32_t main(void) {

  int32_t i,cnt=0;
  uint8_t RC5_System_prev=0;
  uint8_t RC5_Command_prev=0;
  CHIP_PMU_MCUPOWER_T mcupower=PMU_MCU_SLEEP;

  SystemCoreClockUpdate();

// init GPIO
  Chip_GPIO_Init(LPC_GPIO_PORT);
  Chip_SYSCTL_PeriphReset(RESET_GPIO);

// init SPI0 at SystemCoreClock speed
  Chip_SPI_Init(LPC_SPI0);
  Chip_SPI_ConfigureSPI(LPC_SPI0,SPI_MODE_MASTER|
                                 SPI_CLOCK_CPHA0_CPOL0|
                                 SPI_DATA_MSB_FIRST|
                                 SPI_SSEL_ACTIVE_LO);
  LPC_SPI0->DIV=0;
  Chip_SPI_Enable(LPC_SPI0);

// init MRT
  Chip_MRT_Init();

// init SWM
  Chip_SWM_Init();
  Chip_SWM_DisableFixedPin(SWM_FIXED_SWCLK);//PIO0_3
  Chip_SWM_DisableFixedPin(SWM_FIXED_SWDIO);//PIO0_2
  Chip_SWM_DisableFixedPin(SWM_FIXED_ACMP_I2);//PIO0_1
  Chip_SWM_DisableFixedPin(SWM_FIXED_ACMP_I1);//PIO0_0
  Chip_SWM_MovablePinAssign(SWM_SPI0_SCK_IO,CLK_PIN);
  Chip_SWM_MovablePinAssign(SWM_SPI0_MOSI_IO,MOSI_PIN);
  Chip_SWM_MovablePinAssign(SWM_CTIN_0_I,IR_PIN);
  Chip_SWM_Deinit();

// init onboard LED
  Chip_GPIO_SetPinState(LPC_GPIO_PORT,0,LED_PIN,true);
  Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT,0,LED_PIN);

// init LCD reset pin
  Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT,0,RESET_PIN);

// init LCD
  LCDInit();
  LCDClearScreenBlack();

// init SCT
  Chip_SCT_Init(LPC_SCT);
  // set prescaler, SCT clock = 1 MHz, clear counter
  LPC_SCT->CTRL_L |= SCT_CTRL_PRE_L(SystemCoreClock/1000000-1) | SCT_CTRL_CLRCTR_L;
  sct_fsm_init();
  NVIC_EnableIRQ(SCT_IRQn);

// init PIO0_3 pin interrupt for wakeup from sleep mode
  Chip_SYSCTL_SetPinInterrupt(IR_IRQ,IR_PIN);
  Chip_PININT_EnableIntLow(LPC_PININT, PININTCH(IR_IRQ));
  NVIC_EnableIRQ(PININT3_IRQn);
  Chip_SYSCTL_EnablePINTWakeup(IR_IRQ);

// set sleep options
  Chip_SYSCTL_SetDeepSleepPD(SYSCTL_DEEPSLP_BOD_PD | SYSCTL_DEEPSLP_WDTOSC_PD);
  Chip_SYSCTL_SetWakeup(~(SYSCTL_SLPWAKE_IRCOUT_PD | SYSCTL_SLPWAKE_IRC_PD | SYSCTL_SLPWAKE_FLASH_PD ));

  LCDPutStr("kbiva.wordpress.com", MAX_X / 2 + 50, 10, WHITE, BLACK);
  LCDPutStr("RC5 Decoder", MAX_X / 2 + 35, 35, WHITE, BLACK);
  LCDPutStr("Frame:", MAX_X / 2 + 20, 1, WHITE, BLACK);
  LCDPutStr("System:", MAX_X / 2 + 5 , 1, WHITE, BLACK);
  LCDPutStr("Cmd:", MAX_X / 2 - 10, 1, WHITE, BLACK);
  LCDPutStr("Toggle:", MAX_X / 2 - 25, 1, WHITE, BLACK);
  LCDPutStr("Count:", MAX_X / 2 - 40, 1, WHITE, BLACK);

  while (1) {

// put chip to sleep
    switch(mcupower) {
      case PMU_MCU_SLEEP:
      default:
        LCDPutStr("SLEEP     ", MAX_X / 2 - 60, 10, WHITE, BLACK);
        Chip_PMU_SleepState(LPC_PMU);
        break;
      case PMU_MCU_DEEP_SLEEP:
        LCDPutStr("DEEP-SLEEP", MAX_X / 2 - 60, 10, WHITE, BLACK);
        Chip_PMU_DeepSleepState(LPC_PMU);
        break;
      case PMU_MCU_POWER_DOWN:
        LCDPutStr("POWER-DOWN", MAX_X / 2 - 60, 10, WHITE, BLACK);
        Chip_PMU_PowerDownState(LPC_PMU);
        break;
    }

// start MRT timer channel 0
    Chip_MRT_SetInterval(LPC_MRT_CH0, SystemCoreClock | MRT_INTVAL_LOAD);
    Chip_MRT_SetMode(LPC_MRT_CH0,MRT_MODE_ONESHOT);
    Chip_MRT_SetEnabled(LPC_MRT_CH0);

// turn on onboard LED
    Chip_GPIO_SetPinState(LPC_GPIO_PORT,0,LED_PIN,false);

// start SCT
    LPC_SCT->CTRL_L &= ~SCT_CTRL_HALT_L;

// wait for timeout
    while(!RC5_timeout)
    {};

// stop SCT
    LPC_SCT->CTRL_L |= SCT_CTRL_HALT_L;

    if (RC5_flag) {
      // if frame received, output information on LCD

      if((RC5_System != RC5_System_prev) || (RC5_Command != RC5_Command_prev)) {
        cnt = 1;
      }
      else {
        cnt++;
      }

      for (i = 3; i >= 0; i--){

        LCDPutChar(ascii[(RC5_Frame >> (i * 4)) & 0x0F],MAX_X / 2 + 20,80+(3-i)*7,WHITE, BLACK);
        if(i < 2) {
          if((RC5_System!=RC5_System_prev) || (RC5_Command!=RC5_Command_prev)){
            LCDPutChar(ascii[(RC5_System >> (i * 4)) & 0x0F],MAX_X / 2 + 5,66+(3-i)*7,WHITE, BLACK);
            LCDPutChar(ascii[(RC5_Command >> (i * 4)) & 0x0F],MAX_X / 2 - 10,66+(3-i)*7,WHITE, BLACK);
          }
        }
        LCDPutChar(ascii[(cnt >> (i * 4)) & 0x0F],MAX_X / 2 - 40,80+(3-i)*7,WHITE, BLACK);
      }

      LCDPutStr(RC5_Toggle ? "ON ":"OFF", MAX_X / 2 - 25, 80, WHITE, BLACK);

      switch(RC5_Command) {
        case 0x50:
          mcupower = PMU_MCU_SLEEP;
        break;
        case 0x55:
          if(RC5_Toggle){
            spi0Transfer(SLEEPOUT);
            spi0Transfer(DISPON);
          }
          else {
            spi0Transfer(DISPOFF);
            spi0Transfer(SLEEPIN);
          }
        break;
        case 0x56:
          mcupower = PMU_MCU_DEEP_SLEEP;
        break;
        case 0x6B:
          mcupower = PMU_MCU_POWER_DOWN;
        break;
      }

      RC5_System_prev = RC5_System;
      RC5_Command_prev = RC5_Command;
    }
// turn off onboard LED
    Chip_GPIO_SetPinState(LPC_GPIO_PORT,0,LED_PIN,true);
// clear flags
    RC5_flag = 0;
    RC5_timeout = 0;
  }