From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

External Gateway Issues on CAN Bus

Hi, I'm new to this forum, and was hoping you all could give me some guidance on why my setup for the external gateway that I've created isn't working.

 

In a previous (functional) setup that I had, I took the messages from the ECM and routed that into my CAN case and laptop.  At another location on the bus, I tee-d in (i.e. through a separate pair of CAN wires) and retransmitted the ECM's modified messages back on to the bus.  I would receive LoC DTCs until I ran a CAPL script, to make sure that messages were transmitted/received on both ends.

 

In my current (non-functional) setup, I cut into a single pair of CAN_HI/CAN_LO lines from the ECM.  I attach termination resistors on both ends, and have them both come into my CAN case and laptop (presumably the cut closest to the ECM is collecting its Tx'ed messages, and the cut farther from it is collecting messages Rx'ed to it).  Now, the problem is that I can only read messages that are either Rx'ed by it or Tx'ed from it, but not simultaneously.  My CAPL script isn't sending messages from one side to the other, and I am receiving a NACK error message. 

 

My guess is that my hardware setup is indeed wrong, and that I must transmit from another location on the bus.  And because CAN is half-duplex, I can only see messages of one direction.  But I still have some lingering questions:

1) When a module sends CAN messages, will it only be able to receive CAN messages from other modules once its own sent messages are ACK'ed?

2) CAN messages are broadcast, meaning that all modules connected to the bus will see all messages.  So why is it the case that I cannot see the ECM messages in my current setup?

 

If you all could give me any pointers, I would greatly appreciate it.  Thank you.

 
0 Kudos
Message 1 of 7
(4,221 Views)

This is quite confusing and hard to follow but there are a few things that jump out right away that are wrong.

 


@maskar wrote:

And because CAN is half-duplex, I can only see messages of one direction.  

 

Not entirely true, and doesn't matter if it is.  So you are sorta right that CAN can't transmit and receive "at the same time"  The bus has a high, and a low and both are used to transmit.  And if you start transmitting when another node is transmitting you will wait until the bus is not active, and then try again.  This will usually be on the order of less than a millisecond later.  Unless the bus is at 100% bus load, with messages that are a higher priority, your message will eventually go out.  But it takes so little time for a message to actually go out, this delay usually doesn't happen at all, or on higher bus loads may happen but once in a while.  If you perform a single write function, the hardware will take care of this retransmit, and will keep trying until it finally goes out.

 

As for the wiring.  You should only ever have at most two 120ohm resistors between the CAN H and CAN L wires.  Take a meter and check the resistance.  Between CAN H and CAN L it shouldn't read much less than 60 ohms.  If it does you have too many resistors.  It can work with less, but it likely won't work with more.

 

1) A CAN node will be able to read, even if it has a frame that can't go out due to a higher priority message that is holding it up.

 

2) Don't know too many things could be wrong to say.  Is the transceiver in a write only mode?  Is there a way to turn on echoing a write message and see if it can be read at the same node?

 

And if you haven't yet, read up on my CAN blog.  Part 1, and Part 2 go over some of the basics.

Message 2 of 7
(4,183 Views)

My apologies for my delayed response; my Internet connection has been rather spotty.  But I do believe that my understanding of certain aspects of CAN is a bit flawed.

 

I will continue to try this out, and I will continue to update this thread.  I don't have much of an electronics background, and I am looking through your CAN blog.  However, I still have a few other questions:

1) I'm still not understanding how messages are received.  When a node transmits a message onto the bus, does it "stay on the bus" until it is received by a module?  I think it is safe to assume that if a message is not accepted, other nodes can still transmit.  Can I achieve a 100% bus load by sending messages that will not be accepted?

 

If I set up a node to send several high-priority messages with incorrect CRCs (to the point that other nodes don't accept them), does that prevent other nodes from transmitting?  I ask because there are times that I've tee-d into the bus (via OBD) and have sent such messages.  Three things usually happen: 1) I get implausibility faults and DTCs related to other modules, 2) I get kicked off the bus and can no longer measure any signals, 3) absolutely no effect.  In the third case, the nodes probably aren't even accepting the message.

 

2) I am a bit confused about CAN addressing.  There are three addresses that I'm familiar with.  Send, receive, and fixed; all of them are either 11-bit or all 29-bit addresses.  Does setting up a gateway require a special addressing configuration?

0 Kudos
Message 3 of 7
(4,167 Views)

I'll do my best but some of these questions I'm not best equiped to answer.

 


@maskar wrote:

 

1) I'm still not understanding how messages are received.  When a node transmits a message onto the bus, does it "stay on the bus" until it is received by a module?  I think it is safe to assume that if a message is not accepted, other nodes can still transmit.  Can I achieve a 100% bus load by sending messages that will not be accepted?


If a message isn't accepted for whatever reason, it doesn't "stay on the bus", but it will be sent again and again until someone on the bus says they got it properly and fully.  If there is only one device on the bus and it tries to send something, it will continually send that message over and over waiting to hear back from anyone.

 

If a message has a bad CRC I'm unsure what will happen, but I suspect it won't be accepted and no one on the bus will send the ACK because they will assume part of the message was lost due to corruption.  This device will likely send the same message again and again until someone ACKs it.  But since this feature of the CRC is set by the hardware transceiver I think setting the wrong CRC is likely difficult to impossible.  But if it were possible to force an incorrect CRC I think the bus would end up being 100% loaded with this message with an incorrect CRC waiting for someone to ACK it. 

 

