View previous topic :: View next topic |
Author |
Message |
seidleroni
Joined: 08 Sep 2008 Posts: 21
|
CAN Question: Can I have a general CAN transmit interrupt? |
Posted: Wed Nov 19, 2008 1:27 pm |
|
|
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
|
|
Posted: Wed Nov 19, 2008 2:04 pm |
|
|
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
|
|
Posted: Thu Nov 20, 2008 3:05 am |
|
|
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
|
|
Posted: Thu Nov 20, 2008 7:13 am |
|
|
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 |
|
|
|