Please help me on practical CAN implementation

Thread Starter

aspirea5745

Joined Apr 17, 2019
106
I’ve learned the basics of the Controller Area Network (CAN) protocol and now want to move to practical implementation with hands-on experience.

Should I start with a small development board that supports CAN, or would it be better to use two or more microcontrollers with CAN support and transceiver ICs?

I’d appreciate your @Papabravo @JohnInTX and community suggestions on what boards, microcontrollers, or tools have you used or would you recommend for hands-on experience ?
 
Last edited:

Ian0

Joined Aug 7, 2020
13,121
Start with two microcontrollers and two transceivers. You can't mess up the hardware (easily). CAN gets upset if there is only one device working as there is nothing to send the acknowledge pulse, so it keeps retransmitting over and over again.
Set up the baud rate on both, set up a receive mailbox on one with no filtering, so that it receives everything that is on the bus.
Set up a mailbox to transmit on the other device. Trigger a transmit and watch on the scope. If you get one burst of data about 80 bits long, you have a link and the receiver is acknowledging.
 

Thread Starter

aspirea5745

Joined Apr 17, 2019
106
Start with two microcontrollers and two transceivers. You can't mess up the hardware (easily). CAN gets upset if there is only one device working as there is nothing to send the acknowledge pulse, so it keeps retransmitting over and over again.
I appreciate the suggestion. If you don’t mind, could you please share the names of the microcontrollers and transceivers you recommend? I know any that support CAN should work, but I’d like to know which ones you have tried and would be good for implementation on a breadboard or veroboard.
 

Ian0

Joined Aug 7, 2020
13,121
I appreciate the suggestion. If you don’t mind, could you please share the names of the microcontrollers and transceivers you recommend? I know any that support CAN should work, but I’d like to know which ones you have tried and would be good for implementation on a breadboard or veroboard.
The ones I have used are Renesas RA4M1 and NXP LPC1517. Of the two, the NXP was marginally easy to understand.
 

John P

Joined Oct 14, 2008
2,054
You can do this on Arduinos, and get the benefit of easy setup. If you use the Uno, you can get the CAN interface as a shield, or you can buy a little module that you can wire to some of the Arduino pins.
 

Papabravo

Joined Feb 24, 2006
22,072
I’ve learned the basics of the Controller Area Network (CAN) protocol and now want to move to practical implementation with hands-on experience.

Should I start with a small development board that supports CAN, or would it be better to use two or more microcontrollers with CAN support and transceiver ICs?

I’d appreciate your @Papabravo @JohnInTX and community suggestions on what boards, microcontrollers, or tools have you used or would you recommend for hands-on experience ?
It has been nearly two decades since I did anything meaningful with any actual hardware, so I am in a really poor position to recommend any actual devices.

I can tell you that a lonely node on a network is a great development tool, precisely because when there is no dominant bit in the ACK slot, a CAN controller will repeat that frame indefinitely. This means you do not need a storage scope or a logic analyzer to capture a frame. You can tell from a repetitive trace that:
  1. You have correctly configured the bit rate
  2. You can see the automatically inserted "stuff" bits
  3. You can see that the proper amount of interfame space is allowed for successive transmissions
  4. You can see the response of the CAN device when you externally "step" on a recessive bit in the middle of a frame.
These things will raise your confidence that two similarly configured nodes should actually be able to communicate.

One more thing:
Normally a CAN cable plant will consist of a "long" twisted pair cable with a nominal characteristic impedance of 120 Ω, with 120 Ω resistors on each end. For beginning experiments, use a short piece of cable with a 60 Ω resistor at one end only. You can deal with "long" cables after everything is working. When designing a product, never ever put termination resistors on the product. Termination resistors belong on the cable system and NOWHERE else. You have no idea how difficult it is to debug a system with 32 nodes and 3 or more termination resistors
 
Last edited:

atferrari

Joined Jan 6, 2004
5,007
I’ve learned the basics of the Controller Area Network (CAN) protocol and now want to move to practical implementation with hands-on experience.

Should I start with a small development board that supports CAN, or would it be better to use two or more microcontrollers with CAN support and transceiver ICs?

