Best way to modify single I/O pin on CANOpen DS 401

cancommunicationmicrocontroller

I have a microcontroller with CAN and need to implement a CANOpen master. It needs to toggle a pin I/O on a third party device using CANOpen specification DS 401.

How is the best way to accomplish it?

The problem is that I/O bit can't be accessed individually but only whole 8bits or 16bits register (CANOpen DS 401 – Register address 6200h).

I can see two options:

A)

  • A.1) Write to "Filter Mask Output" (CANOpen DS 401 – Register address 6308h) with bit mask I want to modify.
  • A.2) Write to "Write Outputs 16 Bits" (CANOpen DS 401 – Register address 6300H) with desired value
  • A.3) Reset "Filter Mask Output" (CANOpen DS 401 – Register address 6308h).

B) ("Filter Mask Output" is always set)

  • B.1) Read "Write Outputs 16 Bits" (CANOpen DS 401 – Register address 6300H)
  • B.2) Write to "Write Outputs 16 Bits" (CANOpen DS 401 – Register address 6300H) with modified value readen on step B.1

Advantages from A)

  • More safe

Advantages from B)

  • Less messages

My environment is a multi master setup, with values from "Write Outputs 16 Bits" always broadcasting as a TPDO.

Best Answer

There's not a lot of data involved, so in case your node is the only node in the network that will access the particular DS401 node, the ultimate solution is to keep an "output mirror bitmap" in your own microcontroller RAM, which corresponds directly to all outputs you have sent to the DS401 node. That way you already know in advance the status of the other bits.

Which such a configuration you can also send out the data cyclically to the DS401 node and thereby contantly refresh it (industry de facto way of designing mission critical systems).

In case multiple nodes will be writing to the DS401 node, you have to use method B), read the data first, alter it and write it back.

The filter & polarity etc features of DS401 are mildly useful. They are mainly intended to be used for on-site calibration purposes, in a system where the end user has access to the DS401 object dictionary but otherwise can't configure anything in the system. It doesn't make sense to use those features when you are writing software for microcontroller, since doing things like bit masking is trivial from inside the C program.