void UART1_IRQHandler() { uint32_t interruptSource = UART_GetIntId(UART1_DEVICE) & UART_IIR_INTID_MASK; if(interruptSource == 0) { // Check Modem status uint8_t modemStatus = UART_FullModemGetStatus(LPC_UART1); // Check CTS status change flag if (modemStatus & UART1_MODEM_STAT_DELTA_CTS) { // if CTS status is active, continue to send data if (modemStatus & UART1_MODEM_STAT_CTS) { CTS_STATE = ACTIVE; UART_TxCmd(UART1_DEVICE, ENABLE); } else { // Otherwise, Stop current transmission immediately CTS_STATE = INACTIVE; UART_TxCmd(UART1_DEVICE, DISABLE); } } } switch(interruptSource) { case UART_IIR_INTID_RDA: case UART_IIR_INTID_CTI: handleReceiveInterrupt(); break; case UART_IIR_INTID_THRE: handleTransmitInterrupt(); break; } }
/*********************************************************************//** * @brief UART1 interrupt handler sub-routine * @param[in] None * @return None **********************************************************************/ void UART1_IRQHandler(void) { uint8_t modemsts; uint32_t intsrc, tmp, tmp1; /* Determine the interrupt source */ intsrc = UART_GetIntId((LPC_UART_TypeDef *)LPC_UART1); tmp = intsrc & UART_IIR_INTID_MASK; /* * In case of using UART1 with full modem, * interrupt ID = 0 that means modem status interrupt has been detected */ if (tmp == 0){ // Check Modem status modemsts = UART_FullModemGetStatus(LPC_UART1); #if (AUTO_RTS_CTS_USE == 0) // Check CTS status change flag if (modemsts & UART1_MODEM_STAT_DELTA_CTS) { // if CTS status is active, continue to send data if (modemsts & UART1_MODEM_STAT_CTS) { // Re-Enable Tx UART_TxCmd((LPC_UART_TypeDef *)LPC_UART1, ENABLE); } // Otherwise, Stop current transmission immediately else{ // Disable Tx UART_TxCmd((LPC_UART_TypeDef *)LPC_UART1, DISABLE); } } #endif } // Receive Line Status if (tmp == UART_IIR_INTID_RLS){ // Check line status tmp1 = UART_GetLineStatus((LPC_UART_TypeDef *)LPC_UART1); // Mask out the Receive Ready and Transmit Holding empty status tmp1 &= (UART_LSR_OE | UART_LSR_PE | UART_LSR_FE \ | UART_LSR_BI | UART_LSR_RXFE); // If any error exist if (tmp1) { UART1_IntErr(tmp1); } } // Receive Data Available or Character time-out if ((tmp == UART_IIR_INTID_RDA) || (tmp == UART_IIR_INTID_CTI)){ UART1_IntReceive(); } // Transmit Holding Empty if (tmp == UART_IIR_INTID_THRE){ UART1_IntTransmit(); } }
void xl_UART_Config(unsigned char port) { UART_CFG_Type UARTConfigStruct; UART_FIFO_CFG_Type UARTFIFOConfigStruct; UART_ConfigStructInit(&UARTConfigStruct); UART_FIFOConfigStructInit(&UARTFIFOConfigStruct); switch(port) { case 0: PINSEL_ConfigPin(0,2,1); PINSEL_ConfigPin(0,3,1); UARTConfigStruct.Baud_rate = 115200; UART_Init( (UART_ID_Type)port, &UARTConfigStruct ); UART_FIFOConfig( (UART_ID_Type)port, &UARTFIFOConfigStruct ); UART_TxCmd( (UART_ID_Type)port, ENABLE ); UART_IntConfig(UART_0, UART_INTCFG_RBR, ENABLE); UART_IntConfig(UART_0, UART_INTCFG_RLS, ENABLE); NVIC_SetPriority(UART0_IRQn, ((0x02<<3)|0x02)); NVIC_EnableIRQ(UART0_IRQn); break; case 2: PINSEL_ConfigPin(0,10,1); PINSEL_ConfigPin(0,11,1); /** */ PINSEL_ConfigPin(1, 19, 6); UARTConfigStruct.Baud_rate = 9600; UART_Init( (UART_ID_Type)port, &UARTConfigStruct ); LPC_UART2->RS485CTRL = 0x31; LPC_UART2->RS485DLY = 0x10; UART_FIFOConfig( (UART_ID_Type)port, &UARTFIFOConfigStruct ); UART_TxCmd( (UART_ID_Type)port, ENABLE ); UART_IntConfig(UART_2, UART_INTCFG_RBR, ENABLE); UART_IntConfig(UART_2, UART_INTCFG_RLS, ENABLE); // NVIC_SetPriority(UART2_IRQn, ((0x02<<3)|0x03)); NVIC_DisableIRQ(UART2_IRQn); break; default: break; } }
void board_init(void) { SystemInit(); CGU_Init(); SysTick_Config( CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE)/CFG_TICKS_PER_SECOND ); /* 1 ms Timer */ //------------- USB Bus power HOST ONLY-------------// scu_pinmux(0x1, 7, MD_PUP | MD_EZI, FUNC4); // P1_7 USB0_PWR_EN, USB0 VBus function Xplorer scu_pinmux(0x2, 6, MD_PUP | MD_EZI, FUNC4); // P2_6 is configured as GPIO5[6] for USB1_PWR_EN GPIO_SetDir (5, BIT_(6), 1); // GPIO5[6] is output GPIO_SetValue (5, BIT_(6)); // GPIO5[6] output high // Leds Init for (uint8_t i=0; i<BOARD_MAX_LEDS; i++) { scu_pinmux(leds[i].port, leds[i].pin, MD_PUP|MD_EZI|MD_ZI, FUNC0); GPIO_SetDir(leds[i].port, BIT_(leds[i].pin), 1); // output } #if CFG_UART_ENABLE //------------- UART init -------------// UART_CFG_Type UARTConfigStruct; scu_pinmux(0x6 ,4, MD_PDN|MD_EZI, FUNC2); // UART0_TXD scu_pinmux(0x6 ,5, MD_PDN|MD_EZI, FUNC2); // UART0_RXD UART_ConfigStructInit(&UARTConfigStruct); // default: baud = 9600, 8 bit data, 1 stop bit, no parity UARTConfigStruct.Baud_rate = CFG_UART_BAUDRATE; // Re-configure baudrate UART_Init((LPC_USARTn_Type*) LPC_USART0, &UARTConfigStruct); // Initialize UART port UART_TxCmd((LPC_USARTn_Type*) LPC_USART0, ENABLE); // Enable UART #endif }
/* Desc:Configures the PINSEL data structure to setup pin P0.2 for use with the I2C bus and enables it */ void setupUART(){ //UART works with 4 main steps PINSEL_CFG_Type PinCfg; //Configure Pin select register UART_CFG_Type UARTConfigStruct; //Configure the UART Register UART_FIFO_CFG_Type FifoCfg; //Configure the UART FIFO Register //Init UART PinCfg.Funcnum = 1; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Portnum = 0; PinCfg.Pinnum = 2; PINSEL_ConfigPin(&PinCfg); UART_ConfigStructInit(&UARTConfigStruct); UART_Init((LPC_UART_TypeDef *)LPC_UART0, &UARTConfigStruct); UART_FIFOConfigStructInit(&FifoCfg); UART_FIFOConfig((LPC_UART_TypeDef *) LPC_UART0, &FifoCfg); //Enable UART Transmit UART_TxCmd((LPC_UART_TypeDef *)LPC_UART0, ENABLE); }
void uart_init() { UART_CFG_Type cfg; UART_FIFO_CFG_Type fifo_cfg; UART_ConfigStructInit(&cfg); cfg.Baud_rate = 57600; PINSEL_CFG_Type PinCfg; PinCfg.Funcnum = 1; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Pinnum = 2; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 3; PINSEL_ConfigPin(&PinCfg); UART_Init(LPC_UART0, &cfg); UART_FIFOConfigStructInit(&fifo_cfg); UART_FIFOConfig(LPC_UART0, &fifo_cfg); UART_TxCmd(LPC_UART0, ENABLE); }
/********************************************************************************************************* ** Function name: uartInit ** Descriptions: 串口初始化,设置为8位数据位,1位停止位,无奇偶校验,波特率为115200 ** input parameters: 无 ** output parameters: 无 ** Returned value: 无 *********************************************************************************************************/ void UART0Init (void) { UART_CFG_Type UART_ConfigStruct_Test; UART_FIFO_CFG_Type FIFOCfg_Test; UART_INT_Type UARTIntCfg_Test; GPIO_PinselConfig(RXD0,1); GPIO_PinselConfig(TXD0,1); GPIO_PinselConfig(EN_485_0,0); WriteEN_485_0(0); UART_ConfigStruct_Test.Baud_rate = UART0_BPS; UART_ConfigStruct_Test.Databits = UART_DATABIT_8; UART_ConfigStruct_Test.Parity = UART_PARITY_NONE; UART_ConfigStruct_Test.Stopbits = UART_STOPBIT_1; UART_Init((LPC_UART_TypeDef *)LPC_UART0,(UART_CFG_Type *)&UART_ConfigStruct_Test); UART_TxCmd((LPC_UART_TypeDef *)LPC_UART0,ENABLE); FIFOCfg_Test.FIFO_DMAMode = DISABLE; FIFOCfg_Test.FIFO_Level = UART_FIFO_TRGLEV2; FIFOCfg_Test.FIFO_ResetRxBuf = ENABLE; FIFOCfg_Test.FIFO_ResetTxBuf = ENABLE; UART_FIFOConfig((LPC_UART_TypeDef *)LPC_UART0, (UART_FIFO_CFG_Type *)&FIFOCfg_Test); UARTIntCfg_Test = UART_INTCFG_RBR; UART_IntConfig((LPC_UART_TypeDef *)LPC_UART0, UARTIntCfg_Test,ENABLE); InitFIFO((stcFIFO *)&sUART0RecFIFO,UART0RecBuf,sizeof(UART0RecBuf)); NVIC_EnableIRQ(UART0_IRQn); NVIC_SetPriority(UART0_IRQn, UART0_IRQn); }
void Serial_Init(const uint32_t BaudRate, const bool DoubleSpeed) { UART_CFG_Type UARTConfigStruct; /* * Initialize UART1 pin connect */ #if (BOARD == BOARD_XPLORER) scu_pinmux(0x1 ,13 , MD_PDN, FUNC1); // UART1_TXD scu_pinmux(0x1 ,14 , MD_PLN|MD_EZI|MD_ZI, FUNC1); // UART1_RXD #else scu_pinmux(0x4 ,1 , MD_PDN|MD_EZI, FUNC6); // UART3_TXD scu_pinmux(0x4 ,2 , MD_PDN|MD_EZI, FUNC6); // UART3_RXD #endif /* Initialize UART Configuration parameter structure to default state: * Baudrate = 9600bps * 8 data bit * 1 Stop bit * None parity */ UART_ConfigStructInit(&UARTConfigStruct); UARTConfigStruct.Baud_rate = BaudRate; // Re-configure baudrate // Initialize DEBUG_UART_PORT peripheral with given to corresponding parameter UART_Init(DEBUG_UART_PORT, &UARTConfigStruct); // Enable UART Transmit UART_TxCmd(DEBUG_UART_PORT, ENABLE); }
void USART_Init(void) { UART_CFG_Type UARTConfigStruct; UART_FIFO_CFG_Type UARTFIFOConfigStruct; PINSEL_ConfigPin(0,2,1); PINSEL_ConfigPin(0,3,1); UART_ConfigStructInit(&UARTConfigStruct); UART_Init(USART_ID, &UARTConfigStruct); UART_FIFOConfigStructInit(&UARTFIFOConfigStruct); #if USART_FIFO_LEVEL == 1 UARTFIFOConfigStruct.FIFO_Level = UART_FIFO_TRGLEV0; #elif USART_FIFO_LEVEL == 4 UARTFIFOConfigStruct.FIFO_Level = UART_FIFO_TRGLEV1; #elif USART_FIFO_LEVEL == 8 UARTFIFOConfigStruct.FIFO_Level = UART_FIFO_TRGLEV2; #elif USART_FIFO_LEVEL == 14 UARTFIFOConfigStruct.FIFO_Level = UART_FIFO_TRGLEV3; #endif UART_FIFOConfig(USART_ID, &UARTFIFOConfigStruct); UART_TxCmd(USART_ID, ENABLE); UART_IntConfig(USART_ID, UART_INTCFG_RBR, ENABLE); UART_IntConfig(USART_ID, UART_INTCFG_RLS, ENABLE); UART_IntConfig(USART_ID, UART_INTCFG_THRE, ENABLE); NVIC_SetPriority(USART_IRQ, ((0x01<<3)|0x01)); NVIC_EnableIRQ(USART_IRQ); }
void serial_init(void) { PINSEL_CFG_Type PinCfg; UART_CFG_Type UARTConfigStruct; UART_FIFO_CFG_Type UARTFIFOConfigStruct; //Init pins PinCfg.Funcnum = PINSEL_FUNC_1; PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL; PinCfg.Pinmode = PINSEL_PINMODE_PULLUP; PinCfg.Portnum = PINSEL_PORT_0; PinCfg.Pinnum = PINSEL_PIN_2; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = PINSEL_PIN_3; PINSEL_ConfigPin(&PinCfg); //Init UART Configuration parameter structure to default state: 115200,8,1,N UART_ConfigStructInit(&UARTConfigStruct); UARTConfigStruct.Baud_rate = 115200; //Init FIFOConfigStruct using defaults UART_FIFOConfigStructInit(&UARTFIFOConfigStruct); //Start the devices USB serial UART_Init((LPC_UART_TypeDef *)LPC_UART0, &UARTConfigStruct); UART_FIFOConfig((LPC_UART_TypeDef *)LPC_UART0, &UARTFIFOConfigStruct); UART_TxCmd((LPC_UART_TypeDef *)LPC_UART0, ENABLE); }
void uart2_init(const uint32_t BaudRate, const bool DoubleSpeed) { UART_CFG_Type UARTConfigStruct; PINSEL_CFG_Type PinCfg; PinCfg.Portnum = UART2_PORTNUM; PinCfg.Pinnum = UART2_TX_PINNUM; PinCfg.Funcnum = UART2_FUNCNUM; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = UART2_RX_PINNUM; PINSEL_ConfigPin(&PinCfg); /* Initialize UART Configuration parameter structure to default state: * Baudrate = 9600bps * 8 data bit * 1 Stop bit * None parity */ UART_ConfigStructInit(&UARTConfigStruct); // Re-configure baudrate UARTConfigStruct.Baud_rate = BaudRate; // Initialize DEBUG_UART_PORT peripheral with given to corresponding parameter UART_Init((LPC_UART_TypeDef *)FPGA_UART_PORT, &UARTConfigStruct); // Enable UART Transmit UART_TxCmd((LPC_UART_TypeDef *)FPGA_UART_PORT, ENABLE); UART_IntConfig((LPC_UART_TypeDef *)FPGA_UART_PORT, UART_INTCFG_RBR, ENABLE); NVIC_EnableIRQ(UART2_IRQn); }
void uart0_shutdown(void) { puts(""); UART_CFG_Type UARTConfigStruct; PINSEL_CFG_Type PinCfg; PinCfg.Portnum = UART0_PORTNUM; PinCfg.Pinnum = UART0_TX_PINNUM; PinCfg.Funcnum = 0; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = UART0_RX_PINNUM; PINSEL_ConfigPin(&PinCfg); GPIO_SetDir(UART0_PORTNUM, (1<<UART0_TX_PINNUM), 1); GPIO_SetValue(UART0_PORTNUM, (1<<UART0_TX_PINNUM)); UART_TxCmd((LPC_UART_TypeDef *)CONSOLE_UART_PORT, DISABLE); UART_IntConfig((LPC_UART_TypeDef *)CONSOLE_UART_PORT, UART_INTCFG_RBR, DISABLE); NVIC_DisableIRQ(UART0_IRQn); }
void Serial_Init(const uint32_t BaudRate, const bool DoubleSpeed) { UART_CFG_Type UARTConfigStruct; /* * Initialize UART pin connect */ // scu_pinmux(0x2 ,0 , MD_PDN, FUNC1); // UART0_TXD // scu_pinmux(0x2 ,1 , MD_PLN|MD_EZI|MD_ZI, FUNC1); // UART0_RXD scu_pinmux(0x2 ,3 , MD_PDN, FUNC2); // UART3_TXD scu_pinmux(0x2 ,4 , MD_PLN|MD_EZI|MD_ZI, FUNC2); // UART3_RXD /* Initialize UART Configuration parameter structure to default state: * Baudrate = 9600bps * 8 data bit * 1 Stop bit * None parity */ UART_ConfigStructInit(&UARTConfigStruct); UARTConfigStruct.Baud_rate = BaudRate; // Re-configure baudrate // Initialize uart peripheral with given to corresponding parameter UART_Init(DEBUG_UART_PORT, &UARTConfigStruct); // Enable UART Transmit UART_TxCmd(DEBUG_UART_PORT, ENABLE); }
void sio_init(void) { //LPC_USART_3 PINSEL_CFG_Type PinSelCfg; UART_CFG_Type UartCFG_Struct; UART_FIFO_CFG_Type UART_FIFO_CFG_Struct; // P4_28 PinSelCfg.Portnum = PINSEL_PORT_4; PinSelCfg.Pinnum = PINSEL_PIN_28; PinSelCfg.Funcnum = PINSEL_FUNC_3; PinSelCfg.OpenDrain = PINSEL_PINMODE_NORMAL; PinSelCfg.Pinmode = PINSEL_PINMODE_PULLUP; PINSEL_ConfigPin(&PinSelCfg); // P4_29 PinSelCfg.Pinnum = PINSEL_PIN_29; PINSEL_ConfigPin(&PinSelCfg); uartDataToSend.currPtr = 0; uartDataToSend.lastPtr = 0; /* Initialize UART Configuration parameter structure to default state: * Baudrate = 9600bps * 8 data bit * 1 Stop bit * None parity */ UART_ConfigStructInit(&UartCFG_Struct); /* Set Baudrate to 115200 */ UartCFG_Struct.Baud_rate = 115200; /* Initialize UART3 peripheral with given to corresponding parameter */ UART_Init(SERIAL_USART, &UartCFG_Struct); /* Initialize FIFOConfigStruct to default state: * - FIFO_DMAMode = DISABLE * - FIFO_Level = UART_FIFO_TRGLEV0 * - FIFO_ResetRxBuf = ENABLE * - FIFO_ResetTxBuf = ENABLE * - FIFO_State = ENABLE */ UART_FIFOConfigStructInit(&UART_FIFO_CFG_Struct); /* Initialize FIFO for UART3 peripheral */ UART_FIFOConfig(SERIAL_USART, &UART_FIFO_CFG_Struct); /* Enable UART Transmit */ UART_TxCmd(SERIAL_USART, ENABLE); UART_IntConfig(SERIAL_USART, UART_INTCFG_THRE, ENABLE); NVIC_SetPriorityGrouping(UART3_PriorGrup); NVIC_SetPriority(UART3_IRQn, UART3_Prior); NVIC_EnableIRQ(UART3_IRQn); }
/* *@描述:初始化串口 *@参数:void *@返回:无 */ void InitUart(void) { // UART Configuration structure variable UART_CFG_Type UARTConfigStruct; // UART FIFO configuration Struct variable UART_FIFO_CFG_Type UARTFIFOConfigStruct; // Pin configuration for UART0 PINSEL_CFG_Type PinCfg; /* * Initialize UART pin connect */ PinCfg.OpenDrain = UARTOpendrain; PinCfg.Pinmode = UARTPinMode; PinCfg.Portnum = UARTPortTX; PinCfg.Pinnum = UARTPinTX; PinCfg.Funcnum = UARTFuncTX; PINSEL_ConfigPin(&PinCfg); PinCfg.Portnum = UARTPortRX; PinCfg.Pinnum = UARTPinRX; PinCfg.Funcnum = UARTFuncRX; PINSEL_ConfigPin(&PinCfg); /* Initialize UART Configuration parameter structure to default state: * Baudrate = 9600bps * 8 data bit * 1 Stop bit * None parity */ UART_ConfigStructInit(&UARTConfigStruct); // Re-configure baudrate to 57600bps UARTConfigStruct.Baud_rate = 57600; // Initialize UART peripheral with given to corresponding parameter UART_Init((LPC_UART_TypeDef *)_LPC_UART, &UARTConfigStruct); /* Initialize FIFOConfigStruct to default state: * - FIFO_DMAMode = DISABLE * - FIFO_Level = UART_FIFO_TRGLEV0 * - FIFO_ResetRxBuf = ENABLE * - FIFO_ResetTxBuf = ENABLE * - FIFO_State = ENABLE */ UART_FIFOConfigStructInit(&UARTFIFOConfigStruct); UARTFIFOConfigStruct.FIFO_Level = UART_FIFO_TRGLEV3;//8 character // Initialize FIFO for UART0 peripheral UART_FIFOConfig((LPC_UART_TypeDef *)_LPC_UART, &UARTFIFOConfigStruct); // Enable UART Transmit UART_TxCmd((LPC_UART_TypeDef *)_LPC_UART, ENABLE); /* Enable UART Rx interrupt */ UART_IntConfig((LPC_UART_TypeDef *)_LPC_UART, UART_INTCFG_RBR, ENABLE); /* Enable UART line status interrupt */ UART_IntConfig((LPC_UART_TypeDef *)_LPC_UART, UART_INTCFG_RLS, DISABLE); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(_UART_IRQ, ((0x01<<3)|0x01)); /* Enable Interrupt for UART channel */ NVIC_EnableIRQ(_UART_IRQ); BufInit(&bufSerialRec); }
void uart_init(void) { // UART Configuration structure variable UART_CFG_Type UARTConfigStruct; // UART FIFO configuration Struct variable UART_FIFO_CFG_Type UARTFIFOConfigStruct; // Pin configuration for UART PINSEL_CFG_Type PinCfg; /* * Initialize UART3 pin connect: P4.28 -> TXD3; P4.29 -> RXD3 * or P0.2 -> TXD0, P0.3 -> RXD0 */ PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL; PinCfg.Pinmode = PINSEL_PINMODE_PULLUP; #if DBG_UART_NUM == 3 PinCfg.Funcnum = PINSEL_FUNC_3; PinCfg.Portnum = 4; PinCfg.Pinnum = 28; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 29; PINSEL_ConfigPin(&PinCfg); #else PinCfg.Funcnum = PINSEL_FUNC_1; PinCfg.Portnum = 0; PinCfg.Pinnum = 2; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 3; PINSEL_ConfigPin(&PinCfg); #endif /* Initialize UART Configuration parameter structure to default state: * Baudrate = as below * 8 data bit * 1 Stop bit * None parity */ UART_ConfigStructInit(&UARTConfigStruct); UARTConfigStruct.Baud_rate = 115200; // Initialize UART peripheral with given to corresponding parameter UART_Init(DBG_UART, &UARTConfigStruct); /* Initialize FIFOConfigStruct to default state: * - FIFO_DMAMode = DISABLE * - FIFO_Level = UART_FIFO_TRGLEV0 * - FIFO_ResetRxBuf = ENABLE * - FIFO_ResetTxBuf = ENABLE * - FIFO_State = ENABLE */ UART_FIFOConfigStructInit(&UARTFIFOConfigStruct); // Initialize FIFO for UART peripheral UART_FIFOConfig(DBG_UART, &UARTFIFOConfigStruct); // Enable UART Transmit UART_TxCmd(DBG_UART, ENABLE); }
/*********************************************************************//** * @brief Client Hardware Initialize * @param[in] None * @return None ***********************************************************************/ void ClientHardwareInit(void) { // UART Configuration structure variable UART_CFG_Type uart_config; // UART FIFO Configuration Struct variable UART_FIFO_CFG_Type uart_fifo; // Pin configuration for UART0 PINSEL_CFG_Type pin; // Initialize UART0 pin connect pin.Funcnum = PINSEL_FUNC_1; pin.OpenDrain = PINSEL_PINMODE_OPENDRAIN; pin.Pinmode = PINSEL_PINMODE_PULLUP; pin.Pinnum = PINSEL_PIN_2; pin.Portnum = PINSEL_PORT_0; PINSEL_ConfigPin(&pin); pin.Pinnum = PINSEL_PIN_3; PINSEL_ConfigPin(&pin); // Initialize UART Configration parameter structure to default state: // Baudrate = 9600bps // 8 data bit // 1 stop bit // None parity UART_ConfigStructInit(&uart_config); // Set baudrate to 115200 */ uart_config.Baud_rate = 115200; // Initialize UART0 peripheral with give to corresponding parameter */ UART_Init((LPC_UART_TypeDef *)LPC_UART0, &uart_config); // Initialize FIFOConfigStruct to default state: // - FIFO_DMAMode = DISABLE // - FIFO_Level = UART_FIFO_TRGLEV0 // - FIFO_ResetRxBuf = ENABLE // - FIFO_ResetTxBuf = ENABLE // - FIFO_State = ENABLE UART_FIFOConfigStructInit(&uart_fifo); // Initialize FIFO for UART0 peripheral UART_FIFOConfig((LPC_UART_TypeDef *)LPC_UART0, &uart_fifo); // Enable UART Transmit UART_TxCmd((LPC_UART_TypeDef *)LPC_UART0, ENABLE); // Enable UART Rx interrupt UART_IntConfig((LPC_UART_TypeDef *)LPC_UART0, UART_INTCFG_RBR, ENABLE); // Enable UART line status interrupt UART_IntConfig((LPC_UART_TypeDef *)LPC_UART0, UART_INTCFG_RLS, ENABLE); // preemption = 1, sub-priority = 1 NVIC_SetPriority(UART0_IRQn, ((0x01 << 3) | 0x01)); // Enable Interrupt for UART0 channel NVIC_EnableIRQ(UART0_IRQn); }
/*********************************************************************//** * @brief Modem Status interrupt callback * @param[in] modemState modem status value * @return None **********************************************************************/ void UART1_ModemCallBack(uint8_t modemState) { #if (AUTO_RTS_CTS_USE == 0) // Check CTS status change flag if (modemState & UART1_MODEM_STAT_DELTA_CTS) { // if CTS status is active, continue to send data if (modemState & UART1_MODEM_STAT_CTS) { // Re-Enable Tx UART_TxCmd((LPC_UART_TypeDef *)LPC_UART1, ENABLE); } // Otherwise, Stop current transmission immediately else{ // Disable Tx UART_TxCmd((LPC_UART_TypeDef *)LPC_UART1, DISABLE); } } #endif }
/* Auto flow control does work, but it turns the serial write functions into * blocking functions, which drags USB down. Instead we handle it manually so we * can make them asynchronous and let USB run at full speed. */ void configureFlowControl() { if (UART_FullModemGetStatus(LPC_UART1) & UART1_MODEM_STAT_CTS) { // Enable UART Transmit UART_TxCmd(UART1_DEVICE, ENABLE); } // Enable Modem status interrupt UART_IntConfig(UART1_DEVICE, UART1_INTCFG_MS, ENABLE); // Enable CTS1 signal transition interrupt UART_IntConfig(UART1_DEVICE, UART1_INTCFG_CTS, ENABLE); resumeReceive(); }
void init_uart(void){ UART_CFG_Type uartCfg; uartCfg.Baud_rate = 115200; uartCfg.Databits = UART_DATABIT_8; uartCfg.Parity =UART_PARITY_NONE; uartCfg.Stopbits = UART_STOPBIT_1; pinsel_uart3(); UART_Init(LPC_UART3, &uartCfg); UART_TxCmd(LPC_UART3,ENABLE); }
void vMBMasterPortClose(void) { /******************DISABLE the uart NVIC *******************/ NVIC_DisableIRQ(UART0_IRQn); NVIC_DisableIRQ(UART2_IRQn); NVIC_DisableIRQ(UART3_IRQn); NVIC_DisableIRQ(UART4_IRQn); /*****************DISABLE the uartrx exit********************/ UART_IntConfig(UART_0, UART_INTCFG_RBR, DISABLE); UART_IntConfig(UART_2, UART_INTCFG_RBR, DISABLE); UART_IntConfig(UART_3, UART_INTCFG_RBR, DISABLE); UART_IntConfig(UART_4, UART_INTCFG_RBR, DISABLE); /*******************Enable the uart line exit***************/ UART_IntConfig(UART_0, UART_INTCFG_RLS, DISABLE); UART_IntConfig(UART_2, UART_INTCFG_RLS, DISABLE); UART_IntConfig(UART_3, UART_INTCFG_RLS, DISABLE); UART_IntConfig(UART_4, UART_INTCFG_RLS, DISABLE); UART_RS485ReceiverCmd(UART_0,DISABLE); UART_RS485ReceiverCmd(UART_2,DISABLE); UART_RS485ReceiverCmd(UART_3,DISABLE); UART_RS485ReceiverCmd(UART_4,DISABLE); /*******************Uart DISABLE****************************/ UART_TxCmd(LPC_UART0,DISABLE); UART_TxCmd(LPC_UART2,DISABLE); UART_TxCmd(LPC_UART3,DISABLE); UART_TxCmd((LPC_UART_TypeDef *)LPC_UART4,DISABLE); // USART_ITConfig(USART2, USART_IT_TXE | USART_IT_RXNE, DISABLE); // USART_Cmd(USART2, DISABLE); }
void serial_init(uint32_t baud_rate) { UART_CFG_Type UART_config; UART_FIFO_CFG_Type UART_fifo_config; PINSEL_CFG_Type pin_config; // Configure TXD and RXD Pins pin_config.OpenDrain = PINSEL_PINMODE_NORMAL; pin_config.Pinmode = PINSEL_PINMODE_PULLUP; pin_config.Funcnum = UART_TXD_FUNC; pin_config.Portnum = UART_TXD_PORT; pin_config.Pinnum = UART_TXD_PIN; PINSEL_ConfigPin(&pin_config); pin_config.Funcnum = UART_RXD_FUNC; pin_config.Portnum = UART_RXD_PORT; pin_config.Pinnum = UART_RXD_PIN; PINSEL_ConfigPin(&pin_config); #pragma message "BT TXD on Pin : P" STRING(UART_TXD_PORT) "_" STRING(UART_TXD_PIN) #pragma message "BT RXD on Pin : P" STRING(UART_RXD_PORT) "_" STRING(UART_RXD_PIN) // Configure UART UART_config.Baud_rate = baud_rate; UART_config.Databits = UART_DATABIT_8; UART_config.Parity = UART_PARITY_NONE; UART_config.Stopbits = UART_STOPBIT_1; UART_Init((LPC_UART_TypeDef *)UART_PORT, &UART_config); // Configure FIFO UART_fifo_config.FIFO_DMAMode = DISABLE; UART_fifo_config.FIFO_Level = UART_FIFO_TRGLEV0; UART_fifo_config.FIFO_ResetRxBuf = ENABLE; UART_fifo_config.FIFO_ResetTxBuf = ENABLE; UART_FIFOConfig((LPC_UART_TypeDef *)UART_PORT, &UART_fifo_config); // Enable UART Transmit UART_TxCmd((LPC_UART_TypeDef *)UART_PORT, ENABLE); // Enable UART interrupts UART_IntConfig((LPC_UART_TypeDef *)UART_PORT, UART_INTCFG_RLS, ENABLE); UART_IntConfig((LPC_UART_TypeDef *)UART_PORT, UART_INTCFG_RBR, ENABLE); UART_IntConfig((LPC_UART_TypeDef *)UART_PORT, UART_INTCFG_THRE, ENABLE); // preemption = 1, sub-priority = 1 NVIC_SetPriority(UARTx_IRQn, ((0x01 << 3) | 0x01)); // Enable Interrupt for UART NVIC_EnableIRQ(UARTx_IRQn); }
/* * Configure the pins according to their intended default function */ int _roboveroConfig(uint8_t * args) { int i; UART_CFG_Type UARTConfigStruct; PWM_TIMERCFG_Type PWMCfgDat; configAllPins(); /* * Enable 7 analog inputs */ ADC_Init(LPC_ADC, 200000); for (i = 0; i < 4; i++) ADC_ChannelCmd(LPC_ADC, i, ENABLE); for (i = 5; i < 8; i++) ADC_ChannelCmd(LPC_ADC, i, ENABLE); /* * Configure I2C0 for IMU communications */ I2C_Init(LPC_I2C0, 100000); I2C_Cmd(LPC_I2C0, ENABLE); /* * Initialize CAN bus */ CAN_Init(LPC_CAN1, 100000); /* * Initialize UART1 */ UART_ConfigStructInit(&UARTConfigStruct); UARTConfigStruct.Baud_rate = 115200; UART_Init((LPC_UART_TypeDef*)LPC_UART1, &UARTConfigStruct); UART_TxCmd((LPC_UART_TypeDef*)LPC_UART1, ENABLE); /* * Initialize PWM * * Peripheral clock is 30MHz. Prescale by 30 cycles for 1us resolution. */ PWMCfgDat.PrescaleOption = PWM_TIMER_PRESCALE_TICKVAL; PWMCfgDat.PrescaleValue = 30; PWM_Init(LPC_PWM1, PWM_MODE_TIMER, &PWMCfgDat); return 0; }
static void uart3_init(rt_uint32_t baudrate) { PINSEL_CFG_Type PinSelCfgType; UART_CFG_Type UartCfgType; UART_FIFO_CFG_Type UartFIFOCfgType; //pin config //TXD PinSelCfgType.Portnum = PINSEL_PORT_0; PinSelCfgType.Pinnum = PINSEL_PIN_0; PinSelCfgType.Funcnum = PINSEL_FUNC_2; PinSelCfgType.Pinmode = PINSEL_PINMODE_PULLUP; PinSelCfgType.OpenDrain = PINSEL_PINMODE_NORMAL; PINSEL_ConfigPin(&PinSelCfgType); //RXD PinSelCfgType.Portnum = PINSEL_PORT_0; PinSelCfgType.Pinnum = PINSEL_PIN_1; PinSelCfgType.Funcnum = PINSEL_FUNC_2; PinSelCfgType.Pinmode = PINSEL_PINMODE_TRISTATE; PinSelCfgType.OpenDrain = PINSEL_PINMODE_NORMAL; PINSEL_ConfigPin(&PinSelCfgType); //init UartCfgType.Baud_rate = baudrate; UartCfgType.Parity = UART_PARITY_NONE; UartCfgType.Databits = UART_DATABIT_8; UartCfgType.Stopbits = UART_STOPBIT_1; UART_Init(LPC_DEV_UART, &UartCfgType); //FIFO UartFIFOCfgType.FIFO_ResetRxBuf = ENABLE; UartFIFOCfgType.FIFO_ResetTxBuf = ENABLE; UartFIFOCfgType.FIFO_DMAMode = DISABLE; UartFIFOCfgType.FIFO_Level = UART_FIFO_TRGLEV2; UART_FIFOConfig(LPC_DEV_UART, &UartFIFOCfgType); //int UART_IntConfig(LPC_DEV_UART, UART_INTCFG_RBR, ENABLE); //enable UART_TxCmd(LPC_DEV_UART, ENABLE); }
/****************************************************************************** * * Description: * Initialize the console (UART connected to USB-to-UART bridge) * *****************************************************************************/ void console_init(void) { // UART Configuration structure variable UART_CFG_Type UARTConfigStruct; // pinsel for UART PINSEL_ConfigPin(0,2,1); PINSEL_ConfigPin(0,3,1); UART_ConfigStructInit(&UARTConfigStruct); UARTConfigStruct.Baud_rate = 115200; // Initialize UART0 peripheral with given to corresponding parameter UART_Init(CONSOLE_DEV, &UARTConfigStruct); // Enable UART Transmit UART_TxCmd(CONSOLE_DEV, ENABLE); }
static void uart_regs_init(uint8_t id) { uart_tab[id]->bit_len = SystemCoreClock / uart_tab[id]->config.Baud_rate; UART_DeInit(uart_tab[id]->uart); UART_Init(uart_tab[id]->uart, &(uart_tab[id]->config)); /////////////////////////////////////// // init hardware fifo // Initialize FIFO for UART0 peripheral UART_FIFO_CFG_Type UARTFIFOConfigStruct; UARTFIFOConfigStruct.FIFO_DMAMode = DISABLE; UARTFIFOConfigStruct.FIFO_Level = UART_FIFO_TRGLEV2; UARTFIFOConfigStruct.FIFO_ResetRxBuf = ENABLE; UARTFIFOConfigStruct.FIFO_ResetTxBuf = ENABLE; UART_FIFOConfig(uart_tab[id]->uart, &UARTFIFOConfigStruct); UART_TxCmd(uart_tab[id]->uart, ENABLE); // enable transmit uart_tab[id]->uart->IER |= UART_IER_RBRINT_EN; // enable rbr interrupt uart_tab[id]->uart->IER |= UART_IER_THREINT_EN; // enable thre interrupt // Do not enable transmit interrupt here, since it is handled by // UART_Send() function, just to reset Tx Interrupt state for the // first time switch(id) { case 0: NVIC_SetPriority(UART0_IRQn, ((0x01<<3)|0x01)); // preemption = 1, sub-priority = 1 NVIC_EnableIRQ(UART0_IRQn); // Enable Interrupt for UART0 channel break; case 1: NVIC_SetPriority(UART1_IRQn, ((0x01<<3)|0x01)); // preemption = 1, sub-priority = 1 NVIC_EnableIRQ(UART1_IRQn); // Enable Interrupt for UART0 channel break; case 2: NVIC_SetPriority(UART2_IRQn, ((0x01<<3)|0x01)); // preemption = 1, sub-priority = 1 NVIC_EnableIRQ(UART2_IRQn); // Enable Interrupt for UART0 channel break; case 3: NVIC_SetPriority(UART3_IRQn, ((0x01<<3)|0x01)); // preemption = 1, sub-priority = 1 NVIC_EnableIRQ(UART3_IRQn); // Enable Interrupt for UART0 channel default: break; } }
void DEBUG_init(void) // init code for the USB serial line { UART_CFG_Type UARTConfigStruct; // UART Configuration structure variable UART_FIFO_CFG_Type UARTFIFOConfigStruct; // UART FIFO configuration Struct variable PINSEL_CFG_Type PinCfg; // Pin configuration for UART /* * Initialize UART pin connect */ PinCfg.Funcnum = 1; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; // USB serial first PinCfg.Portnum = 0; PinCfg.Pinnum = 2; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 3; PINSEL_ConfigPin(&PinCfg); /* Initialize UART Configuration parameter structure to default state: * - Baudrate = 9600bps * - 8 data bit * - 1 Stop bit * - None parity */ UART_ConfigStructInit(&UARTConfigStruct); /* Initialize FIFOConfigStruct to default state: * - FIFO_DMAMode = DISABLE * - FIFO_Level = UART_FIFO_TRGLEV0 * - FIFO_ResetRxBuf = ENABLE * - FIFO_ResetTxBuf = ENABLE * - FIFO_State = ENABLE */ UART_FIFOConfigStructInit(&UARTFIFOConfigStruct); // Built the basic structures, lets start the devices/ // USB serial UART_Init((LPC_UART_TypeDef *)LPC_UART0, &UARTConfigStruct); // Initialize UART0 peripheral with given to corresponding parameter UART_FIFOConfig((LPC_UART_TypeDef *)LPC_UART0, &UARTFIFOConfigStruct); // Initialize FIFO for UART0 peripheral UART_TxCmd((LPC_UART_TypeDef *)LPC_UART0, ENABLE); // Enable UART Transmit }
void SER_Init(uint32_t baudrate) { UART_CFG_Type UART_ConfigStruct; UART_FIFO_CFG_Type UART_FIFOInitStruct; UART_ConfigStruct.Baud_rate = baudrate; UART_ConfigStruct.Parity = UART_PARITY_NONE; UART_ConfigStruct.Stopbits = UART_STOPBIT_1; UART_ConfigStruct.Databits = UART_DATABIT_8; UART_Init(LPC_UART0, &UART_ConfigStruct); //Init UART0 with parameters, defined above UART_TxCmd(LPC_UART0, ENABLE); //Enable transmission on UART TxD pin UART_FIFOConfigStructInit(&UART_FIFOInitStruct); //Fills each UART_FIFOInitStruct member with its default value UART_FIFOConfig(LPC_UART0, &UART_FIFOInitStruct); //Configure FIFO function on UART0 peripheral UART_IntConfig(LPC_UART0,UART_INTCFG_RBR,ENABLE); //Enable UART0 RBR Interrupt NVIC_EnableIRQ(UART0_IRQn); //Enable UART0 Interrupts }
void printsetup(void){ UART_CFG_Type UARTConfigStruct; // UART Configuration structure variable UART_FIFO_CFG_Type UARTFIFOConfigStruct; // UART FIFO configuration Struct variable PINSEL_CFG_Type PinCfg; // Pin configuration for UART PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Funcnum = 1; PinCfg.Portnum = 0; PinCfg.Pinnum = 2; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 3; PINSEL_ConfigPin(&PinCfg); UART_ConfigStructInit(&UARTConfigStruct); UART_FIFOConfigStructInit(&UARTFIFOConfigStruct); UART_Init((LPC_UART_TypeDef *) LPC_UART0, &UARTConfigStruct); UART_TxCmd((LPC_UART_TypeDef *) LPC_UART0, ENABLE); }
/*********************************************************************//** * @brief De-initializes the UARTx peripheral registers to their * default reset values. * @param[in] UARTx UART peripheral selected, should be: * - LPC_UART0: UART0 peripheral * - LPC_UART1: UART1 peripheral * - LPC_UART2: UART2 peripheral * - LPC_UART3: UART3 peripheral * @return None **********************************************************************/ void UART_DeInit(LPC_UART_TypeDef* UARTx) { // For debug mode CHECK_PARAM(PARAM_UARTx(UARTx)); UART_TxCmd(UARTx, DISABLE); #ifdef _UART0 if (UARTx == LPC_UART0) { /* Set up clock and power for UART module */ CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART0, DISABLE); } #endif #ifdef _UART1 if (((LPC_UART1_TypeDef *)UARTx) == LPC_UART1) { /* Set up clock and power for UART module */ CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART1, DISABLE); } #endif #ifdef _UART2 if (UARTx == LPC_UART2) { /* Set up clock and power for UART module */ CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART2, DISABLE); } #endif #ifdef _UART3 if (UARTx == LPC_UART3) { /* Set up clock and power for UART module */ CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART3, DISABLE); } #endif }