I’d appreciate your @Papabravo @JohnInTX and community suggestions on what boards, microcontrollers, or tools have you used or would you recommend for hands-on experience ?
Long ago, after learning the basics of CAN protocol and against all recommendations (implement a single node and test it in an already working network) I implemented my own network of 3 nodes using a PIC micro 18F4550 for each. Right now I cannot remember what transceivers I used but they weren't Microchip's.

Worked from the first try.

The 18F4550 micro had a huge amount of registers to serve the CAN specific routines but poorly (or wrongly) identified in the datasheet; it was kind of a nightmare but ended working to satisfaction.

Not having a specific application in mind at the moment, I lost interest once I got it working.

Programming was, as always, in Assembly. My files should be still around here.
 

nsaspook

Joined Aug 27, 2009
16,275
I’ve learned the basics of the Controller Area Network (CAN) protocol and now want to move to practical implementation with hands-on experience.

Should I start with a small development board that supports CAN, or would it be better to use two or more microcontrollers with CAN support and transceiver ICs?

I’d appreciate your @Papabravo @JohnInTX and community suggestions on what boards, microcontrollers, or tools have you used or would you recommend for hands-on experience ?
If you're using 8-bit pics then the Q84 is a good choice. My local network on the solar monitor uses can-fd for remote displays and the gateway for a Linux server.
https://forum.allaboutcircuits.com/...rge-controller-datalogger.194146/post-1831094
 

Papabravo

Joined Feb 24, 2006
22,072
Long ago, after learning the basics of CAN protocol and against all recommendations (implement a single node and test it in an already working network) I implemented my own network of 3 nodes using a PIC micro 18F4550 for each. Right now I cannot remember what transceivers I used but they weren't Microchip's.

Worked from the first try.

The 18F4550 micro had a huge amount of registers to serve the CAN specific routines but poorly (or wrongly) identified in the datasheet; it was kind of a nightmare but ended working to satisfaction.

Not having a specific application in mind at the moment, I lost interest once I got it working.

Programming was, as always, in Assembly. My files should be still around here.
The tranceiver was probably a Philips (Now NXP) 82C250. It has certainly been replaced by the 82C251 and othe successors.
 

Thread Starter

aspirea5745

Joined Apr 17, 2019
106
I would plan to set up a two-node CAN communication system on a veroboard. Each node will have a microcontroller (with CAN support) and a CAN transceiver (like MCP2551). The two nodes will communicate with each other over the CAN_H and CAN_L lines.

I’ll place 120-ohm termination resistors at both ends of the bus and provide each node with a 5V (or 3.3V) power supply

For PC communication, I would use a UART-to-RS232 interface to the PC for monitoring

my main concern is about selecting the right microcontroller and a CAN transceiver . I want to ensure the microcontroller with CAN program and CAN setup have already been tested by others, so I can rely on the verifying protocol and avoid spending too much time troubleshooting hardware or software issues. This will allow me to focus on identifying any specific issues with my own setup if something goes wrong.

Let me know if you have any suggestions or thoughts!

Cheers,
 

Ian0

Joined Aug 7, 2020
13,121
I use the TCAN1051. I have also used the MCP2551. They both work the same and are pin compatible. CAN transceivers are hard to blow up, but I found the TCAN1051 was harder to blow up than the MCP2551.
If you have a 3.3V microcontroller that does not have 5V tolerant inputs, then make sure you get a device with a Vref or Vio connection (which is usually on pin 5).
Whilst most microcontroller CAN interfaces differ in how they handle mailboxes, they all have a bit time setting register.
This website
http://www.bittiming.can-wiki.info/
works out the settings for you.
 

trebla

Joined Jun 29, 2019
599
MCP2551 is at end of lifecycle, a drop in replacement is MCP2561. For interfacing with 3.3V MCU-s is MCP2562 with Vio pin. For CAN-FD is drop-in pin compatible tranceivers MCP2561FD and MCP2562FD.
Easier is start developing with MCUs with familiar architecture and with familiar IDE toolchain. Microchip has 8bit MCUs with CAN controller (PIC18Fxx80 and PIC18FxxK80 for example) and lot of 16 and 32 bit MCUs. STM offers lot of STM32 MCUs with CAN and CAN-FD controllers. I believe TI and many other MCU manufacturers have MCUs with CAN capability.
 

Thread Starter

aspirea5745

Joined Apr 17, 2019
106
Easier is start developing with MCUs with familiar architecture and with familiar IDE toolchain. Microchip has 8bit MCUs with CAN controller (PIC18Fxx80 and PIC18FxxK80 for example)
Do you have working CAN code for the PIC microcontroller(s) you’ve suggested? It would be really helpful
 

