User Tools

Site Tools


arduino:rcan-en

RCAN: GC2a


gc2a-module.jpgcan-extframe.jpeg

Introduction

rcan.jpg 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 and Nano Every.


Dependencies

mcp_can.jpg
Add the mcp_can library in the Arduino IDE to be able to communicate with the MCP2515 chip.

Modifications

One modification in the library source code is to disable DEBUG to save memory in the

 ''Documents/Arduino/libraries/mcp_canr/mcp_can_dfs.h'': (line 41)\\
// if print debug information
#ifndef DEBUG_MODE
//#define DEBUG_MODE 1
#endif

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.jpgnano-every-pinout.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 Nano ATmega328P

Nano Pin GC2a
A6 10
A7 9

Note 1: Use a Nano Every to be able to use GC2a port 9 and 10 as output too.
Note 2: For best performance a 16MHz crystal should be used.

Variables

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

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.
4 1 Sync Synchronise output also with the SYNCID


CBUS

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

CBUS→RCAN Rocrail Range Remark
Event node number → CANID Node-ID 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.


MBus

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

500000bps

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.
gpio 16 port I/O
servo 4 port servo and 12 port I/O
=<id> Set the CANID. Replace <id> with a number between 1 and 255.
$pppppppppppppppp Configure multiple ports: The <p> maybe: 0 for output, 1 for input, 2 for input with off delay, 3 for pulse output.
Example: "$1111" will configure port 1 to 4 as input.
#<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.
:SxxxxNxx…xx;
:XxxxxxxxxNxx…xx;
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
pinlayout=0
CAN bps=250, MCP2515 8MHz
hash 0x0F27
:X00310F27N000030170300460C;
:X00230F27N0017000800010000;
:X00230F27N0017000900010000;


Setup


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


Incompatibilities

  • 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

Drawbacks

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 1: 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.
Note 2: For best performance a 16MHz crystal should be used.


SyncID

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.

Example

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

Documentation

Schedule and PCB

arduino/rcan-en.txt · Last modified: 2024/03/13 09:21 by rjversluis