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.

LPC1343 UART Not working in real hardware but working in Keil Simulator?

Status
Not open for further replies.

xpress_embedo

Advanced Member level 4
Joined
Jul 5, 2011
Messages
1,165
Helped
161
Reputation
396
Reaction score
191
Trophy points
1,353
Location
India
Activity points
10,575
Hello!! I am using Keil IDE along with MDK Compiler for ARM LPC1343 Programming.
I want to send some data on UART using LPC1343, i write a code but it is not working on Real Hardware, when i tried to debug it in Keil Simulator it works fine, what might be the problem, can anyone please help me.

Here is my Code:-

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <LPC13xx.h>
 
#define TEST_LED1       (1 << 11)
#define TEST_LED2       (1 << 10)
 
void UART_Init(void);
void UART_Write(unsigned char value);
void UART_Write_Text(unsigned char *msg);
unsigned char UART_Read(void);
 
void Delay_ms(unsigned int time)
{
    unsigned int i,j;
    for(i=0;i<time;i++)
    {
        for(j=0;j<1005;j++)
        ;
    }
}
int main()
{   
    unsigned char msg[] = "EDA BOARD\r\n";
    SystemCoreClockUpdate(); 
    /*Update SystemCoreClock according to register settings */
    
    UART_Init();
    Delay_ms(100);
    UART_Write_Text(msg);
    while(1)
    {
        UART_Write(UART_Read());
    }
}
 
/****************Function Definition**********/
void UART_Init(void)
{
    LPC_IOCON->PIO1_6 &= ~0x07;    /*UART I/O config*/
  LPC_IOCON->PIO1_6 |= 0x01;     /*UART RXD*/
  LPC_IOCON->PIO1_7 &= ~0x07;   
  LPC_IOCON->PIO1_7 |= 0x01;     /*UART TXD*/
    
  /*Enable UART clock*/
  LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12);
  LPC_SYSCON->UARTCLKDIV = 0x4;     /*divided by 4*/
    /*Core is Operating at 72MHz Hence UART is Operating at 72/4=18MHz*/
 
  LPC_UART->LCR = 0x83;             /*8 bits, no Parity, 1 Stop bit*/
    LPC_UART->DLM = 0x00;
  LPC_UART->DLL = 0x75;                         /*9600 bps Baud Rate*/
    LPC_UART->LCR = 0x03;                           /*DLAB = 0*/
  LPC_UART->FCR = 0x07;                         /*Enable and reset TX and RX FIFO*/
}
void UART_Write(unsigned char value)
{
    /*   
    THRE bit can be extracted by this U0LSR & 0x20
    THRE = 0 means data is present.
    THRE = 1 means register is empty.
    In order to transmit data, we have to wait will the THRE = 1,
    then only we can transmit data.
    */   
    while(!(LPC_UART->LSR&0x20));                        //THRE = 0 stay here
    LPC_UART->THR = value;
}
 
void UART_Write_Text(unsigned char *msg)
{
    while(*msg)
    {
        UART_Write(*msg);
        msg++;
    }
}
 
unsigned char UART_Read(void)
{
    /*
    Receiver Data Ready = U0LSR.0 bit
    RDR bit can be extracted by this U0LSR & 0x01
    RDR = 0 means no Data is Received in U0RBR
    RDR = 1 means that Data is present in U0RBR
    */
    while(!(LPC_UART->LSR & 0x01));                        //RDR = 0 stay here
    return (LPC_UART->RBR);
}
/*********************************************/



NOTE:- My Development Board is Ok, as i had tested it with Code written in CoIDE and GNU ARM Compiler, but it consist of UART drivers.
 
Last edited:

xpress_embedo

Advanced Member level 4
Joined
Jul 5, 2011
Messages
1,165
Helped
161
Reputation
396
Reaction score
191
Trophy points
1,353
Location
India
Activity points
10,575
After some R&D i found something new, I just replaced the startup_lpc13xx.s and system_lpc13xx.c files provided with Development Board Sample Code and my code works fine without any change.
I think startup_lpc13xx.s and system_lpc13xx.c must be same, i am not able to find any difference, can anyone please help me now.

Files are attached below, please help
View attachment Codes.zip
 

caiomarcos

Newbie level 4
Joined
Mar 5, 2012
Messages
7
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,283
Activity points
1,326
If you look closely, you will notice that they're not the same.
On the one that is not working the PLL startup routine is incorrect.
Look at lines 397 to 401 in system_LPC13xx.c of the working code and lines 389 to 391 of the not working one - it is missing a few lines in the PLL start up sequence. I believe the error is there.
 

xpress_embedo

Advanced Member level 4
Joined
Jul 5, 2011
Messages
1,165
Helped
161
Reputation
396
Reaction score
191
Trophy points
1,353
Location
India
Activity points
10,575
Thanks a lot but why it is so.

The working file is 2 year older than the Not Working File.
And i am using latest Keil Compiler and had copied the file directly from installation folder then why it is not working, can you please help me in this regard, i am new to arm and its really very complex for me.
 

caiomarcos

Newbie level 4
Joined
Mar 5, 2012
Messages
7
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,283
Activity points
1,326
I've been using the code supplied by NXP with the LPCXpresso, so I can only guess why one works while the other does not.

The datasheet states:
"In order for the update to take effect" after switching PLL input source "first write a zero to the SYSPLLUEN register and then write a one to SYSPLLUEN."

So it is not clear why it is necessary to write a 1, and only then a 0 and a 1 again, like is implemented in the working code. Also, it is not explicit that one would have to wait until it reads 1 from the register. It looks like the new file exactly follows the datasheet, leaving out those extras that are not obvious.

I'm also new to this and maybe those 'extras' are common practices while dealing with this kind of processes.
 

Aviorrr

Newbie level 1
Joined
Sep 2, 2017
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
4
LPC1343 UART Not working in real hardware but working in Keil

before you config uart use below commond:

LPC_SYSCON->SYSAHBCLKCTRL|= 1<<16;

I hope you would successful!!!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top