Questions about the interrupt of MSCAN in MC9S12XDP512

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

Questions about the interrupt of MSCAN in MC9S12XDP512

2,145 Views
lwjtutu
Contributor I
 I am now doing a research on gateway of CAN bus.Inorder to test whether the developing board made by myself is correct, the CAN0 is set to work in the LOOPBACK mode.
         The datasheet said that "Both transmit and receive interrupts are generated"in the LOOPBACK mode. But when I clear the TFLG, it doesn't change and when the receiving buffer receives a message, the RFLG is still zero.why?
      Another problem is: when the TFLG is 1, the interrupt occurs. But after reset, the TFLG is always 1. If i clear the flag  manully, this flag can not be change any more. Because the datasheet said"Read and write accesses to the transmit buffer will be blocked, if the corresponding TXEx bit is cleared
(TXEx = 0)".
   The two  questions have bothered me for several days.
Labels (1)
0 Kudos
4 Replies

621 Views
lwjtutu
Contributor I
The problems have been solved. Thanks.:smileywink:
0 Kudos

621 Views
lwjtutu
Contributor I
Thanks for your patience and sorry not to write the full name of the registers. You are right.The RFLG is the CANRFLG  and the TFLG is the CANTFLG. Processor expert is used in this project. All the initialization is done by the PE.
   Afrer reset, the TXE is 1 and it means that an interrupt could happen. So when the function " _EI()" has been executed, the cpu enters into the interrupt routine immediately. But  I haven't  put the data into the transmit buffer yet. I don't want to enter into the  interrupt.  
  I debug the program using the single step, so I can see the change of every register and the memery during every step.
When in the loopback mode, the receiver has received the data. But the RFLG is still 0. That is so strange.
0 Kudos

621 Views
kef
Specialist I


lwjtutu wrote:
   Afrer reset, the TXE is 1 and it means that an interrupt could happen. So when the function " _EI()" has been executed, the cpu enters into the interrupt routine immediately. But  I haven't  put the data into the transmit buffer yet. I don't want to enter into the  interrupt.  


Again, TXE ==1 means TX buffer is empty and TX interrupt will be called if corresponding TXEIE bit is set in CANTIER register. When you have nothing to send, you should disable CAN TX interrupt by clearing all TXEIE bits. Yes, after reset all TX buffers are empty and all TXE flags should be set.
You say that receiver received the data but RXF *) bit is still 0.  It doesn't make sense. We know that receiver received something only if RXF is 1. If you saw something changing in CAN registers, well, it doesn't mean receiver received something. Message could not pass acceptance filters and and RXF won't set.
 
(* Please note again, you used bad name, RFLG instead of RXF!)
0 Kudos

621 Views
kef
Specialist I
 


lwjtutu wrote:
LOOPBACK mode. But when I clear the TFLG, it doesn't change and when the receiving buffer receives a message, the RFLG is still zero.why?



First of all please us real register and bits names. Does TFLG mean CANxTFLG? And what's RFLG? CANxRFLG? It would be a bad idea to clear entire CANxTFLG and entire CANxRFLG.
 
How do you detect that TFLG doesn't change? And how do you clear it? Are you using normal TXE bit clearing sequence, CANxTFLG=CANxTBSEL ? CANxTFLG TXE bit could flip to zero for less than 1ms (at high bitrate), then it will flip back to one. Of course it's not easy to catch by eye.
Transmitter could refuse to send and receiver won't receive (CANxRFLG RXF bit always zero), if you are still in initialization mode. Did you clear CANxCTL0 INITRQ bit?
 
 


lwjtutu wrote:
      Another problem is: when the TFLG is 1, the interrupt occurs. But after reset, the TFLG is always 1. If i clear the flag  manully, this flag can not be change any more. Because the datasheet said"Read and write accesses to the transmit buffer will be blocked, if the corresponding TXEx bit is cleared
(TXEx = 0)".
   The two  questions have bothered me for several days.



CANxTFLG TXEx bits should be normally 1. TXE=1 means transmit buffer is empty. If you don't want interrupt when TX buffers are empty, then you should disable CAN TX interrupt.
 
If you clear CANxTFLG and TXE bits don't return back to '1', then it's a sign of bus error or initialization mode or something; messages aren't transmitted.  
 
 
0 Kudos