# Documentation of CAN Messages

URL: https://irs.systems/en/docs/cmm-2ch-3ch/can-messages

CMM-2CH and CMM-3CH can be controlled via CAN-FD. Each measurement channel has its own microcontroller. The nominal baudrate is 1 MBit/s, the data baudrate is 4 MBit/s. A DBC file is available on the download page.

## Structure of CAN-IDs

The CAN IDs are built with the following scheme.

| Bit | Mask | Content | Comment |
| --- | --- | --- | --- |
| 28 | `0x10000000` | Direction | 0: PC to uC, 1: uC to PC |
| 27-20 | `0x0FF00000` | Command-ID | 0...255 see section [Commands](/en/docs/cmm-2ch-3ch/can-messages#list-of-can-commands) |
| 19-12 | `0x000FF000` | Module-ID | "M" = `0x4D` |
| 11-4 | `0x00000FF0` | Board-ID | 0...31 (Can be set via DIP switch on CMM-2CH), 255 = `0xFF` = broadcast to all boards |
| 3-0 | `0x0000000F` | Channel-ID | 0...2 (Is hardwired on CMM-xCH), 15 = `0xF` = broadcast to all channels |

The highest value of board (`0xFF`) and channel (`0xF`) is used as broadcast.
For example the ID `0x 0 00 4D 01 F` is the command "SetOnOff" (= `0x01`) for all channels on board 1.

## List of CAN-commands

Physical values are always transmitted as float (32 Bit / Single Precision / LSB first) and in the base unit (V / A / sec / °C / ... ).

### CAN-IDs to set and get register style values

Get-ID and Response-ID are the same, because they already differ in the direction bit 28. The command values in the following table include the direction bit, to make this clear.

| Set-ID | Get-ID | Response-ID | Command | DLC | Data |
| --- | --- | --- | --- | --- | --- |
| - | - | `0x140` | CommandResponse | 2 | StatusCode (U8), Command (U8) |
| `0x001` | `0x041` | `0x141` | OnOff | 1 | OnOff [0/1] (U1) |
| `0x002` | - | - | OnOffSelected | 1 | EnableMask_Board (U8) |
| `0x003` | `0x043` | `0x143` | MinRange | 1 | MinRange (U8) |
| `0x004` | `0x044` | `0x144` | MinMaxAvg | 24 | CurrentMin [A] (float), CurrentAvg [A] (float), CurrentMax [A] (float), VoltageDropMax [V] (float), NoOfSamples (U32), RangeMin (U8), RangeMax (U8) |
| `0x005` | `0x045` | `0x145` | ChannelConfig | 5 | OnOffDefaultValue [0/1] (U1), MeasuredValuesInterval [sec] (float) |
| `0x006` | `0x046` | `0x146` | CanConfig | 3 | TxFrameFormat [Enum] (U8), NominalBaudrate [Enum] (U8), DataBaudrate [Enum] (U8) |
| `0x007` | `0x047` | `0x147` | LegacyConfig | 16 | LocalId (U32), LocalIdIsExt (U1), RemoteId (U32), RemoteIdIsExt (U1), LegacyCyclicId (U32), LegacyCyclicIdIsExt (U1), LegacyCyclicMessageEnable (U1) |
| - | `0x048` | `0x148` | Version | 12 | HardwareType (U8), FirmwareVersion (U16), CompileTimestamp (U32), WarningRegister (U16), HardwareVersion (U8) |
| - | `0x049` | `0x149` | SerialNumber | 12 | SerialNumber (String 12 Bytes) |
| `0x00A` | - | - | RestoreDefault | 0 | - |
| `0x00D` | `0x04D` | `0x14D` | DisableCalibration | 1 | DisableCalibration [0/1] (U1) |

### Status codes

| Code | Description |
| --- | --- |
| `0xA0` | Success |
| `0xE0` | Unknown command |
| `0xE1` | Invalid DLC |
| `0xE2` | Parameter out of range |
| `0xE3` | Flash error |
| `0xE4` | Flash verify error |
| `0xE5` | Command not allowed |
| `0xE6` | Firmware hardware mismatch |
| `0xE7` | File not found |

### Values in WarningRegister

| Name | Value |
| --- | --- |
| WARNING_CANRXFIFOFULL | `0x0001` |
| WARNING_CANTXFIFOFULL | `0x0002` |
| WARNING_CANBUSOFF | `0x0004` |
| WARNING_INVALIDCALIBRATION | `0x0008` |
| WARNING_DISABLEDCALIBRATION | `0x0010` |
| WARNING_ISOTPRXFIFOFULL | `0x0020` |

## Cyclic CAN-IDs uC -> PC

Physical values are always transmitted as float (32 Bit / Single Precision / LSB first) and in the base unit (V / A / sec / °C / ... ).

| Command-ID | Name | DLC | Data |
| --- | --- | --- | --- |
| `0x180` | MeasuredValues | 12 | Current [A] (float), Range (U8), VoltageDrop [V] (float), OnOff [0/1] (U1) |
| `0x18E` | ErrorHandler | 48 | ErrorType (U8), FileNumber (U8), LineNumber (U16), more info |