trebla

Joined Jun 29, 2019
599
Microchip offers free CAN code examples for PIC-K80 and PIC-Q83 MCU families. For Microchip 16 bit MCUs you can find some code examples CE427,CE428,CE429 (for dsPIC33EP512MU810/dsPIC33EP512GM710). For STM32 is simplest way to open some free code examples in STM-s propriertary configurator CubeMX/CubeIDE. If you have CCS PIC18 or dsPIC/PIC24 compiler full license then they offer also very easy interface for CAN and CAN-FD networking.
 

nsaspook

Joined Aug 27, 2009
16,275
Do you have working CAN code for the PIC microcontroller(s) you’ve suggested? It would be really helpful
At what level will you be designing, developing and programming this project? From the ground-up, like designing a PCB using chips and component hardware of your own design and programming at the register level of controller modules for low-level driver routines or is it something at a higher level, with prebuilt hardware and with general CANBUS libs for application level programming so you don't need to worry much about low-level hardware or software details?
 

Thread Starter

aspirea5745

Joined Apr 17, 2019
106
At what level will you be designing, developing and programming this project? From the ground-up, like designing a PCB using chips and component hardware of your own design and programming at the register level of controller modules for low-level driver routines or is it something at a higher level, with prebuilt hardware and with general CANBUS libs for application level programming so you don't need to worry much about low-level hardware or software details?
I am planning to work at a level where I assemble the hardware myself, including setting up the microcontrollers, CAN transceivers, and other components like termination resistors on a veroboard. However, I intend to use microcontrollers with integrated CAN controllers that have been tested with general-purpose CAN libraries to avoid the complexity of low-level register programming and driver development. My primary focus is on ensuring the physical layer setup is correct and existing libraries to test and validate the CAN communication between the nodes.

This approach allows me to work on the hardware connections and initial configurations while relying on pre-tested software solutions to minimize troubleshooting at the low-level protocol or driver level
 

Ian0

Joined Aug 7, 2020
13,121
I'm not a big fan of "drivers" a.k.a bloatware. All they do is add an extra layer of (poor) documentation to the project. I find that the hardware is usually far better documented than the drivers, which generally makes it easier simply to use the hardware.
For CAN there are very few registers to initialise to get it working - mainly the bit timing register.
Then you need to initialise the mailboxes and the acceptance filters, but it can work without them.
 

nsaspook

Joined Aug 27, 2009
16,275
I am planning to work at a level where I assemble the hardware myself, including setting up the microcontrollers, CAN transceivers, and other components like termination resistors on a veroboard. However, I intend to use microcontrollers with integrated CAN controllers that have been tested with general-purpose CAN libraries to avoid the complexity of low-level register programming and driver development. My primary focus is on ensuring the physical layer setup is correct and existing libraries to test and validate the CAN communication between the nodes.

This approach allows me to work on the hardware connections and initial configurations while relying on pre-tested software solutions to minimize troubleshooting at the low-level protocol or driver level
Great. So what type of processing will be handled a each CANBUS node? A typical 32-bit controller will likely have the needed code libraries and IDE to eliminate most the the low-level programming but you will still need to know how to do it so you can troubleshoot problems and modify existing code to better meet your exact needs.

This CANBUS project is for networking vibration sensors. PIC32MK processor boards were designed and built. One was a small remote sensor board for the BMA490L, BMA400 and SCA3300 high-performance 16-bit digital triaxial acceleration sensors.
The other was a host board to collect the remote sensor data and send that to a main host using WFI or Ethernet.
https://forum.allaboutcircuits.com/...nd-sensor-node-for-canbus.189388/post-1765812
PIC32MK MCJ motor controller and sensor node for CANBUS

1734979272141.png
Remote board sending IMU data to PC using the CANBUS interface.

1734979508900.png
Host board.

1734979348551.png
Remote (that can also be programmed data processors) sensor boards with external CANBUS transceivers.

1734979725167.png
https://forum.allaboutcircuits.com/...nd-sensor-node-for-canbus.189388/post-1802267
Remote sensor connected via CANBUS to host controller.

Project source code.
https://github.com/nsaspook/wfi32/tree/nhost/firmware/src
 
Top