The CRC-8 SAE J1850 you mentioned in another thread is different.  This CRC is part of the payload and takes up some of the 8 bytes you have (in standard high speed CAN).  You might have the CAN bus have a proper CRC and have the frame ACK properly, but the CRC-8 in the payload can be incorrect.  This means the message won't be sent over and over again, but the device reading the CRC-8 may choose to set a DTC because it believes something is wrong.  The behavior of the device will be defined by whoever writes software for it, and it can choose to ignore it.

 


@maskar wrote:

 

 

2) I am a bit confused about CAN addressing.  There are three addresses that I'm familiar with.  Send, receive, and fixed; all of them are either 11-bit or all 29-bit addresses.  Does setting up a gateway require a special addressing configuration?


Not sure.  You are right that all frames and all CAN traffic is either a 11 bit or 29 bit address.  I'm unfamiliar with gateways other than the concept of receiving on one port and sending on another.

Message 4 of 7
(4,163 Views)

I finally got a chance to get back to this issue.  I can now provide a little bit more detail.  At key off, one side of the harness reads 60 ohms, and is likely terminated by 2 120 ohm resistors (i.e. connected to high speed vehicle CAN bus).  The other end (connected to ECU) reads 0 Ohms (i.e. disconnected from vehicle CAN bus).  My assumption from here is that I need two 120 ohm termination resistors, one closer to my laptop and one closer to the disconnected wire coming out of the ECU.

 

There are still a few things that I do not understand.  How does the network sense "distance"?  Why can I not just use one 60 ohm resistor (or two 120 ohm resistors a very small distance apart) in the middle of the connection between the ECU and laptop?  How close to the ECU/laptop is "close enough" for termination?  I can only disconnect the ECU from the vehicle CAN bus from the middle section of those two wires.  I read something about stub length and was wondering if there was something analogous for termination resistor placement.

0 Kudos
Message 5 of 7
(4,096 Views)

@maskar wrote:

I finally got a chance to get back to this issue.  I can now provide a little bit more detail.  At key off, one side of the harness reads 60 ohms, and is likely terminated by 2 120 ohm resistors (i.e. connected to high speed vehicle CAN bus).


That's kinda odd that a harness would put both resistors in the harness.  Typically it won't be in the harness at all and instead will have two devices on the bus be terminated.  This should be designed to be the two ECUs at the ends as shown in the diagram you linked to.  That being said this doesn't mean it can't work it just isn't ideal.

 


@maskar wrote:

The other end (connected to ECU) reads 0 Ohms (i.e. disconnected from vehicle CAN bus).  


You mean open right? Infinite?  If it really does read 0Ohms then this won't work at all as both High and Low are being shorted together.

 


@maskar wrote:

 

There are still a few things that I do not understand.  How does the network sense "distance"?  Why can I not just use one 60 ohm resistor (or two 120 ohm resistors a very small distance apart) in the middle of the connection between the ECU and laptop?  How close to the ECU/laptop is "close enough" for termination?  I can only disconnect the ECU from the vehicle CAN bus from the middle section of those two wires.  I read something about stub length and was wondering if there was something analogous for termination resistor placement.


The bus doesn't sense the resistance.  It does not choose to stop working if they aren't there, instead the signal integrity will be hard to maintain without them.  The purpose of the resistors is to keep signal reflection to a minimum.  When you put your DMM on the line it doesn't matter where you put it, you will read 60 ohms.  It also doesn't matter where you put the resistors, you should always read 60 Ohms. 

 

But imagine instead we are in an Olympic sized swimming pool.  If someone jumps into the pool waves will be spread out from the point they jumped in.  For simplicity imagine the waves go the length of the pool only.  The wave will eventually hit the walls and bounce back.  Now imagine I am trying to gauge the size of the wave generated by the splash.  At first it is fine since I just see the original wave, but after the wave comes back I'm going to basically have two waves combining into one.  Now with CAN there isn't just one person jumping in a pool there are many, and they are jumping in at a rate of 500,000 times a second.  To accurately measure the wave we need something to suppress the waves and keep them from bouncing back from the walls.  The most ideal place to put them is one at each wall.  If we put something in the middle of the pool waves will still combine in weird places, and the size of the wave after our barrier will be effected.  Also if we only put in one barrier at one wall, and make it twice as large we still won't have an ideal wave since it can bounce back from the far wall unaffected by a barrier.  Transmission Line Theory covers this.

 


@maskar wrote:

How close to the ECU/laptop is "close enough" for termination?  I can only disconnect the ECU from the vehicle CAN bus from the middle section of those two wires.  I read something about stub length and was wondering if there was something analogous for termination resistor placement.


The stub length ideally is short, like 10cm short.  But in practice I've seen it be on the order of 10 feet and be fine.  I've also seen times when only one resistor would be used and it would be fine.  CAN is quite robust and if your bus load is low many of these guidelines can be flexible.  That being said, whenever things weren't working in my system I would always make an effort to abide by the guidelines.

Message 6 of 7
(4,091 Views)

Almost done with this thread here.  So I went back earlier this week, and it seems that the vehicle actually uses a split termination.  If I OC any line and fit in the low pass filter to my laptop, I can read the signals.  I'm thinking that the low pass filter made the difference.  When and where would I need to do this? 

 

I've figured it out by trial and error, but I'm still not understanding completely.

0 Kudos
Message 7 of 7
(4,014 Views)