We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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
Sorry about the unreadable code - I just pasted it from source files. It was the middle of the night, so I got lazy -- again sorry. Let's first fix that:
#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)); 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"); } }
To your question about the source code line that you pointed out, please ignore it (I took it out here). It wasn't there before (and it didn't work). The reason that I put that line in is because I was having trouble with the debugger. I was trying to see if UxTHR was getting set with ch, but because it was inline with the return statement the watch window didn't appear to update correctly as I stepped through the code. After adding the line, I found that it still wasn't setting UxTHR, so it didn't provide any additional insight and then I forgot to remove it. Thank you for pointing out the error with the code.
I am still looking for a way to get printf working. Any help would be appreciated.