1
\$\begingroup\$

I'm trying without success to perform CAN bus communication between an microcontroller and the host (my computer). My question does not depend on the microcontroller, but on the CAN Bus (classic CAN).

My application tries to send a frame each (5 ms, 10 ms, 100 ms). I have a simple scheduler that execute tasks where I call the function can_write(HwObject,Frame) to write the frame to the bus.

However, the first frame returns OK and it's received at the host, but after that (and for all the following frames) the function returns busy, and I keep seeing the error counter increasing without any frame arriving at the host. Finally the node seems to go into bus off mode.

I want to know what are the main reasons for that: I'm using the same baudrate, 1 Mbit/s, on both sides, but I also tried different ones, but without success to see any results. I have looked around registers to see what could be the issue. For example I get:

  1. The bus detects a transmit abort request.
  2. The channel enters to halt mode after bus off.
  3. The bus is in passive mode.
  4. A channel bus error is detected.
  5. Error warning is detected.
  6. Overload is detected.
  7. A bit stuff error is detected.

PSS: I'm following the AUTOSAR Standard: The CAN specification can be found at: https://www.scribd.com/document/160011317/Autosar-Sws-Candriver

But I can't find what causes this issue. I think it is due to bad synchronization!

\$\endgroup\$
6
  • \$\begingroup\$ If there is no acknowledgement, the packet is retried continuously. The bus is busy, and no further packets can be queued in the hardware. \$\endgroup\$ Commented Dec 11, 2016 at 1:16
  • \$\begingroup\$ What is the name of the USB-to-CAN adapter that is connected to the computer? From what vendor? \$\endgroup\$ Commented Dec 12, 2016 at 0:19
  • \$\begingroup\$ @PeterMortensen I have tried both CAN ESD and CANcase (From Vector) \$\endgroup\$
    – The Beast
    Commented Dec 12, 2016 at 13:46
  • \$\begingroup\$ @SimonRichter Please note that the first frame arrived successfully at the Host but all the following frames fails. In addition an error is detected after while sending the first frame. \$\endgroup\$
    – The Beast
    Commented Dec 14, 2016 at 0:35
  • \$\begingroup\$ I don't have access to that particular software, and it is not mentioned in what I could find online - is there some kind of mode option in that software with values like "Passive", "Listen", "Listen Only", "Normal", "Silent" or similar? For instance, in Kvaser's CanKing program the option is called "Driver Mode" (in window "CAN Controller"), with values "Normal" and "Silent". "Normal" is for the CAN adapter to participate on the CAN bus (when it has been started logging/displaying what is going on on the CAN bus) - this should make it work in your scenario, with only one CAN device. \$\endgroup\$ Commented Dec 15, 2016 at 20:42

1 Answer 1

5
\$\begingroup\$

There are usually two causes of this:

  1. The bus terminators are not installed. The 120 Ω terminators at each end of the bus perform two functions:

    1. Absorb the energy that would otherwise be reflected by the open end of the cable. This is particularly important on long busses and at high bit rates.

    2. To keep the bus in the recessive state when it is not driven. You can think of CAN as being like a open collector line, except that it is implemented as a differential signal. On a open collector line, there needs to be a pullup to keep the bus high when it is not driven. On CAN, you instead need pull-together resistors. They keep the bus in the recessive state when not driven.

  2. No other unit on the bus is receiving the message. This means nobody is sending the ACK required at the low protocol level. When you only have two nodes on the bus, then both have to be up and running for the bus to work. It's not like RS-232, for example, where one node can send and it doesn't matter whether anyone else is listening.

    When the sender receives no ACK, it retries continually. Eventually it may go off line after too many retries, depending on how the error handling and recovery is set up.

    If the bus is intact and signals are correct, then this is a firmware problem with the second node.

As with any debugging, you do tests that tell you which part of the system the problem in not in. The obvious thing to do here is to look at the CAN signals and see if they are right. Remember that CAN is a differential signal. The single signal value that bus nodes interpret is (CAN+)-(CAN-). That should be essentially 0 in recessive state and about 1.8 V in the dominant state. Most bus driver chips, like the common MCP2551, will use about 2.5 V common mode voltage.

\$\endgroup\$
3
  • \$\begingroup\$ Thanks for the reply. I did install bus terminator on the CAN Hw interface (CAN ESD or CANcase from Vector) it looks like this (kvaser.com/wp-content/uploads/canland/product/…). On the other hand off the MCU Board I enabled the resistor two. Regarding the Ack do I need to implement it in software or it's sent automatically ? When sending frames from Host, I can see the CAN Frames arriving at CAN_Rx of the MCU but not on the CAN_Tx pin (While transmitting back) instead sometimes I see error frames .However those frames did not make it to the Host. \$\endgroup\$
    – The Beast
    Commented Dec 12, 2016 at 13:56
  • \$\begingroup\$ Note : But it happens once , a frame has been captured correctly in the HOST side which prove that CAN Hw is set correctly. Many Thanks :) \$\endgroup\$
    – The Beast
    Commented Dec 12, 2016 at 14:00
  • \$\begingroup\$ Hi @OlinLathrop: The problem was solved by disabling the ethernet interface (Tx) that was enabled by default. That's weird I didn't know that communication interfaces (Ethernet, CAN,Lin) can interfere and cause this problem. \$\endgroup\$
    – The Beast
    Commented Dec 17, 2016 at 23:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.