I have this small example to initialise the UART of a LPC1549, 48 pins. This is a modification of the example supplied for the LPC1549 board from lpcopen_2_20_lpcxpresso_nxp_lpcxpresso_1549/periph_uart_rb
For whatever reason the Tx interrupts are being generated but nothing comes out on the Tx line.
I'm using Tx in PIO0_15 pin 23 and Rx in PIO0_14 pin 22.
Can someone spot what is missing? thanks
#include "chip.h"
#include "uart_15xx.h"
#include "string.h"
/*****************************************************************************
* Private types/enumerations/variables
****************************************************************************/
/* Enable this define to use integer clocking instead of the fractional baud
rate generator */
#define USE_INTEGER_CLOCK
/* Transmit and receive ring buffers */
STATIC RINGBUFF_T txring, rxring;
/* Ring buffer size */
#define UART_RB_SIZE 64
/* Set the default UART, IRQ number, and IRQ handler name */
#define LPC_USART LPC_USART0
#define LPC_IRQNUM UART0_IRQn
#define LPC_UARTHNDLR UART0_IRQHandler
/* Default baudrate for testing */
#define UART_TEST_DEFAULT_BAUDRATE 115200
/* Transmit and receive buffers */
static uint8_t rxbuff[UART_RB_SIZE], txbuff[UART_RB_SIZE];
/**
* @brief UART interrupt handler using ring buffers
* @return Nothing
*/
void UART0_IRQHandler(void)
{
/* Want to handle any errors? Do it here. */
/* Use default ring buffer handler. Override this with your own code if you need more capability. */
Chip_UART_IRQRBHandler(LPC_USART, &rxring, &txring);
}
static void Init_UART(void)
{
/* Disables pullups/pulldowns and enable digitial mode */
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 14, (IOCON_FUNC0 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 15, (IOCON_FUNC0 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
/* UART signal muxing via SWM */
Chip_SWM_MovablePortPinAssign(SWM_UART0_RXD_I, 0, 14);
Chip_SWM_MovablePortPinAssign(SWM_UART0_TXD_O, 0, 15);
/* Use main clock rate as base for UART baud rate divider */
Chip_Clock_SetUARTBaseClockRate(Chip_Clock_GetMainClockRate(), false);
/* Setup UART */
Chip_UART_Init(LPC_USART0);
Chip_UART_ConfigData(LPC_USART0, UART_CFG_DATALEN_8 | UART_CFG_PARITY_NONE | UART_CFG_STOPLEN_1);
Chip_UART_SetBaud(LPC_USART0, 115200);
Chip_UART_Enable(LPC_USART0);
Chip_UART_TXEnable(LPC_USART0);
}
/**
* @brief Main UART program body
* @return Always returns 1
*/
int main(void)
{
SystemCoreClockUpdate();
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_GPIO0);
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_MUX);
Chip_SYSCTL_PeriphReset(RESET_MUX);
Init_UART();
RingBuffer_Init(&rxring, rxbuff, 1, UART_RB_SIZE);
RingBuffer_Init(&txring, txbuff, 1, UART_RB_SIZE);
/* Enable receive data and line status interrupt */
Chip_UART_IntEnable (LPC_USART, UART_INTEN_RXRDY);
Chip_UART_IntDisable(LPC_USART, UART_INTEN_TXRDY);
/* Enable UART interrupt */
NVIC_EnableIRQ(UART0_IRQn);
while(1)
{
//Chip_UART_SendRB(LPC_USART, &txring, "Ola\n\r", 5);
Chip_UART_SendRB(LPC_USART, &txring, "U", 1);
}
return 1;
}
Hi,
I suppose that you do not enable the SWM and IOCON gated clock, pls set the bits 12 and 13 in SYSAHBCLKCTRL0 register with like SYSCON->SYSAHBCLKCTRL0|=1<<12|1<<13 instruction, for detailed format, pls check the register definition.
Hope it can help you
BR
XiangJun Rong
Thank you, that made it work
I just wonder if the example is missing that or if I didn't copy and paste properly...