I'm new to CANBUS and have some doubts about how the heartbeat works. My setup involves a PLC communicating with two devices, and I need to be able to determine when I have communication with them. The issue arises when communication is lost; the CANBUS messages freeze completely. To address this, I believe a heartbeat is necessary. My idea is to receive periodic messages with a counter.
I've been attempting to understand how to implement the Producer and Consumer for this message exchange with the CANBUS Master, but so far, I haven't had any success. Could you guide me on how to set up the Producer and Consumer?
device 1: ID 02 device 2: ID 3C
enter image description here This is what I've tried to send, but unfortunately, I haven't received any messages back.
My idea is to receive periodic messages with a counter.
Object dictionary entries are not the same thing as CAN frame identifiers ("COBID")!
Heartbeat consumer and producer is configured in indexes 1016h and 1017h in the object dictionary, as specified by CiA301. In order to access any entry in the object dictionary, you must do a SDO access. This is done through the Tx and Rx SDO objects, you'll have at least one of each. Typically corresponding to CAN id 600h + node id (Tx) and 580h + node id (Rx).
Ideally you configure every node while in pre-operational mode, before moving on to operational mode. It is custom that the NMT master is consumer and everyone else are producers. When Heartbeat is active, each producer node will report which mode it is in, with the specified interval, CAN frame 0x700 + node id.
But instead of using SDO, you send the object dictionary addresses over CAN as if they were identifiers. That won't work. Furthermore you seem to be using extended identifiers which is probably not what you want either.
CANopen is pretty complex so I would recommend studying it in detail before doing anything else. You won't get far with just trial & error.