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.

LPC2103 UART0 Interrupt Problem

Status
Not open for further replies.

rituparnasaikia

Member level 3
Joined
Feb 1, 2006
Messages
57
Helped
3
Reputation
6
Reaction score
0
Trophy points
1,286
Location
Bangalore, India
Activity points
1,696
I have failed generating UART0 interrupt for LPC2103 in Keil Compiler. I can send data using pooling method.

Bellow is the 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include <lpc210x.h>
#define     Fpclk       11059200/4
#define     UART_BPS    9600                                         /*  ???????              */
#define     LN          30
volatile    char RcvNew;                                            /*  ??????????        */
char RcvBuf[LN]={0};                                       /*  ?????????          */
int RcvNum;                                                     /*  ?????????          */
 
/*********************************************************************************************************
** Function name:       DelayNS
** Descriptions:        
** input parameters:    uiDly   ???,??????
** output parameters:   ?
** Returned value:      ?
*********************************************************************************************************/
void DelayNS (int uiDly)
{
    int i;
    
    for (; uiDly > 0; uiDly--){
        for(i = 0; i < 50000; i++);
    }
}
 
enum OptCodeType {PUSH,POP,CLR,CHECK};
int SentFIFO(int OptCode,char OptNum)
{     
    #define FIFO_Size 32
    static char FIFO[FIFO_Size],ptIN,ptOUT;
    switch(OptCode)
    {
        case PUSH :
        if(ptIN==(ptOUT+1)) return 0 ;
        else FIFO[(ptIN++)%FIFO_Size]=OptNum;   
        return  1; 
 
        
        case POP :
        if(ptIN==ptOUT) return(0);
        else return(FIFO[(ptOUT++)%FIFO_Size]);
 
        
        case CLR :
        ptOUT=ptIN;
        return 1;
 
        
        case CHECK:
        if(ptOUT>ptIN) return(ptOUT-ptIN);
        else return (ptIN-ptOUT);
 
        default:
        return 0;
    }
    
}
 
/*********************************************************************************************************
** Function name:       UART0_IRQ
** Descriptions:        ????????
** input parameters:    ?
** output parameters:   ?
** Returned value:      ?
*********************************************************************************************************/
void __irq UART0_IRQ (void)
{
    int i;   
    while ((U0IIR & 0x01) == 0)
    {                                                                       /*  ?????????          */
        switch (U0IIR & 0x0E)
        {                                                                  /*  ??????                */
        
            case 0x04: 
            {                                                            /*  ??????                */
               RcvNew = 1;                                          /*  ????????            */
                for (i= 0; i < 8; i++)                                                       /*  ????8???             */
                    if(RcvNum<LN)
                        RcvBuf[RcvNum++] = U0RBR;
                    
            }
            break;
            
            case 0x0C:                                                         /*  ??????                */
                RcvNew = 1;
                while ((U0LSR & 0x01) == 0x01)
                {                                                        /*  ??????????        */ 
                 if(RcvNum<LN)              RcvBuf[RcvNum++] = U0RBR;
                                        
                }   
                break;
 
            case 0x02:
                
                
            default:
                break;
        }
 
    }
   
   VICVectAddr = 0x00;
   
}
 
/*********************************************************************************************************
** Function name:       UARTInit
** Descriptions:        ?????,???8????,1????,?????,????115200
** input parameters:    uiDly   ???,??????
** output parameters:   ?
** Returned value:      ?
*********************************************************************************************************/
void UARTInit (void)
{
    int uiFdiv; 
    U0LCR  = 0x83;                                                      /*  ???????              */
    uiFdiv = (Fpclk / 16) / UART_BPS;                                   /*  ?????*/
    U0DLM  = uiFdiv / 256;
    U0DLL  = uiFdiv % 256; 
    U0LCR  = 0x03;                                                      /*  ?????                  */
}
 
/*********************************************************************************************************
** Function name:       UART0SendByte
** Descriptions:        ?????????,?????????,??????
** input parameters:    uiDat   ??????
** output parameters:   ?
** Returned value:      ?
*********************************************************************************************************/
void UART0SendByte (char uiDat)
{
    U0THR = uiDat;                                                      /*  ????                    */
    while ((U0LSR & 0x20) == 0);                                        /*  ????????            */
}
 
/*********************************************************************************************************
** Function name:       UART0SendStr
** Descriptions:        ????????
** input parameters:    uiStr   ?????????
**                      uiRcvNum   ????????
** output parameters:   ?
** Returned value:      ?
***************************************************************************************8****************/
void UART0SendStr(char const *uiStr)
{
while( *uiStr)                              /*  ?????????           */
        UART0SendByte (*uiStr++);
    //  UART0SendByte ('\r');
//      UART0SendByte ('\n');
 
}
 
/*********************************************************************************************************
** Function name:       main
** Descriptions:        ??JP6??,????????,??0??????
** input parameters:    ?
** output parameters:   ?
** Returned value:      ?
*********************************************************************************************************/
int main (void)
{
    int i;
    PINSEL0 = PINSEL0 & (~0x0F);                                        
    PINSEL0 = PINSEL0 | 0x05;                                           /*  ??I/O???UART           */
    
    RcvNew = 0;
    UARTInit ();                                                        /*  ?????                  */
    U0FCR = 0x81;                                                       /*  ??FIFO,??8?????? */
    U0IER = 0x01;                                                       /*  ??????                */
    
   // IRQEnable ();
    
    VICIntSelect = 0x00000000;                                          /*  ???????????      */
    VICVectCntl0 = 0x20 | 0x06;                                         /*  ????????????    */
    VICVectAddr0 = (int)UART0_IRQ;                                      /*  ??????                */
    VICIntEnable = 1 << 0x06;                                           /*  ??????                */
    
    UART0SendStr ("==================Hello! ZhiHui Chengjiang======================\n");
    UART0SendStr ("ARM: I'm ready now,sent me the massage!\n");
    while (1){
        if (RcvNew == 1)
        {                                                        /*  ????????            */
            RcvNew = 0;                                          /*  ????                    */
            UART0SendStr (RcvBuf);                              /*  ???????              */
            for(i=0;i<LN;i++)
                RcvBuf[i]=0;
            RcvNum=0;
        }
    }
  return 0;
}

 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top