MSCAN double Rx interrupt

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

MSCAN double Rx interrupt

1,282 Views
sebasira
Senior Contributor I

Hello everybody!

 

I'm trying to get to know the MSCAN module, so I've done a simple test program. It's based on the MSCAN Driver and some Application Notes from Freescale (AN2283)... It's done for the DEMOJM board so if you have one, you can try it.

 

The problem I'm having is that the CAN Rx ISR is executed 2 times... in both it receives the same data... the question is... Am I transmitting 2 times or it just receiving 2 times?...

 

As you can see, I clear the CANRFLG twice.. Why? because if I put a break in the first clear instruction and step it, you could see that the falg remains set, but after the second clear it clears. But if I disable that breakpoint and just let it run, the ISR is executed twice... This makes me think that I transmitt twice...

 

There is a variable named "pepe" wich is initialized as 0, and then incremented in every CAN data read... 

 

 

For a quick start:

- Button PTG0 sends out data (3 bytes 0x17 0x05 0x85) and toggles PTE2 LED

- Button PTG1 sends out data (3 bytes 0x13 0x10 0x59) and toggles PTE3 LED

 

I'd appreciate if you could check the MSCAN routines, in MSCAN.c... I guess that's where the problem is

 

 

Thank you very much!!!

 

CAN_v1.zip

Message Edited by t.dowe on 2009-09-29 10:15 AM
Labels (1)
0 Kudos
3 Replies

315 Views
kef
Specialist I

In main() you have this:

 

        MSCAN_buffer = CAN_LoadBuffer_SID(1);         // Cargar el Elemento 0 de la Tabla de 
        CAN_Transmit_Buffer(MSCAN_buffer);            // Transmitir el Buffer de MSCAN que se cargo

 

CAN_LoadBuffer_SID() is sending clearing selected buffer CANFTLG flag:

 

        CANTFLG = CANTBSEL;                               // Buffer seleccionado no esta mas EMPTY, ahora

 

CAN_Transmit_Buffer() enables TX interrupt. When CANTFLG flag becomes set, TX ISR gets called, which clears CANTFLG flag and Tx buffer is resent. 

Message Edited by kef on 2009-09-28 10:21 PM
0 Kudos

315 Views
sebasira
Senior Contributor I

Well Thanks Kef!

 

So I've got a doubt.... How can I do to send data via Tx ISR?

 

If I do not understand you wrong, inside CAN_LoadBuffer_SID() I'm transmitting data when I do the following:

CANTFLG = CANTBSEL

 

And then inside CAN_Transmit_Buffer() when I enable de Transmit Buffer Interrupt, it sends data again, because the flag in CANTFLG is set since that buffer is empt... is that right?

 

 

I guess that in order to do what I want to do (transmit data in Tx ISR), I will have to put  CAN_LoadBuffer_SID() inside Tx ISR...

 

Thanks in advance!!

0 Kudos

315 Views
kef
Specialist I

If you want or have to use TX interrupts, then TX ISR should pull data from TX FIFO and send pulled data. When your app is going to send message, some foreground task should push messages to FIFO and enable one or more TX interrupts.

0 Kudos