Reply by Carolina February 8, 20112011-02-08
Thanks Richard... It worked. For some reason my simulator shows UART2 and UART3 being powered on. I manually turned them on, and that did the job. I also found an error in the documentation. Table 56 shows that bits 24 and 25 are the ones in charge of turning on those peripherals but that is not that correct. The only way it works is if you set PCONP = 0x03100000.

Thanks again...

Carolina

An Engineer's Guide to the LPC2100 Series

Reply by rtstofer February 8, 20112011-02-08
--- In l..., "Carolina" wrote:
>
> Hello everyone,
>
> I am simply trying to use UART2 and UART3 to implement my printf function. I have tested my code with UART1 and UART0 and it works fine. However, when I change the settings for UART2 or UART3 it doesn't work. I was wondering if maybe in order to use those serial ports I need to add an extra step to my initialization. Please let me know.

Did you turn on the power for the peripherals? Table 56 of the User Manual

Did you turn on the clock for the peripherasl? Table 50 of the User Manual.

These two UARTs don't default to having the power 'on' and clock enabled - Table 56

Richard

Reply by Carolina February 8, 20112011-02-08
Hello everyone,

I am simply trying to use UART2 and UART3 to implement my printf function. I have tested my code with UART1 and UART0 and it works fine. However, when I change the settings for UART2 or UART3 it doesn't work. I was wondering if maybe in order to use those serial ports I need to add an extra step to my initialization. Please let me know.

#include /* LPC23xx definitions */

#define UART2 /* Use UART 0 for printf */

/* If UART 0 is used for printf */
#ifdef UART0
#define UxFDR U0FDR
#define UxLCR U0LCR
#define UxDLL U0DLL
#define UxDLM U0DLM
#define UxLSR U0LSR
#define UxTHR U0THR
#define UxRBR U0RBR
/* If UART 1 is used for printf */
#elif defined(UART1)
#define UxFDR U1FDR
#define UxLCR U1LCR
#define UxDLL U1DLL
#define UxDLM U1DLM
#define UxLSR U1LSR
#define UxTHR U1THR
#define UxRBR U1RBR
/* If UART 2 is used for printf */
#elif defined(UART2)
#define UxFDR U2FDR
#define UxLCR U2LCR
#define UxDLL U2DLL
#define UxDLM U2DLM
#define UxLSR U2LSR
#define UxTHR U2THR
#define UxRBR U2RBR
/* If UART 3 is used for printf */
#elif defined(UART3)
#define UxFDR U3FDR
#define UxLCR U3LCR
#define UxDLL U3DLL
#define UxDLM U3DLM
#define UxLSR U3LSR
#define UxTHR U3THR
#define UxRBR U3RBR
#endif

void init_serial (void) { /* Initialize Serial Interface */
#ifdef UART0
PINSEL0 |= 0x00000050; /* Enable TxD0 and RxD0 */
#elif defined (UART1)
PINSEL0 |= 0x40000000; /* Enable TxD1 */
PINSEL1 |= 0x00000001; /* Enable RxD1 */
#elif defined (UART2)
PINSEL0 |= 0x00500000; /* Enable TxD2 and RxD2 */
#elif defined (UART3)
PINSEL0 |= 0x0000000A; /* Enable TxD3 and RxD3 */
#endif
UxFDR = 0; /* Fractional divider not used */
UxLCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
UxDLL = 78; /* 9600 Baud Rate @ 12.0 MHZ PCLK */
UxDLM = 0; /* High divisor latch = 0 */
UxLCR = 0x03; /* DLAB = 0 */
}
/* Implementation of putchar (also used by printf function to output data) */
int sendchar (int ch) { /* Write character to Serial Port */

while (!(UxLSR & 0x20));

return (UxTHR = ch);
}
int getkey (void) { /* Read character from Serial Port */

while (!(UxLSR & 0x01));

return (UxRBR);
}