1
\$\begingroup\$

I tried CAN communication using PIC18F25K80 and MCP2551. Using two nodes, I could transmit data from one node to other. But, data was transmitted only when the receiver buffer was set to ignore all errors and both the nodes were configured in 'Normal mode'. And, then I configured the receiving node in the 'Listen only mode' and data was received even when the receive buffer was set to 'Receive all valid messages as per the EXIDEN bit in the RXFnSIDL register'.

But, as the TXERR and IRXIF bits were set in the transmitting node, TXREQ bits was not cleared and the message was continuously sent. What could be the reason that causes these errors?

(I have used the internal RC oscillator set at 64 MHz and the baud rate was set as 100 kbit/s.)

enter image description here

\$\endgroup\$
2
  • \$\begingroup\$ This question seems to be a continuation of electronics.stackexchange.com/questions/64220/… \$\endgroup\$
    – Martin
    May 9 '13 at 15:43
  • \$\begingroup\$ This schematic doesn't show power supply connections to the ICs, which could be the key to debugging this problem. Because of that, it also doesn't show power supply decoupling. As a rule, any line drivers such as the CAN transceiver need more decoupling capacitors than other ICs. \$\endgroup\$
    – Martin
    May 10 '13 at 8:30
4
\$\begingroup\$

CAN bus should have at least TWO active nodes. CAN Transmitter considers a transmission successful only if it gets ACK.

When you configure a node in "Listen Only Mode", it recieves data but doesn't Acknowledge it. As there is no other node on bus, Transmitter doesn't get any ACK and hence Error.

Try connecting one more active node on bus and do same experiement. As far as my Experience, You will not get any errors.

\$\endgroup\$
1
  • \$\begingroup\$ I have already tried that too. Programmed the third node to be in the normal mode(message received when set to ignore errors) and tried it in Listen Only Mode too. But, the result was same! Both nodes received message with out any errors in Listen only mode and the TXERR and IRXIF errors . \$\endgroup\$ May 9 '13 at 10:54
4
\$\begingroup\$

As Martin says, lack of proper terminators can certainly be a problem. However, R-C oscillators are generally not accurate enough for CAN. Usually you need less than 1% mismatch, which would imply .5% accuracy at each end, which the internal oscilators of these PICs isn't going to give you. Try with a crystal driving each PIC and see if you still have problems.

By the way, I have used the 18F25K80 and MCP2551 in numerous designs and never had a problem. However, I used a crystal each time.

Added:

Another problem is now apparent, which is that you may not have a common ground between the two nodes. Of course this is important. The CAN lines as driven by the MCP2551 are differential, but are still directly connected. As such, they have a limited common mode range. Both lines float at about 2.5 V when in the passive state. In the dominant state, each line is pulled about 900 mV from the idle level. The MCP2551 can tolerate a reasonable amount of common mode offset on receiving, but of course it needs the lines to be fairly close to the nominal values when transmitting. Such CAN systems require a ground connection. In this case, CAN is a three-wire bus: CANH, CANL, and ground.

What is probably happening is that the common mode offset is within the range of the receiving node to receive. This is why it gets the frame correctly. However, due to the common mode offset it can't successfully put the ACK bit on the bus in such a way that the transmitter sees it. The transmitter therefore thinks there is a error and retries.

\$\endgroup\$
9
  • \$\begingroup\$ I have terminated both the nodes using 120 Ohm. Also, 8 MHz crystal was used instead of the internal RC oscillator and baud rate was set as 100 KbPS. There are no errors found in the receiving end but the transmitting node is still having the TXERR and IRXIF errors. Is it necessary to have a common ground among the nodes? \$\endgroup\$ May 9 '13 at 6:59
  • \$\begingroup\$ @Arun: Argh. You might have mentioned before that you neglected to hook up the grounds. \$\endgroup\$ May 9 '13 at 12:07
  • \$\begingroup\$ As the message frame is received correctly, can I believe that CAN settings are correct? When I tried with a common power supply for both boards, data was not transmitted! And, when different supplies were used, message was again transmitted (of course with the same errors!). \$\endgroup\$ May 9 '13 at 14:06
  • \$\begingroup\$ @Arun: There is something you are not telling us. Show the real setup exactly as you have it wired. This hand waving is not working, and important stuff like you forgot the ground connection would have been spotted immediately if a proper diagram was supplied in the first place. \$\endgroup\$ May 9 '13 at 14:36
  • \$\begingroup\$ @Arun: the requirement for common 0V was already stated in my answer on Apr 3 electronics.stackexchange.com/a/64227/2110 Also, go back to using the same power supply for both boards and get that working first. Sometimes it is necessary to make a problem worse before you can solve it, then the real issue shows up. \$\endgroup\$
    – Martin
    May 9 '13 at 15:40
1
\$\begingroup\$

Most likely it is due to not terminating the cable at both ends with the 120R resistor. If that has been done and there are still problems, make sure you have set the same baud and other CAN settings at both ends.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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