Hi,
I am wondering if there is any sample code setting up interrupts whenever the mailboxes receive new messages successfully.
I manage to have eCAN sending and receiving messages correctly, however, the receiving is currently done by pulling CANRMP
like,
while(ECanaRegs.CANRMP.all != 0xffff0000 ){}
ECanaRegs.CANRMP.all = 0xffff0000;
//copy data from the mailbox to somewhere in memory
As I read the manual, it is possible to set up an interrupt mechanism whenever CANRMP is set by the eCAN module. In addition to the old code, I added the interrupt register related code
EALLOW;
// ECanaRegs.CANMIM.all = 0xFFFFFFFF;
ECanaShadow.CANMIM.all = ECanaRegs.CANMIM.all;
ECanaShadow.CANMIM.bit.MIM16=1; //enable mailbox 16
ECanaRegs.CANMIM.all = ECanaShadow.CANMIM.all;
//mailbox interrupt mask register, Alfred
EDIS;
EALLOW;
//configure receiving to trigger interrupt
//enable INT1 of MBox16
ECanaShadow.CANMIL.all = ECanaRegs.CANMIL.all;
ECanaShadow.CANMIL.bit.MIL16=1; //enable eCAN1INT
ECanaRegs.CANMIL.all = ECanaShadow.CANMIL.all;
/*
//enable interrupt for MBox16
ECanaShadow.CANMIM.bit.MIM16=1;
ECanaRegs.CANMIM.all = ECanaShadow.CANMIM.all;
*/
//enable eCan1INT on GIM
ECanaShadow.CANGIM.all = 0;
ECanaShadow.CANGIM.bit.GIL = 1; //level INT1,
ECanaShadow.CANGIM.bit.I1EN = 1;
ECanaRegs.CANGIM.all = ECanaShadow.CANGIM.all;
PieVectTable.ECAN1INTA = &eCAN1INT_ISR;
// Configure PIE interrupts
PieCtrlRegs.PIECTRL.bit.ENPIE = 1; // Enable vector fetching from PIE block
PieCtrlRegs.PIEACK.bit.ACK9 = 1; // Enables PIE to drive a pulse into the CPU
// The interrupt can be asserted in either of the eCAN interrupt lines
// Comment out the unwanted line...
//PieCtrlRegs.PIEIER9.bit.INTx5 = 0; // Enable INTx.5 of INT9 (eCAN0INT)
PieCtrlRegs.PIEIER9.bit.INTx6 = 1; // Enable INTx.6 of INT9 (eCAN1INT)
EDIS;
// Configure system interrupts
IER |= 0x0100;
This is my ISR
interrupt void eCAN1INT_ISR(void) // eCAN
{
received++;
//clean the receive acknowledge bit
ECanaShadow.CANRMP.all = ECanaRegs.CANRMP.all;
ECanaRegs.CANRMP.all = ECanaShadow.CANRMP.all;
PieCtrlRegs.PIEACK.bit.ACK9 = 1; // Enables PIE to drive a pulse into the CPU
IER |= 0x0100; // Enable INT9
EINT;
return;
}
received is a global variable I declared. And I noticed that it is alway 0, that means interrupt never happened. I check the mailbox 16, and looks it receives the message correctly. I am so confused that why interrupt doesn't get triggered. What else in the million registers do I need to set?
When writing this code, I referred to multint2.c from spra876a I googled and downloaded.
Thanks!