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.

Arm interrupt and exception handler

Status
Not open for further replies.

embpic

Advanced Member level 3
Joined
May 29, 2013
Messages
742
Helped
80
Reputation
160
Reaction score
77
Trophy points
1,308
Location
india
Activity points
5,213
Hi
i am currently working on Arm7 lpc2148. but right now i am doing simple task but no idea regarding interrupt handler and exception handler.
n
facing peoblem with UART0 interrupt also if any one know plz help me and my code is


Code:
#include<lpc214x.h>

void uart0(void)__irq;
void init_uart0(void);
void Initialize(void);
void tx(unsigned char *);
unsigned int aa,r_data;

int main(void)
{
	Initialize();
	tx("Hello WOrld This is LPC2148");
//	tx(r_data);
	while(1);
}

void Initialize(void)
{
	VPBDIV = 0x00;
	PINSEL0 = 0x00000005;
	PINSEL1 = 0X00000000;
	PINSEL2 = 0X00000000;
	IO0SET = (1<<19);
	IO0DIR = 0xfffffff0;	  //61
	aa = 0;
	init_uart0();
}

void init_uart0(void)
{
	U0LCR = 0x83;
	U0DLL = 0x61;
	U0DLM = 0x00;
	U0FDR = 0x00000010;
	U0IER = 0x00000007;
//	U0FCR = 0x06;
	U0LCR &= 0x03;		
	U0FCR = 0x01;
	U0RBR = 0x00;
	U0THR = 0x00;
	VICIntEnable = 0x00000040;
	VICIntSelect = 0x00000000;
	VICVectCntl0 = 0x00000026;
	VICVectAddr0 = (unsigned long)uart0;
}

void uart0(void)__irq
{
//	IO0SET = (1<<16+aa);
//	aa++;
	IO0PIN ^=(1<<19);
	if(U0IIR & 0x40)
		r_data = U0RBR;
	VICVectAddr = 0x00;
}

void tx(unsigned char *stn)
{
	do
	{
		while(!(U0LSR & 0x20));
		U0THR = *stn++;
	}
		while(*stn!='\0');

}

no interrupt is generated and i want all three of interrupt.
thanzz in advance
 

i am using Keil compiler and arm7 lpc2148

- - - Updated - - -

what does FIFO actually do in rx and tx.
 

In your interrupt enable reg config you have just used both Tx and Rx interrupt. But for all the interrupts you jst read the data in ISR. What you need to do is to classify which intterrupt cause the ISR to run by means of U0IIR and do the necessay action. Or else just diable Tx interrupt and enable the Rx interrupts alone...
 

ok i have written following code but it skip 16-byte that is 16-character are get neglected in serial communication and my code is as follows
1st i will consider about simple Uart and after that i will use interrupt.

Code:
#include<lpc214x.h>

void initialize(void);
void tx_stn(unsigned char *);

#define XTAL 12000000
#define PCLK (XTAL/4)

void init_uart(void)
{
	U0RBR = 0x00;
	U0THR = 0x00;
	U0LCR = 0X83;
	U0DLL = 0x00000061;
	U0DLM = 0x00;
	U0FDR = 0x00000010;
	U0IER = 0x07;
	U0LCR &= 0X03;
//	U0FCR = 0x06;
	U0FCR = 0x01;
}


int main()
{
	initialize();
	tx_stn("Hello World how are you today !!!");
	while(1);
}

void initialize(void)
{
   PINSEL0 = 0x00000005;		    // Enable UART0 Rx and Tx pins
	init_uart();
}

void tx_stn(unsigned char *str)
{
	while(*str!='\0')
	{
		while(U0LSR & 0x20 == 0);
		U0THR = *str++;
	}
}
problems are:
1. i was trying to set baud rate at 9600 but get fixed at 496
2. 16 character get skipped due use of FIFO (i think).

- - - Updated - - -

ok i have written following code but it skip 16-byte that is 16-character are get neglected in serial communication and my code is as follows
1st i will consider about simple Uart and after that i will use interrupt.

