/* Sends a character on the UART */ void Board_UARTPutChar(char ch) { #if defined(DEBUG_ENABLE) while ((Chip_UART_ReadLineStatus(DEBUG_UART) & UART_LSR_THRE) == 0) {} Chip_UART_SendByte(DEBUG_UART, (uint8_t) ch); #endif }
/** * @brief Handle interrupt from UART * @return Nothing */ void UART1_IRQHandler(void) { uint8_t ch; uint32_t IntStatus = Chip_UART_GetIntStatus(LPC_USART1); if (IntStatus & RXRDY_INT) { if(receiveCompleted == false) { Chip_UART_ReceiveByte(LPC_USART1, &RxBuf1[RxBufCnt1++]); if (RxBufCnt1 == BUFFER_SIZE) { Chip_UART_IntEnable(LPC_USART1, RXRDY_INT, DISABLE); receiveCompleted = true; RxBufCnt1 = 0; } } else { Chip_UART_ReceiveByte(LPC_USART1, &ch); } } if (IntStatus & TXRDY_INT) { if (sendCompleted == false) { Chip_UART_SendByte(LPC_USART1, RxBuf1[TxBufCnt1++]); if (TxBufCnt1 == BUFFER_SIZE) { Chip_UART_IntEnable(LPC_USART1, TXRDY_INT, DISABLE); sendCompleted = true; TxBufCnt1 = 0; } } else { return; } } }
/* Sends a character on the UART */ void Board_UARTPutChar(char ch) { #if defined(DEBUG_UART) /* Wait for space in FIFO */ while ((Chip_UART_ReadLineStatus(DEBUG_UART) & UART_LSR_THRE) == 0) {} Chip_UART_SendByte(DEBUG_UART, (uint8_t) ch); #endif }
/* UART transmit-only interrupt handler for ring buffers */ void Chip_UART_TXIntHandlerRB(LPC_USART_T *pUART, RINGBUFF_T *pRB) { uint8_t ch; /* Fill FIFO until full or until TX ring buffer is empty */ while ((Chip_UART_ReadLineStatus(pUART) & UART_LSR_THRE) != 0 && RingBuffer_Pop(pRB, &ch)) { Chip_UART_SendByte(pUART, ch); } }
uint32_t Board_UART_Write(LPC_USART_T *pUART, uint8_t const * const buffer, uint32_t const size) { uint32_t ret = 0; while(ret<size) { while((Chip_UART_ReadLineStatus(pUART) & UART_LSR_THRE) == 0){} Chip_UART_SendByte(pUART, buffer[ret]); /* bytes written */ ret++; } return ret; }
/* Transmit a byte array through the UART peripheral (non-blocking) */ int Chip_UART_Send(LPC_USART_T *pUART, const void *data, int numBytes) { int sent = 0; uint8_t *p8 = (uint8_t *) data; /* Send until the transmit FIFO is full or out of bytes */ while ((sent < numBytes) && ((Chip_UART_ReadLineStatus(pUART) & UART_LSR_THRE) != 0)) { Chip_UART_SendByte(pUART, *p8); p8++; sent++; } return sent; }
extern ssize_t ciaaDriverUart_write(ciaaDevices_deviceType const * const device, uint8_t const * const buffer, size_t const size) { ssize_t ret = 0; if((device == ciaaDriverUartConst.devices[0]) || (device == ciaaDriverUartConst.devices[1]) || (device == ciaaDriverUartConst.devices[2]) ) { while((Chip_UART_ReadLineStatus((LPC_USART_T *)device->loLayer) & UART_LSR_THRE) && (ret < size)) { /* send first byte */ Chip_UART_SendByte((LPC_USART_T *)device->loLayer, buffer[ret]); /* bytes written */ ret++; } } return ret; }
void sendString_UART_USB_EDUCIAA(char message[], uint8_t size) { uint8_t msjIndex = 0; uint64_t i; /* sending byte by byte*/ while(( readStatus_UART_USB_EDUCIAA() != 0) && (msjIndex < size)) { Chip_UART_SendByte((LPC_USART_T *)LPC_USART2, message[msjIndex]); /*delay*/ for (i=0;i<50000;i++) { asm ("nop"); } msjIndex++; } }
void UARTUSB_Tx_sendByte(uint8_t byte){ Chip_UART_SendByte(LPC_USART2, byte); }
uint8_t WriteUART(uint8_t BYTE) { Chip_UART_SendByte((LPC_USART_T*)LPC_USART2, BYTE); }
/** \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; }
/* Sends a character on the UART */ void Board_UARTPutChar(char ch) { #if defined(DEBUG_ENABLE) while (Chip_UART_SendByte(DEBUG_UART, (uint8_t) ch) == ERROR) {} #endif }
void enviar_UART(char data_e) { Chip_UART_SendByte(LPC_USART2, data_e); }
uint8_t EnviarByte_UART(uint8_t dato) { Chip_UART_SendByte(LPC_USART2, dato); }
/** * @brief Application main function * @return Does not return * @note This function will not return */ int main(void) { uint32_t i; uint8_t repeat_num = UART_TEST_REPEAT_NUMBER; volatile int j = 1; uint8_t ch = 0; uint32_t IntStatus; /* Generic Initialization */ Board_Init(); Board_LED_Set(0, false); /* Disable UART1 IRQ */ NVIC_DisableIRQ(UART1_IRQn); /* Initialize the UARTs */ App_UART_Init(LPC_USART0); App_UART_Init(LPC_USART1); /* Custom Initialization */ Chip_UART_IntEnable(LPC_USART1, RXRDY_INT, DISABLE); Chip_UART_IntEnable(LPC_USART1, TXRDY_INT, DISABLE); NVIC_EnableIRQ(UART1_IRQn); /* Data transfer loop */ while (repeat_num--) { bufferInit(repeat_num); /* Sending from UART0 (polling mode) to UART1 (interrupt mode) */ receiveCompleted = false; Chip_UART_IntEnable(LPC_USART1, RXRDY_INT, ENABLE); for (i = 0; i < BUFFER_SIZE; i++) { while (Chip_UART_SendByte(LPC_USART0, TxBuf0[i]) != SUCCESS) {} } while (!receiveCompleted) {} /* Clear Rx FIFO */ Chip_UART_ReceiveByte(LPC_USART0, &ch); /* Sending from UART1 (interrupt mode) to UART0 (polling mode) */ sendCompleted = false; Chip_UART_IntEnable(LPC_USART1, TXRDY_INT, ENABLE); for (i = 0; i < BUFFER_SIZE; i++) { while (Chip_UART_ReceiveByte(LPC_USART0, &RxBuf0[i]) != SUCCESS) {} } while (!sendCompleted) {} bufferCheck(); } NVIC_DisableIRQ(UART1_IRQn); /* Test OK - Turn on Red LED */ Board_LED_Set(0, true); /* Should not return */ while (j) {} return 0; }