This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

simple printf demo won't work (MSB2300)

I am amazed at how much trouble I am having getting the simplest demo working. I have stripped everything out of the blinky demo so that I only test the printf capability and nothing comes out.

The simulation environment works, but using the MCB2300, I can't get any output.

First, here is my env:

IDE-Version:
µVision3 V3.80
Copyright (c) Keil Elektronik GmbH / Keil Software, Inc. 1995 - 2009

Tool Version Numbers:
Toolchain: RealView MDK-ARM Version: 3.50
Toolchain Path: BIN40\
C Compiler: Armcc.Exe V4.0.0.524 [Evaluation]
Assembler: Armasm.Exe V4.0.0.524 [Evaluation]
Linker/Locator: ArmLink.Exe V4.0.0.524 [Evaluation]
Librarian: ArmAr.Exe V4.0.0.524 [Evaluation]
Hex Converter: FromElf.Exe V4.0.0.524 [Evaluation]
CPU DLL: SARM.DLL V3.50
Dialog DLL: DARMP.DLL V1.44
Target DLL: BIN\UL2ARM.DLL V1.47
Dialog DLL: TARMP.DLL V1.44

Next, here is my code:

#include <stdio.h>
#include <LPC23xx.H> /* LPC23xx definitions */

struct __FILE { int handle; /* Add whatever you need here */ };
FILE __stdout;

#define UART1 /* 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
#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 */ #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)); U1THR = ch; return (UxTHR = ch);
}

int getkey (void) { /* Read character from Serial Port */

while (!(UxLSR & 0x01));

return (UxRBR);
}

int fputc(int ch, FILE *f) { return (sendchar(ch));
}

int ferror(FILE *f) { /* Your implementation of ferror */ return EOF;
}

void _ttywrch(int ch) { sendchar(ch);
}

void _sys_exit(int return_code) {
label: goto label; /* endless loop */
}

int main (void) {

init_serial(); /* Init UART */ while (1) { /* Loop forever */ printf ("Hello World\n\r"); }
}

It is pulled directly from the demo code.

As I said, it doesn't print anything out when I look ath the UART windows. It would not be possible to develop any real code without this capabilities.

I would very much appreciate any help that anyone can provide. I hope that I am just clueless.

Thanks

david

By the way, I have tried both UART0 and UART1

0