cancel
Showing results for 
Search instead for 
Did you mean: 

How to implement CANopen protocol on stm32?

RMund.1
Associate II
 
3 REPLIES 3
Andrew Neil
Principal III

Much the same as you'd implement it on any other platform?

  1. Study the protocol definition;
  2. Study the chip documentation;
  3. Apply.

Also: https://www.google.com/search?q=CANopen+protocol+on+stm32

In general: http://www.8052mcu.com/forum/read/160143

JPeac.1
Senior

CANFestival is a good starting point for basic services. You'll find the STM32 16-bit CAN filtering is ideal for routing CANopen services, especially for high priority services like NMT heartbeat and EMCY alert messages. I recommend using one FIFO for high priority and the second for normal priority, so that you minimize response time for events like emergency shutdown.

Also, be sure to enable the error/status interrupt. If something goes wrong you need the information on bus events and error counts. They are essential for reliable operation, especially during startup.

One difficulty you'll run into is an inactive bus. If your device is detached from the bus, or the bus is shut down, or you're bringing up the network one node at a time, you will see continuous errors until there are two working nodes. I got around this by adapting an ethernet-like collision strategy, logically disconnecting the device from the bus for random time intervals. Intervals increase over time so you're guaranteed an overlap for startup of the first two nodes.

And yes, the CANopen documantation is the textbook of record for any implementation. Start with basic services: NMT heartbeat; EMCY if you need a fast process shutdown (like a heartbeat failure on a critical node); SDO infrastructure and PDO data broadcasts for the actual workload. Depending on how you structure your PDOs you may need SYNC as well to trigger a synchronized burst of data PDOs from several nodes.

You can hold off on other services like TIME, LSS and SRDO/global fault until you get some experience.

Another gotcha: Bear in mind if you support the two-level message priority you may see messages arriving in what appears to be out-of-order sequence. Receiving an EMCY alert may precede the PDO data broadcast from a failing node, even though the EMCY was sent after the PDO.

Amel NASRI
ST Employee

Hi @RMund.1​ ,

An answer to a similar question as yours is provided by @Community member​  in this discussion.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.