User Tools

Site Tools





The current CAN-GC* hardware serie is based on MC PICs.
RCAN is firmware for CAN based solutions on the Arduino platform.
The firmware target is the Arduino Nano ATmega328P(B).


rcan.jpg The only not standard Arduino library used is

to be able to communicate with the MCP2515 chip.


Two modifications in the library source code are to disable DEBUG to save memory, and increase the timeout value in the Documents/Arduino/libraries/MCP_CAN_lib-master/mcp_can_dfs.h: (line 40 and 45)

// if print debug information
//#define DEBUG_MODE 1
 *   Begin mt
#define TIMEOUTVALUE    100

The original TIMEOUTVALUE of 50 is too low and brings errors on sending frames in a CAN bus. (Depends on how much traffic is on the CAN bus.)
It is very important to disable DEBUG_MODE otherwise there is not enough memory available. The Arduino IDE will complain about this, and RCAN will reboot continuously.

GPIO Board

The difference between the standard PIC based and Arduino boards is the FLAT addressing scheme, and only support long events. (Long/Short events are detected in Rocrail automatically.)
pin_arduino_nano.jpg The GPIO is compatible with the CANGC2. (Except of the addressing scheme.)

Nano's with the ATmega328P cannot use port A6 and A7 as digital I/O, and are only available as input with analogRead.

Input only pins on ATmega328P

Nano Pin GC2a ArduCAN-IO
A6 10 2
A7 9 1


Variable Nr Description
1 Node configuration byte
2…17 Port configuration bytes
18…19 Port state bytes (Read only)

Node configuration byte

Bit Value Function Remark
0 1 Save state Save output states in EEPROM on a power off command.
1 1 Short events Not used.
2,3 0,0 250ms pulse time
2,3 1,0 500ms pulse time
2,3 0,1 1000ms pulse time
2,3 1,1 2000ms pulse time
4 1 Report all on SoD Report also low input values instead of only high.

Port configuration byte

Bit Value Function Remark
0 1 Input Initialise the port as input with internal pull-up resistor.
The GC2a board will also provide 10kOhm resister arrays because the internal pull-up value is too high.
0 0 Output Initialise the port as output.
1 1 Input off delay Input 2 seconds off delay for occupancy detectors.
1 1 Output pulse Pulse length according the global node configuration.
2 1 Invert Invert the digital port value.
3 1 IR port Not used.
4 1 Sync Synchronise output also with the SYNCID


The CBUS protocol is copyrighted by Mike Bolton & Gil Fuchs.

CBUS→RCAN Rocrail Range Remark
Event node number → CANID Bus 0…127 (default 127) CBUS uses the 4 MSBits for priority. (The standard CAN Frame ID is 11 bit.)
Event address → Port Address 1…16 (fixed) This is the Port Number.

Module node number and module CANID are the same and just one value in the firmware.
The CBUS learning mode is not supported and not needed.

The same flat addressing scheme can be used with the PIC based boards by setting the event node numbers to the modules node number and the event addresses to the corresponding port number, and disable the short event option.
In case the RCAN based modules are planned to be used in an existing CBUS network, it is recommended to convert the existing modules to the flat addressing scheme to make it transparent.


Support for Märklin CAN protocol.

  • Inputs are reported as s88 events. (0x11)
  • Outputs react on 0x0B with MM 0x3nnn. The dlc 8 is used as bus/address.
  • Read/Write config with 0x07 and 0x08.
  • Ping is also supported as query in the CBus Node Dialog.

Serial Monitor


Command Description
usbon/usboff Activate/deactivate the USB interface for GridConnect. (default deactivated)
dump Shows the EEPROM first 64 bytes
sod Start of Day
init Re-init all I/O
stat Shows the I/O state
pub Publish board identification and type
loop Set the loopback mode for this session.
norm Set the normal mode. (default)
cbus Switch to CBUS protocol. (125k) (default)
mbus Switch to Märklin CS2 protocol. (250k)
8m Set MCP2515 clock speed to 8MHz. (default)
16m Set MCP2515 clock speed to 16MHz.
l0 Set pin layout to fit the CANGC2a. (default) → Push the reset button to make changes active.
l1 Set pin layout to fit the ArduCAN-I/O. → Push the reset button to make changes active.
=<id> Set the CANID. Replace <id> with a number between 1 and 255.
#<port><config> Configure a port. Replace <port> with a character between 0…9 and a…f.
The <config> maybe: 0 for output, 1 for input, 2 for input with off delay, 3 for pulse output.
Example: "#a1" will configure port 10 as input.
ASCII frame which will be send on the CAN bus and evaluated by the board. (GridConnect scheme as used by MERG CBUS.)
See chapter 10 of the MERG "Developer’s Guide for CBUS".

Also all CAN traffic and supported OPCs are traced in the serial monitor.

Loopback Mode

The original text is found in the Microchip MCP2515 manual in section 10.4.
Loopback mode will allow internal transmission of messages from the transmit buffers to the receive buffers without actually transmitting messages on the CAN bus.
This mode can be used in system development and testing.
In this mode, the ACK bit is ignored and the device will allow incoming messages from itself, just as if they were coming from another node.
The Loopback mode is a silent mode, meaning no messages will be trans- mitted while in this state (including error flags or Acknowledge signals). The TXCAN pin will be in a recessive state.

Monitor output example

MBus 0x3017
CAN bps=250, MCP2515 8MHz
hash 0x0F27


The CBUS-IO will report itself as GC2a, module type 12.
The firmware version is only visible with the SocketCAN and GC2a interface.


  • SLiM is not supported
  • FLiM is not supported
  • Learn mode is not supported
  • The ‘Device Addressed’ model; This is fixed: NN → CANID, DN → Port 1…16
  • The push button will not request a node number by OPC_RQNN, but will publish itself by OPC_PNN


With the FLAT addressing it is not possible to activate outputs with one command, NN+DN, on multiple boards(nodes).
This option is not or only hardly used, and makes the setup of boards needlessly very complex.
Tip: With the SYNCID the outputs can be synchronised with other IDs.

Push Button

The push button on the Arduino keeps its original function: Reboot.
After every reboot an OPC_PNN will be send to popup the CBusNode dialog in Rocview with selected node.
This feature can be used to identify a node.

GC2a as USB Interface

The GC2a can be used parallel as CBus/MBus interface.
It uses the same ASCII framing as the CANGC1(e) interface. (See chapter 10 of the MERG “Developer’s Guide for CBUS”.)

Line setting must be set to:

  • USB
  • 500000bps (This is set automatically in case of USB type.)
  • No hardware handshake (RTS/CTS)
  • Linefeed

With this option, the GC2a can also be used standalone; The minimal CBUS setup.

Note: Because the ACK slot bit will not be set by other CAN modules, a send error will be reported, but can be ignored in standalone mode.


The SyncID option is added to be able to synchronise input event from board X with output states on board Y.
The port mapping is 1:1.
It can also be use to switch multiple outputs with a single Rocrail command.


On board with ID 33 is input port switched to ON.
Another board with ID 22 hast set SyncID to 33, and will check if the corresponding port is an output and will synchronise it with the input port of board 33.
This situation is often used for switch panels.

Source Code


Schedule and PCB

arduino/rcan-en.txt · Last modified: 2020/07/01 07:52 by rjversluis