int32_t Board_UART_getChar(LPC_USART_T *pUART) { if (Chip_UART_ReadLineStatus(pUART) & UART_LSR_RDR) { return (int32_t)Chip_UART_ReadByte(pUART); } return -1; }
void UART0_IRQHandler (void) { uint8_t status = Chip_UART_ReadLineStatus(LPC_USART0); if(status & UART_LSR_RDR) { if(uart0RxBufferData.index<uart0RxBufferData.size) { uart0RxBufferData.buffer[uart0RxBufferData.index] = Chip_UART_ReadByte(LPC_USART0); if(uart0RxBufferData.timeout==0) { if(uart0RxBufferData.buffer[uart0RxBufferData.index]==uart0RxBufferData.finalByte) { uart0RxBufferData.flagNewPacket=1; //Board_UARTPutSTR("entro paquete por byte final!:"); //Board_UARTPutSTR(uart0RxBufferData.buffer); } } else { uart3RxBufferData.timeoutCounter=uart3RxBufferData.timeout; } uart3RxBufferData.index++; } else uart3RxBufferData.flagNewPacket=1; } }
void __lpc1788_isr_uart4(void) { while (UART_LSR_RDR & Chip_UART_ReadLineStatus(LPC_UART4)) { read_byte = Chip_UART_ReadByte(LPC_UART4); buf_uart.buffer[buf_uart.producer] = read_byte; BUF_PRODUCER_PLUS1; } }
/* UART receive-only interrupt handler for ring buffers */ void Chip_UART_RXIntHandlerRB(LPC_USART_T *pUART, RINGBUFF_T *pRB) { /* New data will be ignored if data not popped in time */ while (Chip_UART_ReadLineStatus(pUART) & UART_LSR_RDR) { uint8_t ch = Chip_UART_ReadByte(pUART); RingBuffer_Insert(pRB, &ch); } }
void ciaaUARTInit(void) { /* UART0 (RS485/Profibus) */ Chip_UART_Init(LPC_USART0); Chip_UART_SetBaud(LPC_USART0, 115200); Chip_UART_TXEnable(LPC_USART0); Chip_SCU_PinMux(9, 5, MD_PDN, FUNC7); /* P9_5: UART0_TXD */ Chip_SCU_PinMux(9, 6, MD_PLN|MD_EZI|MD_ZI, FUNC7); /* P9_6: UART0_RXD */ Chip_UART_SetRS485Flags(LPC_USART0, UART_RS485CTRL_DCTRL_EN | UART_RS485CTRL_OINV_1); Chip_SCU_PinMux(6, 2, MD_PDN, FUNC2); /* P6_2: UART0_DIR */ /* Restart FIFOS: set Enable, Reset content, set trigger level */ Chip_UART_SetupFIFOS(LPC_USART0, UART_FCR_FIFO_EN | UART_FCR_TX_RS | UART_FCR_RX_RS | UART_FCR_TRG_LEV0); /* dummy read */ Chip_UART_ReadByte(LPC_USART0); /* enable rx interrupt */ Chip_UART_IntEnable(LPC_USART0, UART_IER_RBRINT); NVIC_EnableIRQ(USART0_IRQn); RingBuffer_Init(uarts[0].rrb, rxbuf[0], 1, UART_BUF_SIZE); RingBuffer_Init(uarts[0].trb, txbuf[0], 1, UART_BUF_SIZE); /* UART2 (USB-UART) */ Chip_UART_Init(LPC_USART2); Chip_UART_SetBaud(LPC_USART2, 115200); Chip_UART_TXEnable(LPC_USART2); Chip_SCU_PinMux(7, 1, MD_PDN, FUNC6); /* P7_1: UART2_TXD */ Chip_SCU_PinMux(7, 2, MD_PLN|MD_EZI|MD_ZI, FUNC6); /* P7_2: UART2_RXD */ Chip_UART_IntEnable(LPC_USART2, UART_IER_RBRINT); NVIC_EnableIRQ(USART2_IRQn); RingBuffer_Init(uarts[1].rrb, rxbuf[1], 1, UART_BUF_SIZE); RingBuffer_Init(uarts[1].trb, txbuf[1], 1, UART_BUF_SIZE); /* UART3 (RS232) */ Chip_UART_Init(LPC_USART3); Chip_UART_SetBaud(LPC_USART3, 115200); Chip_UART_TXEnable(LPC_USART3); Chip_SCU_PinMux(2, 3, MD_PDN, FUNC2); /* P2_3: UART3_TXD */ Chip_SCU_PinMux(2, 4, MD_PLN|MD_EZI|MD_ZI, FUNC2); /* P2_4: UART3_RXD */ Chip_UART_IntEnable(LPC_USART3, UART_IER_RBRINT); NVIC_EnableIRQ(USART3_IRQn); RingBuffer_Init(uarts[2].rrb, rxbuf[2], 1, UART_BUF_SIZE); RingBuffer_Init(uarts[2].trb, txbuf[2], 1, UART_BUF_SIZE); }
/* Gets a character from the UART, returns EOF if no character is ready */ int Board_UARTGetChar(void) { #if defined(DEBUG_UART) if (Chip_UART_ReadLineStatus(DEBUG_UART) & UART_LSR_RDR) { return (int) Chip_UART_ReadByte(DEBUG_UART); } #endif return EOF; }
//================================================[UART Management]========================================================== void Board_UART_Init(LPC_USART_T *pUART) { if(pUART==LPC_USART0) { /* UART0 (RS485/Profibus) */ Chip_UART_Init(LPC_USART0); Chip_UART_SetBaud(LPC_USART0, 115200); Chip_UART_SetupFIFOS(LPC_USART0, UART_FCR_FIFO_EN | UART_FCR_TRG_LEV0); Chip_UART_TXEnable(LPC_USART0); Chip_SCU_PinMux(9, 5, MD_PDN, FUNC7); /* P9_5: UART0_TXD */ Chip_SCU_PinMux(9, 6, MD_PLN|MD_EZI|MD_ZI, FUNC7); /* P9_6: UART0_RXD */ Chip_UART_SetRS485Flags(LPC_USART0, UART_RS485CTRL_DCTRL_EN | UART_RS485CTRL_OINV_1); Chip_SCU_PinMux(6, 2, MD_PDN, FUNC2); /* P6_2: UART0_DIR */ uart0RxBufferData.buffer = NULL; uart0RxBufferData.size=0; uart0RxBufferData.index=0; uart0RxBufferData.flagNewPacket=0; uart0RxBufferData.timeoutCounter=0; //NVIC_SetPriority(USART0_IRQn, 1); //NVIC_EnableIRQ(USART0_IRQn); } else if(pUART==LPC_USART3) { /* UART3 (RS232) */ Chip_UART_Init(LPC_USART3); Chip_UART_SetBaud(LPC_USART3, 115200); Chip_UART_SetupFIFOS(LPC_USART3, UART_FCR_FIFO_EN | UART_FCR_TRG_LEV0); Chip_UART_TXEnable(LPC_USART3); Chip_SCU_PinMux(2, 3, MD_PDN, FUNC2); /* P2_3: UART3_TXD */ Chip_SCU_PinMux(2, 4, MD_PLN|MD_EZI|MD_ZI, FUNC2); /* P2_4: UART3_RXD */ uart3RxBufferData.buffer = NULL; uart3RxBufferData.size=0; uart3RxBufferData.index=0; uart3RxBufferData.flagNewPacket=0; uart3RxBufferData.timeoutCounter=0; //NVIC_SetPriority(USART3_IRQn, 1); //NVIC_EnableIRQ(USART3_IRQn); } /* Restart FIFOS: set Enable, Reset content, set trigger level */ Chip_UART_SetupFIFOS(pUART, UART_FCR_FIFO_EN | UART_FCR_TX_RS | UART_FCR_RX_RS | UART_FCR_TRG_LEV0); /* dummy read */ Chip_UART_ReadByte(pUART); /* enable rx interrupt */ Chip_UART_IntEnable(pUART, UART_IER_RBRINT); }
/*==================[external functions definition]==========================*/ extern ciaaDevices_deviceType * ciaaDriverUart_open(char const * path, ciaaDevices_deviceType * device, uint8_t const oflag) { /* Restart FIFOS: set Enable, Reset content, set trigger level */ Chip_UART_SetupFIFOS((LPC_USART_T *)device->loLayer, UART_FCR_FIFO_EN | UART_FCR_TX_RS | UART_FCR_RX_RS | UART_FCR_TRG_LEV0); /* dummy read */ Chip_UART_ReadByte((LPC_USART_T *)device->loLayer); /* enable rx interrupt */ Chip_UART_IntEnable((LPC_USART_T *)device->loLayer, UART_IER_RBRINT); return device; }
/* Read data through the UART peripheral (non-blocking) */ int Chip_UART_Read(LPC_USART_T *pUART, void *data, int numBytes) { int readBytes = 0; uint8_t *p8 = (uint8_t *) data; /* Send until the transmit FIFO is full or out of bytes */ while ((readBytes < numBytes) && ((Chip_UART_ReadLineStatus(pUART) & UART_LSR_RDR) != 0)) { *p8 = Chip_UART_ReadByte(pUART); p8++; readBytes++; } return readBytes; }
uint8_t UARTUSB_Rx_readByte(){ uint8_t dato = Chip_UART_ReadByte(LPC_USART2); return dato; }
uint8_t ReadUART() { return Chip_UART_ReadByte((LPC_USART_T*)LPC_USART2); }
uint8_t readByte_UART_USB_EDUCIAA() { return Chip_UART_ReadByte((LPC_USART_T *)LPC_USART2); }
/** \brief Main function * * This is the main entry point of the software. * * \returns 0 * * \remarks This function never returns. Return value is only to avoid compiler * warnings or errors. */ int main(void) { /*Put initializations in a separate function hw_init(void) or something like that...*/ Chip_SCU_PinMux(1,0,MD_PUP|MD_EZI|MD_ZI,FUNC0); /* GPIO0[4], SW1 */ Chip_SCU_PinMux(1,1,MD_PUP|MD_EZI|MD_ZI,FUNC0); /* GPIO0[8], SW2 */ Chip_SCU_PinMux(1,2,MD_PUP|MD_EZI|MD_ZI,FUNC0); /* GPIO0[9], SW3 */ Chip_SCU_PinMux(1,6,MD_PUP|MD_EZI|MD_ZI,FUNC0); /* GPIO1[9], SW4 */ Chip_GPIO_SetDir(LPC_GPIO_PORT, 0,(1<<4)|(1<<8)|(1<<9),0); Chip_GPIO_SetDir(LPC_GPIO_PORT, 1,(1<<9),0); /* LEDs */ Chip_SCU_PinMux(2,0,MD_PUP,FUNC4); /* GPIO5[0], LED0R */ Chip_SCU_PinMux(2,1,MD_PUP,FUNC4); /* GPIO5[1], LED0G */ Chip_SCU_PinMux(2,2,MD_PUP,FUNC4); /* GPIO5[2], LED0B */ Chip_SCU_PinMux(2,10,MD_PUP,FUNC0); /* GPIO0[14], LED1 */ Chip_SCU_PinMux(2,11,MD_PUP,FUNC0); /* GPIO1[11], LED2 */ Chip_SCU_PinMux(2,12,MD_PUP,FUNC0); /* GPIO1[12], LED3 */ Chip_GPIO_SetDir(LPC_GPIO_PORT, 5,(1<<0)|(1<<1)|(1<<2),1); Chip_GPIO_SetDir(LPC_GPIO_PORT, 0,(1<<14),1); Chip_GPIO_SetDir(LPC_GPIO_PORT, 1,(1<<11)|(1<<12),1); Chip_GPIO_ClearValue(LPC_GPIO_PORT, 5,(1<<0)|(1<<1)|(1<<2)); Chip_GPIO_ClearValue(LPC_GPIO_PORT, 0,(1<<14)); Chip_GPIO_ClearValue(LPC_GPIO_PORT, 1,(1<<11)|(1<<12)); /*Hardware GPIO initialization (leds, buttons ...)*/ /*UART initialization*/ /* UART0 (RS485/Profibus) */ Chip_UART_Init(LPC_USART0); Chip_UART_SetBaud(LPC_USART0, 115200); Chip_UART_SetupFIFOS(LPC_USART0, UART_FCR_FIFO_EN | UART_FCR_TRG_LEV0); Chip_UART_TXEnable(LPC_USART0); Chip_SCU_PinMux(9, 5, MD_PDN, FUNC7); /* P9_5: UART0_TXD */ Chip_SCU_PinMux(9, 6, MD_PLN|MD_EZI|MD_ZI, FUNC7); /* P9_6: UART0_RXD */ Chip_UART_SetRS485Flags(LPC_USART0, UART_RS485CTRL_DCTRL_EN | UART_RS485CTRL_OINV_1); Chip_SCU_PinMux(6, 2, MD_PDN, FUNC2); /* P6_2: UART0_DIR */ /* UART2 (USB-UART) */ Chip_UART_Init(LPC_USART2); Chip_UART_SetBaud(LPC_USART2, 115200); Chip_UART_SetupFIFOS(LPC_USART2, UART_FCR_FIFO_EN | UART_FCR_TRG_LEV0); Chip_UART_TXEnable(LPC_USART2); Chip_SCU_PinMux(7, 1, MD_PDN, FUNC6); /* P7_1: UART2_TXD */ Chip_SCU_PinMux(7, 2, MD_PLN|MD_EZI|MD_ZI, FUNC6); /* P7_2: UART2_RXD */ /* UART3 (RS232) */ Chip_UART_Init(LPC_USART3); Chip_UART_SetBaud(LPC_USART3, 115200); Chip_UART_SetupFIFOS(LPC_USART3, UART_FCR_FIFO_EN | UART_FCR_TRG_LEV0); Chip_UART_TXEnable(LPC_USART3); Chip_SCU_PinMux(2, 3, MD_PDN, FUNC2); /* P2_3: UART3_TXD */ Chip_SCU_PinMux(2, 4, MD_PLN|MD_EZI|MD_ZI, FUNC2); /* P2_4: UART3_RXD */ /*Chip_UART_IntDisable((LPC_USART_T *)LPC_USART2, UART_IER_THREINT);*/ /* this one calls write */ /*ciaaDriverUart_txConfirmation(device);*/ /* enable THRE irq (TX) */ /* Chip_UART_IntEnable((LPC_USART_T *)LPC_USART2, UART_IER_THREINT);*/ uint64_t j; uint8_t size = 28; uint8_t i = 0; uint8_t data = 0; char message[] = "Follow the white rabbit...\n\r"; /* just send the F ...! */ /* Chip_UART_Send((LPC_USART_T *) LPC_USART2, message, index); */ /*looking for a 'a' character*/ /* perform the needed initialization here */ while(1) { /* do nothing */ data = i = 0; /*wait for keyboard character*/ while (data == 0) { data = Chip_UART_ReadByte((LPC_USART_T *)LPC_USART2); switch (data){ case 'r': /*Toggle Red Led*/ Chip_GPIO_SetPortToggle(LPC_GPIO_PORT,LED2_PORT,LED_2); break; case 'v': /*Toggle Green Led*/ Chip_GPIO_SetPortToggle(LPC_GPIO_PORT,LED3_PORT,LED_3); break; case 'a': /*Toggle Yellow Led*/ Chip_GPIO_SetPortToggle(LPC_GPIO_PORT,LED1_PORT,LED_1); break; default: data = 0; } } /*Send string*/ while(((Chip_UART_ReadLineStatus((LPC_USART_T *)LPC_USART2) & UART_LSR_THRE) != 0) && (i < size)) { /* send first byte */ Chip_UART_SendByte((LPC_USART_T *)LPC_USART2, message[i]); /* bytes written */ /*delay*/ for (j=0;j<50000;j++){ asm ("nop"); } i++; } } return 0; }
char recibir_UART(void) { Chip_UART_ReadByte(LPC_USART2); return data_r; }
uint8_t LeerByte_UART(void) { Chip_UART_ReadByte(LPC_USART2); }
/* Přerušení.. * UART0 - Konfigurace mac/ip adresy * UART2 - Pro konektory J4 - 5 na desce * UART4 - Pro debug test (konektory J6 - 7) * * Přijímání dat po bajtu od zařízení JN5148 a ukládání * do kruhového bufferu. */ void __lpc1788_isr_uart0(void) { while (UART_LSR_RDR & Chip_UART_ReadLineStatus(UART0)) { eeprom_buffer[eeprom_lenght] = Chip_UART_ReadByte(UART0); eeprom_lenght++; } }