Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

LPC2000 UART code problem in Keil

Status
Not open for further replies.

Tamasco

Full Member level 3
Joined
Jun 27, 2006
Messages
155
Helped
10
Reputation
20
Reaction score
6
Trophy points
1,298
Activity points
2,083
lpc2000 uart

I wrote the following program for the NXP LPC2000 mcu. The progam compiles whenever i comment out the library header file #include <stdio.h> . But the problem is that it doesn't work when i load it! I guess it's because #include <stdio.h> has been commented out. The program is provided below.
I would appreciate it if u could help me out.
Thanks in advace.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

define CR 0x0D

#include <LPC21xx.H>

#include <stdio.h> //the program compiles when i comment this out!

#include <string.h>

//my function prototypes
void init_serial (void);
int putchar (int ch);
int getchar (void);




int main(void)
{
VPBDIV = 0x02; //Divide Pclk by two
init_serial();



while(1)
{

printf("Hello Engineer.... TEST UART-0\n"); // Call printf Function
printf("Press any key to continue....\n"); //Echo terminal
}
}

void init_serial (void) /* Initialize Serial Interface */
{
PINSEL0 = 0x00050000; /* Enable RxD1 and TxD1 */
U1LCR = 0x00000083; /* 8 bits, no Parity, 1 Stop bit */
U1DLL = 0x000000C2; /* 9600 Baud Rate @ 30MHz VPB Clock */
U1LCR = 0x00000003; /* DLAB = 0 */
}


int putchar (int ch) /* Write character to Serial Port */
{

if (ch == '\n') {
while (!(U1LSR & 0x20));
U1THR = CR; /* output CR */
}
while (!(U1LSR & 0x20));
return (U1THR = ch);
}


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

while (!(U1LSR & 0x01));

return (U1RBR);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
 

keil uart

what is this line doing here define CR 0x0D before #include. It must be after your #include declarations.
If you do that you program prints on the serial window.
My question is why are you not calling int putchar (int ch), and getch function. getchar() function is written but are not called from anywhere. what is the use of this. If you want to stop the printing when you type some character then make getchar() as a interrupt function
 
  • Like
Reactions: samba007

    Tamasco

    Points: 2
    Helpful Answer Positive Rating

    samba007

    Points: 2
    Helpful Answer Positive Rating
lpc2000 uart.c

Ok thank u for taking your time to go through my code and offering useful suggestions .

Added after 10 minutes:


I still have the same problem even after taking out the getchar() function and moving #define CR 0x0D below the header files.

Below is the file indicating the specific errors.
 

uart program in keil for lpc2129

I am able to compile the problem as I have selected the LPC2129, in keil. I am attaching the screen shot of successful compilation. Probably you might have added a wrong startup code, in program. Just change the target as 2129 and try. Ithink other problem I think is due to compiler problem. If this does not work I will suggest you something else to try.
 

    Tamasco

    Points: 2
    Helpful Answer Positive Rating
lpc2000

Thanks a lot once again. I tried selecting LPC2129 but still am having the same problems. Maybe it's because am using an evaluation version of keil. I'll check my start-up code and other settings.
 

function retarget keil

That is not a problem of compiler. Could you please load a example project and try to execute the program. It is not the problem of evaluation version. As I tried in the same. Please reinstall the keil once. or
1. first create a new project in a different folder and try to run the same program.
2. Create a new project open a new blank file. copy this file there and give save as in a different name. and try it.
I had these problem very long back I did few things out of which it worked for some trick.
Please update if it workes as i have to confirm the procedure for future.
 

    Tamasco

    Points: 2
    Helpful Answer Positive Rating
lpc2000 uart read line

Thanks ckshivaram.
I'll follow the steps and if it doesn't work i'll reinstall the software (uvision3). I'll give the updates.
 

code for uart0 in lpc2129

As per my PM to you if it does not work then it is compiler problem. Please try to execute the same in some other computer with keil 3 and cross verify. install keil from some other source not from what you installed in your system. I think some dll files got corrupted. reinstall it it will solve your problem.

bye
 

stdio.h library for keil

use retarget.c from c:\keil\arm\examples\retarget.c add this file
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top