Chip_IOCON_PinMux(LPC_IOCON, IOCON_PIO1_5, IOCON_MODE_INACT, IOCON_FUNC2); Chip_TIMER_Init(LPC_TIMER32_0); Chip_TIMER_TIMER_SetCountClockSrc(LPC_TIMER32_0, TIMER_CAPSRC_RISING_PCLK, 0); Chip_TIMER_PrescaleSet(LPC_TIMER32_0, 1);//1=> every 2 PCLK clocks Chip_TIMER_CaptureRisingEdgeEnable(LPC_TIMER32_0, 0); Chip_TIMER_CaptureFallingEdgeEnable(LPC_TIMER32_0, 0); Chip_TIMER_CaptureEnableInt(LPC_TIMER32_0, 0); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(TIMER_32_0_IRQn, 1); NVIC_EnableIRQ(TIMER_32_0_IRQn); |
Chip_IOCON_PinMux(LPC_IOCON, IOCON_PIO1_0, IOCON_MODE_PULLUP |[color=#f00] IOCON_DIGMODE_EN[/color], IOCON_FUNC3); |
Board_LED_Toggle(0); |
#define CAPDATA_SIZE256 static uint32_t capdata[CAPDATA_SIZE]; static int capdataidx = 0; void TIMER32_0_IRQHandler(void) { __disable_irq(); if(capdataidx < CAPDATA_SIZE) { capdata[capdataidx++] = Chip_TIMER_ReadCount(LPC_TIMER32_0); } __enable_irq(); } void cap_init(void) { capdataidx = 0; Chip_IOCON_PinMux(LPC_IOCON, IOCON_PIO1_5, IOCON_MODE_INACT, IOCON_FUNC2); Chip_TIMER_Init(LPC_TIMER32_0); Chip_TIMER_Disable(LPC_TIMER32_0); Chip_TIMER_TIMER_SetCountClockSrc(LPC_TIMER32_0, TIMER_CAPSRC_RISING_PCLK, 0); Chip_TIMER_PrescaleSet(LPC_TIMER32_0, 1);//1=> every 2 PCLK clocks Chip_TIMER_CaptureRisingEdgeEnable(LPC_TIMER32_0, 0); Chip_TIMER_CaptureFallingEdgeEnable(LPC_TIMER32_0, 0); Chip_TIMER_CaptureEnableInt(LPC_TIMER32_0, 0); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(TIMER_32_0_IRQn, 1); NVIC_EnableIRQ(TIMER_32_0_IRQn); Chip_TIMER_Reset(LPC_TIMER32_0); Chip_TIMER_Enable(LPC_TIMER32_0); } |
SystemCoreClockUpdate(); Board_Init(); Board_LED_Set(0, false); cap_init(); UART_Init(); CAN_Init(); UART_Start(); while (1) { } /* DeInitialize UART0 peripheral */ NVIC_DisableIRQ(UART0_IRQn); Chip_UART_DeInit(LPC_USART); return 1; } |
void UART_Init(void) { Init_UART_PinMux(); /* Setup UART for 115.2K8N1 */ Chip_UART_Init(LPC_USART); Chip_UART_SetBaud(LPC_USART, 1500000); Chip_UART_ConfigData(LPC_USART, (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT)); Chip_UART_SetupFIFOS(LPC_USART, (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV2)); Chip_UART_TXEnable(LPC_USART); /* Before using the ring buffers, initialize them using the ring buffer init function */ RingBuffer_Init(&rxring, rxbuff, 1, UART_RRB_SIZE); RingBuffer_Init(&txring, txbuff, 1, UART_SRB_SIZE); } void UART_Start(void) { /* Enable receive data and line status interrupt */ Chip_UART_IntEnable(LPC_USART, (UART_IER_RBRINT | UART_IER_RLSINT)); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(UART0_IRQn, 1); NVIC_EnableIRQ(UART0_IRQn); } |