This is an old revision of the document!


RCAN


Not to be translated until no longer WIP.


store-cdn.arduino.cc_uni_catalog_product_cache_1_image_520x330_604a3538c15e081937dbfbd20aa60aad_a_0_a000005_featured_2.jpgcan-extframe.jpeg

Introduction

The current CANGCA* 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 ATmega328PB.


Dependencies

The only not standard Arduino library used is

to be able to communicate with the MCP2515 chip.

Modifications

One modification in the library source code is the timeout value in the mcp_can_dfs.h:

#define TIMEOUTVALUE    100

The original value of 50 is too low and brings errors on sending frames in a CAN bus.


CBUS Boards

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.)

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.


CBUS-IO

The CBUS-IO is compatible with the CANGC2. (Except of the addressing scheme.)

Nano's with the ATmega328P cannot use port 1 and 2 as digital I/O.

Variables

Variable Nr Description
1 Global module configuration
2…17 Port configurations
18…19 Port state
20 CANID


DEBUG

If the DEBUG define is set to > 0, it is possible to use some serial monitor commands:

Command Description
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

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

Entering Configuration Mode Successful!
Setting Baudrate Successful!
MCP2515 Initialized Successfully!
Loading board 1
CANID=25 BoardType=2 Version=3.a
wait 1000ms...
go...
__AVR_ATmega328P__
init port 0(15) as INPUT_PULLUP
init port 1(14) as INPUT_PULLUP
init port 2(10) as INPUT_PULLUP
init port 3(F) as INPUT_PULLUP
init port 4(12) as OUTPUT
init port 5(13) as OUTPUT
init port 6(E) as OUTPUT
init port 7(2) as OUTPUT
init port 8(11) as INPUT_PULLUP
init port 9(3) as INPUT_PULLUP
init port 10(4) as INPUT_PULLUP
init port 11(5) as INPUT_PULLUP
init port 12(6) as OUTPUT
init port 13(7) as OUTPUT
init port 14(8) as OUTPUT
init port 15(9) as OUTPUT
state changed of port 0 from 0 to 1 conf=3 timer=0
snd Standard ID: 0x019       DLC: 5  Data: 0x93 0x00 0x19 0x00 0x01
state changed of port 1 from 0 to 1 conf=3 timer=0
snd Standard ID: 0x019       DLC: 5  Data: 0x93 0x00 0x19 0x00 0x02
EEPROM: 000 -> 0x00 0x11 0x19 0x00 0x00 0x00 0x00 0x00
EEPROM: 008 -> 0x03 0x03 0x03 0x03 0x00 0x00 0x00 0x00
EEPROM: 016 -> 0x01 0x01 0x01 0x01 0x00 0x00 0x00 0x00
EEPROM: 024 -> 0x03 0x00 0x00 0x00 0x00 0x00 0x00 0x00
EEPROM: 032 -> 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
EEPROM: 040 -> 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
EEPROM: 048 -> 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
EEPROM: 056 -> 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
SoD
state changed of port 9 from FF to 0 conf=1 timer=0
snd Standard ID: 0x019       DLC: 5  Data: 0x94 0x00 0x19 0x00 0x0A
state changed of port 10 from FF to 0 conf=1 timer=0
snd Standard ID: 0x019       DLC: 5  Data: 0x94 0x00 0x19 0x00 0x0B
state changed of port 11 from FF to 0 conf=1 timer=0
snd Standard ID: 0x019       DLC: 5  Data: 0x94 0x00 0x19 0x00 0x0C
state changed of port 0 from FF to 1 conf=3 timer=0
snd Standard ID: 0x019       DLC: 5  Data: 0x93 0x00 0x19 0x00 0x01
state changed of port 1 from FF to 1 conf=3 timer=0
snd Standard ID: 0x019       DLC: 5  Data: 0x93 0x00 0x19 0x00 0x02
state changed of port 2 from FF to 0 conf=3 timer=0
snd Standard ID: 0x019       DLC: 5  Data: 0x94 0x00 0x19 0x00 0x03
state changed of port 3 from FF to 0 conf=3 timer=0
snd Standard ID: 0x019       DLC: 5  Data: 0x94 0x00 0x19 0x00 0x04
state changed of port 8 from FF to 0 conf=1 timer=0
snd Standard ID: 0x019       DLC: 5  Data: 0x94 0x00 0x19 0x00 0x09


Setup


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


Protocol

The CBUS protocol dictates the number of data bytes for all OPC ranges.
This makes no sense for CAN, because the DLC field is responsible for the number of data bytes used in a message.
The CBUS protocol seems to reflect the LocoNet scheme…
The OPC_PNN, a response on a query modules OPC_QNN, will not set the DLC to 6 but to 8. The last two bytes will contain the firmware version.
Officially the OPC_PNN is in the range of 6 data bytes.

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.


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 CBUS-USB Interface

The GC2a can be used parallel as CBUS interface.
It uses the same ASCII framing as the CANGC1(e) interface.

Line setting must be set to:

  • USB
  • 500000bps (This is set automatically in case of USB type.)
  • Linefeed


Source Code


Personal Tools