![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Ericj92
Joined: 09 Apr 2013 Posts: 2
|
PIC18F25K80 UART2 interrupt doesn't work |
Posted: Tue Apr 09, 2013 2:49 am |
|
|
Hello,
I'm working with a PIC18F25K80 at the moment and I'm trying to detect a interrupt caused by the internal EUSART2 module of this PIC. But I'm encountering some problems.
I just wrote some basic code to check if an interrupt has occured on the RS232 communication at any given time, just to make sure that the interrupt function is called.
Code: | .
#include <18F25k80.h>
//#DEVICE HIGH_INTS=TRUE // enable interrupts
#DEVICE ADC=10
#fuses HSH,NOWDT,BROWNOUT,PUT,NOPLLEN,SOSC_DIG,NOIESO,NOFCMEN,CANB
#include <STDLIB.H>
#include <math.h>
#use delay(clock=16000000)
#use rs232(BAUD=9600,BRGH1OK,PARITY=N, BITS=8, ERRORS, STOP=1,UART2 )
int8 bMessageComplete = 0;
#int_rda //RS232 data ready
// highest priority interrupt HIGH or FAST
void isr_serial () // RS232 interrupt function
{
bMessageComplete=1;
}
void main() {
// enable the right interrupts
clear_interrupt(INT_RDA);
enable_interrupts(INT_RDA);
enable_interrupts(global);
// A LED is connect to this output and is made high, to shut it down.
output_high(PIN_C2);
while(true){
if(bMessageComplete==1){
// if an interrupt has occured, the variable bMessageComplete equals true
// the LED connect to C2 and will light up.
output_low(PIN_C2);
}
}
}
|
The PIC is connected to a PCB by a MAX3381 chip connected to a COM-port.
It is a software problem, it seems that the interrupt isn't enabled. I tested the hardware and all connections are right. The functions getc() and putc() can be used and with hyperterminal I can receive and transmit data.
The compiler version I used is 4.1.24.
Who can help me to figure this out?
Eric |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19359
|
|
Posted: Tue Apr 09, 2013 3:24 am |
|
|
Er....
INT_RDA, is UART1
INT_RDA2, is UART2.......
Second comment.
The serial receive function _must_ read the character, or it cannot exit.
The interrupt can't be cleared, till the character is read, so unless you read the character the interrupt will trigger for ever.
Third comment.
You haven't set the interrupt to be HIGH priority. There is no point in using HIGH, unless you have other interrupts. If you do, there is a caveat, that INT_EXT, will always be a high priority interrupt.
HIGH, and FAST are the same 'priority wise'. Difference is that FAST relies on only saving the registers automatically stored, and doesn't save anything else. You cannot therefore use this _unless_ you save any other registers used, and can never have more than one interrupt using FAST (so if INT_EXT is used, FAST cannot be used). The compiler will automatically switch an interrupt defined as 'FAST', to 'HIGH' if this happens. You could not use FAST to handle an interrupt putting data into a buffer, since the table pointers won't then be saved.....
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Ericj92
Joined: 09 Apr 2013 Posts: 2
|
|
Posted: Tue Apr 09, 2013 3:46 am |
|
|
thank you for the very fast response. I set the high priority interrupts, changed every int_rda to int_rda2 and added a getc() in the interrupt routine, now everything works as I expected.
The helpfile doesn't properly declare what the function of the int_rdax interrupts are.
Sincerly,
Eric |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19359
|
|
Posted: Tue Apr 09, 2013 4:02 am |
|
|
It assumes a degree of 'pre-knowledge' of the PIC.
Minimum extra reading, beyond the manual, is:
1) K&R. The 'bible' of C. 90% of CCS is standard, and this is necessary.
2) The chip data sheet.
3) The application notes for the peripherals.
4) The processor .h file
5) The examples.
Then you start with a chance.....
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|