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.

[PIC] UART RX Interrupt for PIC 18

Status
Not open for further replies.

qne

Newbie level 4
Newbie level 4
Joined
Oct 12, 2011
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,326
hello...

friends i am trying to do a task through serial interrupt..
problem is that intrrupt happend only once. code dsoent return from ISR to recieve new interrupt...
help...


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
// pic 18F452
// MiKroC for PIC
 
void main()
 {
 TRISC.f6 = 0;
 TRISC.f7 = 1;
 
 
 SPBRG = 15;                       //9600 BR with 10MHz
RCSTA.SPEN=1;                                // activate Rx pin)
TXSTA.TXEN=1;                                // Activate Tx pin Transmissiom
RCSTA.CREN=1;                                // Activate Reception
PIE1.RCIE=1;                                // Enable Reception interrupt
INTCON.GIE=1;                                // Enable Global interrupt
INTCON.PEIE=1;                                // Enable Peripheral interrup
 
 
while(1); // waiting for interrupt
 }
// ISR upon serial RX interrupt
 
void Interrupt()
{
PORTD = 0XAA;
delay_ms(100);
PORTD = 0XFF; 
PIR1.RCIF = 0;
}

 
Last edited by a moderator:

Your code is almost correct but it will only receive one character per 100mS, if you are sending at 9600 bauds you would expect to receive 960 characters per second (10 bits per character).
Remove the delay from the interrupt routine, in general you should never do anything to slow down an interrupt because while sitting in the delay routine, other interrupts could be missed. If you want PORTD to change to show when a character has been received, use the interrupt routine to set a variable and check it and reset it in the while() loop. You probably also want to read the RCREG inside the interrupt routine, even if you don't use the value elsewhere.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top