Code:
#include<lpc214x.h>

void initialize(void);
void tx_stn(unsigned char *);

#define XTAL 12000000
#define PCLK (XTAL/4)

void init_uart(void)
{
	U0RBR = 0x00;
	U0THR = 0x00;
	U0LCR = 0X83;
	U0DLL = 0x00000061;
	U0DLM = 0x00;
	U0FDR = 0x00000010;
	U0IER = 0x07;
	U0LCR &= 0X03;
//	U0FCR = 0x06;
	U0FCR = 0x01;
}


int main()
{
	initialize();
	tx_stn("Hello World how are you today !!!");
	while(1);
}

void initialize(void)
{
   PINSEL0 = 0x00000005;		    // Enable UART0 Rx and Tx pins
	init_uart();
}

void tx_stn(unsigned char *str)
{
	while(*str!='\0')
	{
		while(U0LSR & 0x20 == 0);
		U0THR = *str++;
	}
}
problems are:
1. i was trying to set baud rate at 9600 but get fixed at 496
2. 16 character get skipped due use of FIFO (i think).
 

i am using Keil compiler and arm7 lpc2148

- - - Updated - - -

what does FIFO actually do in rx and tx.

Actually FIFO is just a queue... What ever we write in the U0THR and the data received in U0RBR will continously written on to the queue...
When ever all data in Tx queue gets completely transmitted, It rises the interrupt Tx FIFO empty...
And vice versa for Rx...
(i.e the data continously received in FIFO and if you don't read it by U0RBR, the Rx FIFO full interrupt will be triggerred...)

To manage the interrupt properly just integrate Line status register, Interruput Identification register in the ISR for proper Tx and Rx...
 

problems are:
1. i was trying to set baud rate at 9600 but get fixed at 496
2. 16 character get skipped due use of FIFO (i think).

THRE bit is high if THR(FIFO) is not full (but not means fully empty)..
 

thanx venkadeshm & mathespbe i will improve this routine

- - - Updated - - -

thanx for guidance but can't configure and adjust the FIFO prperly so plz give some guidance again i restart the code and very simply i written routine but same problem plz help
Code:
#include<lpc214x.h>

void uart_init(void);
void init(void);
void tx_stn(unsigned char *);
void rx_stn(void);


int main()
{
	init();
	tx_stn("Hello World how are you today2");
//	rx_stn();
	while(1);
	{
			
	}
}
	
void init(void)
{
	VPBDIV = 0x00;
	PINSEL0 = 0x00000005;
	uart_init();
}

void uart_init(void)
{
		U0LCR = 0x83;
	U0DLL = 0x61;
	U0DLM = 0x00;
	U0LCR &= 0x03;
//	U0FCR = 0x01;
}

void tx_stn(unsigned char *stn)
{
	do
	{
		U0THR = *stn++;
		while(U0LSR & 0x40==0);			
	}while(*stn!='\0');
}

void rx_stn(void)
{
unsigned char aa;
		do
		{
				aa = U0RBR;
			if(aa=='a')
			{
				IO0SET = (1<<18);
			}
		}while(aa!='b');
}

plz provide some explanation
thnxz
 

Hi here is the working program with 12MHZ and 9600Baud rate Its a small mistake
94820d1376395179-untitled.jpg


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
#include<lpc21xx.h>
 
void uart_init(void);
void init(void);
void tx_stn(unsigned char *);
void rx_stn(void);
 
 
int main()
{
    init();
 
    while(1)
    {
    tx_stn("Hello World how are you today2");
    rx_stn();       
    }
}
    
void init(void)
{
    PLLCON  = 0x00;    //disable PLL
    PLLFEED = 0xAA;
    PLLFEED = 0x55;
    VPBDIV  = 0x02;   //pclk = CCLK/4 and CCLK = Fosc
    PINSEL0 = 0x00000005;
    uart_init();
}
 
void uart_init(void)
{
    U0LCR = 0x83;
    U0DLL = 39;
    U0DLM = 0x00;
    U0LCR = 0x03;
}
 
void tx_stn(unsigned char *stn)
{
    do
    {
        U0THR = *stn++;
        while((U0LSR & 0x40) == 0);  //Here is your fault
                
    }while(*stn!='\0');
}
 
void rx_stn(void)
{
unsigned char a;
 
do{
while(!(U0LSR & 01));
a = U0RBR;
 
if(a=='a')
IO0SET = (1<<18);
 
}while(a!='z');
 
}

 

Attachments

  • untitled.JPG
    untitled.JPG
    64.4 KB · Views: 124

thanx for transmitter function it works properly for me also. and sorry for receiver code in above example it is wrong
but still confusion regarding FIFO for rx and Tx. if u have any explanation or flow of data plz upload .

whether These FIFO are accessible? if? how?
 

Ok I will post the same operation with FIFO and explain how it works.....

- - - Updated - - -


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
#include<lpc21xx.h>
 
void uart_init(void);
void init(void);
void tx_stn(unsigned char *);
 
 
int main()
{
    init();
    
    tx_stn("Hello World how are you today2"); 
    
    while(1)
    {
    }
}
    
void init(void)
{
    PLLCON  = 0x00;    //disable PLL
    PLLFEED = 0xAA;
    PLLFEED = 0x55;
    VPBDIV  = 0x02;   //pclk = CCLK/2 and CCLK = Fosc
    PINSEL0 = 0x00000005;
    uart_init();
}
 
void uart_init(void)
{
    U0LCR = 0x83;
    U0DLL = 39;
    U0DLM = 0x00;
    U0LCR = 0x03;
    U0FCR = 0x07;        // Extra line
}
 
void tx_stn(unsigned char *stn)
{
    int i;
    
    do{
    
        for( i = 0; i < 16 && *stn != '\0' ; i++)
    
        U0THR = *stn++;         // Put 16 datas on the buffer
                       
        while( ! (U0LSR & 0x40) );  // Wait for all of them to transmit
    
    } (*stn != '\0' )           // do this until all data transmitted
    
}



- - - Updated - - -

We are putting 16 chars at a time on the fifo because 16 is the size of fifo.
 
  • Like
Reactions: embpic

    embpic

    Points: 2
    Helpful Answer Positive Rating
thank you sir for providing example for FIFO. and how to add interrupt for transmitter for sending data rather than waiting for data to send. i had tried and i have written for rx.
is there required delay while sending data OR
use this method use instead of interrupt.
 

thank you sir for providing example for FIFO. and how to add interrupt for transmitter for sending data rather than waiting for data to send. i had tried and i have written for rx.
is there required delay while sending data OR
use this method use instead of interrupt.
Go and look at the #3 That has the ISR function..
 

yes sir but as i seen u have send data through isr also and using interrupt also at both places u are puuting data in tx buffer as
HTML:
void sio_irq (void) __irq 
{
  volatile char IIR;

  IIR = U1IIR;
	
       if ( (IIR & 0x0E) == 0x02 )
			 if ( i <= size ) 
				 {
           U1THR = tx[i%TXSIZE];                          //here also u are putting data in Tx buffer
           i++;
         }
				 
  VICVectAddr = 0; /* Acknowledge Interrupt */
}


void transmit(const char *str,int siz)
{
	int j;
  
	U1IER &= ~2;
	
	if(i >= size)
	{
	for(j = 0; j < siz; j++)
	tx[j%TXSIZE] = str[j];
	i = 0;
	size = siz;
	
	U1THR = tx[i%TXSIZE];                                  // here also u r putting data
	i++;
	}
	else
	{
	for(j = 0; j < siz; j++)
	tx[(j+size)%TXSIZE] = str[j];
	size = siz + size;
	}
	
	U1IER |= 2;
}

means from where data is actually sending.
thanx

- - - Updated - - -

sorry u are sending data from isr and from other function which is not called in isr which is called from while loop. independent of isr.
 
Last edited:

sending the data in in transmit function is to initiate the transmission... After once initiated the process will be continued with the ISR...
 

ok thanx sir really it helps me.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top