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

CAN Question: Can I have a general CAN transmit interrupt?

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



Joined: 08 Sep 2008
Posts: 21

View user's profile Send private message

CAN Question: Can I have a general CAN transmit interrupt?
PostPosted: Wed Nov 19, 2008 1:27 pm     Reply with quote

Is it possible to just have ONE CAN transmit interrupt rather than creating interrupt service routines for all 3 transmit interrupts (CANTX0,CANTX1,CANTX2)?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 19, 2008 2:04 pm     Reply with quote

You could probably use #int_default to do this. Here's some sample
code that I think will work. I haven't test this in hardware, so you
need to test it if you want to use it.
Code:

#include <18F4580.h>
#fuses HS,NOWDT,BROWNOUT,PUT,NOLVP
#use delay (clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)


#byte PIE3 = 0xFA3
#bit TXB0IE = PIE3.2
#bit TXB1IE = PIE3.3
#bit TXB2IE = PIE3.4

#byte PIR3 = 0xFA4
#bit TXB0IF = PIR3.2
#bit TXB1IF = PIR3.3
#bit TXB2IF = PIR3.4

#INT_DEFAULT
void cantx_isr(void)
{
if(TXB0IE)
   if(TXB0IF)
     {
       // Insert code to handle CANTX0 interrupt


      clear_interrupt(INT_CANTX0);
     }

if(TXB1IE)
   if(TXB1IF)
     {
       // Insert code to handle CANTX1 interrupt

      clear_interrupt(INT_CANTX1);
     }


if(TXB2IE)
   if(TXB2IF)
     {
       // Insert code to handle CANTX2 interrupt


      clear_interrupt(INT_CANTX2);
     }


}

//=================================
void main()
{
enable_interrupts(INT_CANTX0);
enable_interrupts(INT_CANTX1);
enable_interrupts(INT_CANTX2);

enable_interrupts(GLOBAL);


while(1);
}
Ttelmah
Guest







PostPosted: Thu Nov 20, 2008 3:05 am     Reply with quote

Remember you will also have to add code to save/restore any registers used in your routines, if going this route. There is an example, showing just saving a few minimal registers, but the number involved will rise significantly if your code is at all complex...
Obviously, since the bits are in the same register, you could just perform a single 'and' operation like:
Code:

if (PIR3 & 0b011100) {
    //Here _one_ of the CAN interrupts has triggered.

}

To get a 'single' interrupt handler being called, but since the handling will be different in parts, having separate routines, 'makes sense'.

Best Wishes
seidleroni



Joined: 08 Sep 2008
Posts: 21

View user's profile Send private message

PostPosted: Thu Nov 20, 2008 7:13 am     Reply with quote

Thank you both for your help. I think I will just go and use 3 separate routines (which works fine). Thank you for your help
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