CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC18F25K80 UART2 interrupt doesn't work

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ericj92



Joined: 09 Apr 2013
Posts: 2

View user's profile Send private message

PIC18F25K80 UART2 interrupt doesn't work
PostPosted: Tue Apr 09, 2013 2:49 am     Reply with quote

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
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Tue Apr 09, 2013 3:24 am     Reply with quote

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
Ericj92



Joined: 09 Apr 2013
Posts: 2

View user's profile Send private message

PostPosted: Tue Apr 09, 2013 3:46 am     Reply with quote

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
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Tue Apr 09, 2013 4:02 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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