K60 CAN InterruptRxTx not working: Buffers not changing back to Empty or Unlocking on Receive, and Interrupt skipping/missing every other one on transmit.

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

K60 CAN InterruptRxTx not working: Buffers not changing back to Empty or Unlocking on Receive, and Interrupt skipping/missing every other one on transmit.

1,828 Views
jeff_sylvester
Contributor I

I have a K60F120 tower and K60N152 tower and am trying to set up can network.  Interrupt mode is not working.  both receive and transmit are tied to the same interrupt line.  I ran codewarrior example code from processor expert library that sends one message out and loops back.  this code performs CAN_SendFrame(), and then does CAN_ReceiveFrame()  sending and receiving one message then ending/quiting.  I modified the code to keep going using simple one second loop to send and receive on one second loop.  and took out loopback and connected regular wires, and also have CAN analyzer connected.  First message works fine, then second and third and fourth, etc.. message fail because Message Buffer is not being properly cleared/reset.  Code jumps to InterruptRxTx Interrupt routine generated by PE tool, that reads the IFLAG1 register, and clears MASK1 register and calls user event either OnFreeTxBuffer or OnFullRxBuffer.   I was having problems so I configured one TWR-K60 as receive only and the other TWR-K60 as transmit only.  on the transmit only one, it actually transmitts the messages ( I have incrementing data message, message1 has data=1, message2 has data=2) but the interrupt does not trigger,  (It skips every other one) this tells me the message buffer is not being cleared / initialized, I can see on the CAN analyzer that the messages are going across the bus, but my code tells me that every other message has failed to transmit, because the interrupt is not being triggered. I see by looking at the registers in the debugger that the IMASK2 and IFLAG2 registers are mirroring the ESR1 register and the IMASK1 registers some how?  Similarly the receive only tower receives the first message fine, the second message gives full so no interrupt happens, the third message does overflow,  which says we are actually seeing the messages but not processing them because the interrupt does not happen to tell me I have a message.  If I touch the IMASK2 or IFLAG2 registers on either one, I get bus fault and the core locks up>  it seems like this interface only designed to operate in polling mode not interrupt mode.  the code initialzes properly then after sending or receiving one message it is toast, because the interrupt never triggers again.  My configuration is the same as field devices, where they typically send mostly data, and another one reads mostly data,  this hardware design where you have to ping pong to read different buffers in order to free up the just transmitted or received buffer seems like a bad design,   once you service the buffer, it should reset.

on the RxBuffer CODE table, it says Servicing a buffer is to either read a different buffer, or read the timer register. and that servicing a FULL buffer does not set it to EMPTY, it just unlocks for new message to overwrite the current message.  and if you service a OVERRUN it goes back to FULL> but then farther down in the manual 48.4.3 Receive Process, it says

Recommended way to Service a mailbox

1 Read the Control and Status Word of Mailbox

2 Check BUSY bit

3 Read Mailbox data

4 Acknowledge IFLAG register of Buffer you are in (the one that cause the interrupt)

5 Read the timer Register. 

it looks to me like the example code is not set up correctly because the CAN_SendFrame(), and CAN_ReceiveFrame()  are actually setting and clearing flags, and reading the timer, when you want the interrupt routine to be doing this?   it seems backwards?  all I know is that I cant clear the MB to properly reset and process new data?

0 Kudos
8 Replies

1,128 Views
dlb
Contributor I

Jeff,

I'm having the same issue with a KE06 using Processor Expert with KDS. I receive the first message, call ReadFrame() in my main loop after a receive flag is set in my event handler (Events.c). I enabled all the error events just to see what's going on, and I get lots of calls to OnError(), which is only caused by MSCAN_PDD_RX_BUFFER_OVERRUN_FLAG. Transmit seems to be working fine, but there's some condition that prevents any more receive interrupts. You're right that ReadFrame is supposed to reset the buffer and re-enable the interrupt, but it doesn't work.

Did you make in progress with this issue in your project? Any enlightenment is much appreciated.

EDIT: By calling ReadFrame() in my main loop regardless of my receive flag, I was able to get this working, but it's not ideal.

-dlb

0 Kudos

1,128 Views
sruthyuk
Contributor I

hi Jeff,

Is ur problem solved?? i have also the same problem while testing CAN network.Here am trying to test CAN0 as transmitting one & CAN1 as receiving one in the same twr k60f120 by adding external transceiver circuit. Am testingProblem for FlexCAN (KINETIS512_SC_100MHz) kinetis project in KDS2.0. Transmitting message  entered into the FlexCAN_PrepareAndStartTransmit() function only in the first transmit even FlexCAN_Write occurs in while(1). Also transmitted messages is viewed in CAN_TX pin of processor But  no interrupt is generated after first transmit to clear the message buffer?? What may be the solution for avoiding this problem??

PLEASE HELP TIME CRITICAL

regards,

sruthy uk

0 Kudos

1,128 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi Jeff,

What do you mean for "I modified the code to keep going using simple one second loop to send and receive on one second loop. " Would you please share your changes for a review? Thanks for your patience!


Have a great day,
Kan

0 Kudos

1,128 Views
jeff_sylvester
Contributor I

Kan,  Code warrior 10.3 and / or 10.6 has simple example code for each of the ports,  I2C, Uart, DMA controller, CAN, TSI, etc.. in the CAN example code provided, it sends one message (Transmit), and receives back the same message using internal loopback then the program ends,  so all I did is add a timer to the project to trip / trigger every one second to loop endlessly to send another message instead of just sending one and quitting.  The sample code works because it only sends ONE message and quits, the modified code fails as soon as you send 2,3, 4, more messages the buffers overflow because the Flag and Maintenance required for the Buffers to reset is not correct.  and the buffers overflow.

0 Kudos

1,128 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi Jeff,

It is hard to understand your project just by texts, is there any code snippet for reference? It looks like a result of acknowledge errors, so please also check the ACKERR bit in the Error and Status Register.

Hope that helps,


Have a great day,
Kan

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,128 Views
mjbcswitzerland
Specialist V

Hi Jeff

I can't help with examples and PE generated code but you could look at the following which contains a complete solution for all K devices with CAN.

http://www.utasker.com/docs/uTasker/uTaskerCAN.PDF

https://www.youtube.com/watch?v=Ha8cv_XEvco

This has been used since 2006 on Coldfires and migrated to the Kinetis since it has the same FlexCAN.

Regards

Mark

Kinetis: http://www.utasker.com/kinetis.html

K60: µTasker Kinetis TWR-K60N512 support / µTasker Kinetis TWR-K60D100M support / µTasker Kinetis TWR-K60F120M support

For the complete "out-of-the-box" Kinetis experience and faster time to market

0 Kudos

1,128 Views
jeff_sylvester
Contributor I

thanks for trying to help, for some reason the links are not working?

0 Kudos

1,128 Views
mjbcswitzerland
Specialist V

Hi Jeff

Sorry that the links don't work for you - I suppose its destiny saying you'll need to fix the Freescale problems ;-)

Regards

Mark

0 Kudos