Continuous CAN transmit on K60 and K40

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

Continuous CAN transmit on K60 and K40

Jump to solution
2,832 Views
yorknh
Contributor IV

I've recently compiled and executed the sci2can example for both the K60 and the K40. My next step was to disable the internal loopback mode so I could connect the two boards to run the external loopback demo.

Prior to connecting the two boards together I hooked each one to a scope to make sure the CAN bus activity was what I expected. What I noticed in both cases is that the same frame is continuously repeated which is not what I expected since the number of transmits specified to the FlexCAN_Write function is 1. Digging a little deeper I can see that the FlexCAN_PrepareAndStartTransmit function sets the CODE field of the message buffer to 0xC, SRR is 0, IDE is 0, RTR is 0 and DLC is 1.

Based on the description of the message buffer code for Tx buffers a CODE of 0xC and RTR of 0 should result in "Transmit data frame unconditionally once. After transmission, the MB automatically returns to INACTIVE state".

If I stop the debugger and manually set the CODE field of the MB to inactive, and then let the code continue execution the frame is no longer transmitted.

So my question is why is it that transmission doesn't terminate on it's own?

Thanks

Labels (1)
Tags (1)
1 Solution
1,831 Views
ndavies
Contributor V

CAN messages need to be acknowledged by another CAN module. The controller continues to send the message out until either the message is ack'ed or the it goes into a bus fault. You need a second CAN node on the bus to ack the message and you must have the bus terminated correctly. This is standard CAN bus protocol for a single module with no other modules awake on the bus. It's one of the things that adds reliability to the CAN protocol.

Norm Davies

View solution in original post

12 Replies
1,831 Views
sruthyuk
Contributor I

Hi Larry,

Did you tested  the external loopback demo by connecting the two kinetis tower boards ??Is there any sample code for testing two CAN nodes??

With regards,

sruthy uk

0 Kudos
1,831 Views
yorknh
Contributor IV

I couldn't edit my previous response...

I never did connect 2 twr boards specifically, but I did do it with 1 TWR-K60D100M and 1 Freedom K64 board with additional circuitry. I did get that to work successfully. The document Robert Boys put together was very useful, but unfortunately I don't remember the details of getting it to work. Because of a system architecture change, CAN wasn't going to be a suitable solution, which is why I stopped any further development. Sorry I can't be of more assistance.

0 Kudos
1,831 Views
sruthyuk
Contributor I

Hi,

Is there any sample code to refer me for testing the two CAN module communication? Here i have already tested both CAN0 & CAN1 module in TWR-K60F120M using loopback mode and its working fine. Now i am trying to test communication between these two CAN module ie, like CAN0 is used for transmitting data and CAN1 going to receive that data. Please help me for finding a solution.

best regards,

sruthy uk

0 Kudos
1,831 Views
jcdammeyer
Contributor III

You need transceivers or an open collector interface.  Plus what the Tx pin sends the Rx pin must see.

0 Kudos
1,831 Views
sruthyuk
Contributor I

Hi friend,

While testing CAN in TWR-K60F120M using the sci2can demo,the code gets stuck at  PE_DEBUGHALT() in cpu.c file during debugging.What may be the reason behind this?? How can i solve this problem??

Here am using CAN0 (PTC13/12 for FlexCAN0) by connecting TXD & RXD pins for loopback testing.

0 Kudos
1,831 Views
yorknh
Contributor IV

Hello sruthy uk,

I abandoned any further CAN experimentation over 9 months ago, and unfortunately don't have an answer for you.

0 Kudos
1,832 Views
ndavies
Contributor V

CAN messages need to be acknowledged by another CAN module. The controller continues to send the message out until either the message is ack'ed or the it goes into a bus fault. You need a second CAN node on the bus to ack the message and you must have the bus terminated correctly. This is standard CAN bus protocol for a single module with no other modules awake on the bus. It's one of the things that adds reliability to the CAN protocol.

Norm Davies

1,831 Views
yorknh
Contributor IV

Ahh, thank you for the quick reply! If it wasn't obvious, I'm totally new to the CAN protocol. Apparently I need to read the CAN spec a few more times.

0 Kudos
1,831 Views
robertboys
Contributor IV

Hello

I attach my CAN Primer.

I hope it helps.

Bob Boys

San Mateo, California

1,831 Views
jcdammeyer
Contributor III

"P17 corresponds to a generally accepted standard for CAN on DB9 connectors. P17 Pin 7 is the CAN Hi bus line and

pin 6 is CAN Lo."  I think you've inadvertently used the pin numbers from the chip there rather than the connector in your text.

Your comments about grounds between nodes are almost correct.  The principal reason for using grounds on ALL CAN networks is to ensure that the common mode voltage between ground and the CAN pins aren't exceeded.  A high common mode spike relative to two separate grounds can toast your CAN transceiver chip.  You'd never even see why.  It would just fail or become sporadic.

0 Kudos
1,831 Views
yorknh
Contributor IV

Bob,

That is a VERY helpful document. Thank for taking the time to put that together and for bringing it to my attention.

Larry

0 Kudos
1,831 Views
mjbcswitzerland
Specialist V

Larry

You can also take a look at the following video which shows how CAN can be used with the Kinetis (single or dual), the bus monitored with a CAN bus analyser and it also show how a simulated Kinetis device can be connected to a real CAN bus for development/test work.

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

There is a CAN document top go with it concentrating on the SW interface: http://www.utasker.com/docs/uTasker/uTaskerCAN.PDF

Regards

Mark

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

0 Kudos