interrupt MSCAN illegal bp - M68EVB912DP256  MC9S12DP256

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

interrupt MSCAN illegal bp - M68EVB912DP256  MC9S12DP256

2,228 Views
Seitec
Contributor III
Hello
I have problem with my interrupt, at the end of interrupt, jump to command Illegal BP and asm BGND.
 
Do anybody know please, where is problem?
Thank you very much to all.
void interrupt 39 Tx_CAN0(unsigned long id, unsigned char Priority, unsigned char length, unsigned char *Data){
 
unsigned volatile char i, buf_num;
unsigned char ERR_BUFFER_FULL = 'E';
if(!CAN0TFLG)                         /*transmi buffer empty? TXEx*/
    //return ERR_BUFFER_FULL;
CAN0TIER = 0x00;                      /*TXEIE 0 - no interrupt request*/
buf_num = CAN0TFLG;                    /*ulozeni volnych buffer*/
CAN0TBSEL = buf_num;                   /*TXx dany buffer je vybran*/
buf_num = CAN0TBSEL;

*((unsigned long *) ((unsigned long)(&CAN0TXIDR0))) = id;  /*nastaveni id*/
for(i=0; i<length;i++){
 *(&CAN0TXDSR0 + i) = Data[i];       /*kopirovani zpravy*/
 }
 CAN0TXDLR = length;                         /*nastaveni delky*/
 
 CAN0TXTBPR = Priority;                /*nastaveni priority*/
 
 CAN0TFLG = buf_num;                         /*transmit dat*/
 
 while((CAN0TFLG & buf_num) != buf_num);   /*počká na konec přenosu*/
}  /*konec preruseni*/
 
 
Added p/n to subject.


Message Edited by NLFSJ on 2008-12-01 11:19 AM
Labels (1)
0 Kudos
7 Replies

464 Views
Lundin
Senior Contributor IV
It might be wise to tell which mcu and compiler you are using.

First of all: what kind of interrupt is that?! I have never heard of a computer that accepts parameters to an ISR. It sounds very likely that this is the source of the error, it seems like you managed to trick the compiler to compile the code as an ordinary function, instead of as an isr. Then you will get a "return from subroutine" instruction instead of a "return from interrupt" and the program will crash.

if(!CAN0TFLG) /*transmi buffer empty? TXEx*/
//return ERR_BUFFER_FULL;
CAN0TIER = 0x00; /*TXEIE 0 - no interrupt request*/


The above will disable the interrupt if the buffer that caused the interrupt is empty. Is this intentional? It surely looks suspicious. If you use {} for your C statements you won't get these kind of potential bugs and the program will be easier to read.
0 Kudos

464 Views
Seitec
Contributor III
I am sorry.
M68EVB912DP256  MC9S12DP256. CodeWarrior Development Studio IDE version 5.9.0   Build 2830.
 I repair it upon this code:
 
void interrupt 39 Tx_CAN0(void)
{
 
unsigned volatile char i, buf_num;

if(!CAN0TFLG) printf("error");                        /*transmi buffer empty? TXEx*/
 
buf_num = CAN0TFLG;                    /*ulozeni volnych buffer*/
CAN0TBSEL = buf_num;                   /*TXx dany buffer je vybran*/
buf_num = CAN0TBSEL;

*((unsigned long *) ((unsigned long)(&CAN0TXIDR0))) = id;  /*nastaveni id*/
for(i=0; i<length;i++)
{
 *(&CAN0TXDSR0 + i) = Data[i];       /*kopirovani zpravy*/
 }
 CAN0TXDLR = length;                         /*nastaveni delky*/
 
 CAN0TXTBPR = Priority;                /*nastaveni priority*/
 
 CAN0TFLG = buf_num;                         /*transmit dat*/
 
 while((CAN0TFLG & buf_num) != buf_num);   /*počká na konec přenosu*/
}  /*here start ILLEGAL BP and BGND */
Thank you very much Lundin, it is interrupt for MSCAN transmit.
 
 
But problem persist.
0 Kudos

464 Views
Lundin
Senior Contributor IV
Note that all those variables you had as parameters must now be global, and that all global variables that are accessed by both main() and interrupts must be made volatile.

Regarding your problem, try changing this:

void interrupt 39 Tx_CAN0(void)

into this:

#pragma TRAP_PROC
void Tx_CAN0(void)


Also disassemble the code and make sure that the code generated for the isr ends with asm instruction RTI and not RTS or RTC. In case of the latter two, the program will crash.

The program will also crash if you try to call an interrupt from main() as a plain function.
0 Kudos

464 Views
Seitec
Contributor III
I do this
#pragma TRAP_PROC
void Tx_CAN0(void){
 
unsigned volatile char i, buf_num;
unsigned char ERR_BUFFER_FULL = 'E';
//if(!CAN0TFLG) printf("error");                        /*transmi buffer empty? TXEx*/
buf_num = CAN0TFLG;                    /*ulozeni volnych buffer*/
CAN0TBSEL = buf_num;                   /*TXx dany buffer je vybran*/
buf_num = CAN0TBSEL;

*((unsigned long *) ((unsigned long)(&CAN0TXIDR0))) = id;  /*nastaveni id*/
for(i=0; i<length;i++){
 *(&CAN0TXDSR0 + i) = Data[i];       /*kopirovani zpravy*/
 }
 CAN0TXDLR = length;                         /*nastaveni delky*/
 
 CAN0TXTBPR = Priority;                /*nastaveni priority*/
 
 CAN0TFLG = buf_num;                         /*transmit dat*/
 
 while((CAN0TFLG & buf_num) != buf_num);   /*poèká na konec pøenosu*/
}  /*konec preruseni*/
 
 
and in prm file I wrote VECTOR ADDRESS 0x0000ffb0 Tx_CAN0
 
But how I can call or invoke this interrupt?
Thank you very much  Lundin.
0 Kudos

464 Views
Seitec
Contributor III
oh I am stupid,
ok I try it.
But my problem persist. At the end of interrupt, jump to Illegal Bp and BGND.
 
I am control memory 0x0000ffb0 i saw there was address of Tx_CAN0. But it jump to BGND.
Do anybody know please where could be error?
0 Kudos

464 Views
Lundin
Senior Contributor IV
- You don't call interrupts, the hardware calls them. This is the whole point of using interrupts.

- If you attempt to call an isr as if it was an ordinary function, your program will crash.

- Did you disassemble the code as I suggested to make sure that the interrupt ends with RTI?

- Did you place the isr in non-banked flash?
0 Kudos

464 Views
Seitec
Contributor III
Hello
yes interrupt ends with RTI and it is not in banked memory.
 
Thank you very much Ludin.
0 Kudos