> For the complete documentation index, see [llms.txt](https://www.opal-rt.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.opal-rt.com/docs/hypersim/examples/i-o-interfaces/can-4-channels.md).

# CAN 4 channels

## Description

The **CAN 4 Channels** example, located in **File > Open an Example File > IO Interfaces**, permits to test the CAN communication on the simulator using two loopback pairs across four CAN-FD channels.

The objective is to demonstrate manual and DBC-based message transmission, dynamic CAN IDs, and cyclic versus non-cyclic messaging while monitoring channel statuses in ScopeView.

<figure><img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-3c132bc4546b77f767b82dcff53b02918d166092%2FCAN-4-channels-1.png?alt=media" alt=""><figcaption></figcaption></figure>

## Requirements

* Simulator equipped with a Kvaser 4-channel CAN card and breakout cable.
* Loopback wiring: connect channels 0↔1 and channels 2↔3.
* CAN bus termination using a termination resistor.
* Hardware that supports CAN with Flexible Data-Rate (CAN FD).

## Detailed explanation

All four channels are configured with a bit rate of 1 Mbps. Silent, extended, and promiscuous modes are disabled. Each channel transmits one message with the dynamic ID option enabled, allowing the CAN ID to be changed during model execution.

Messages on channels 0 and 1 use manually built data frames, while channels 2 and 3 use data frame definitions imported from a DBC file. Channels 0 and 1 exchange messages over one loopback pair; channels 2 and 3 exchange messages over the second loopback pair.

Channel behavior and message configuration:

* Channel pairing: channel 0 receives from channel 1 and vice versa; channel 2 receives from channel 3 and vice versa.
* Channels 0 and 1 (Bus\_0/Node\_0/Message\_0 and Bus\_0/Node\_1/Message\_1) transmit non-cyclic messages. These must be enabled every time step via the *Enable Message* input to transmit.
* Channels 2 and 3 (Bus\_Dbc/MCU\_1/MCU\_1\_PARKING\_CAMERA and Bus\_Dbc/MCU\_2/MCU\_2\_DOOR\_LOCK) transmit cyclic messages at 10 ms and 5 ms, respectively. To make a message cyclic, check *Enable Cyclic Transmission* and set a *Transmit Rate*. Cyclic messages have no *Enable Message* input and transmit at the configured rate.

All channels have CAN FD enabled, so the payload size is 64 bytes. Flags and statuses for each channel can be monitored in ScopeView. It is also possible to clear transmission and reception buffers and to set the MSG\_STD and MSG\_RTR bits of transmitted messages.

## Simulation and results

To exchange data between channels 0 and 1, set the following blocks to 1:

* Ch0\_Tx\_Enable
* Ch0\_Rx\_Enable
* Ch1\_Tx\_Enable
* Ch1\_Rx\_Enable

No action is required for channels 2 and 3; reception is already enabled, and transmission is cyclic.

To modify transmitted data, change the values of blocks named ChY\_Tx\_DataZ, where Y is the channel (0, 1, 2, or 3) and Z is the data index (0–7).

Use ScopeView to validate loopback functionality by loading the CAN\_4\_Channels.svt template located alongside the model.

<figure><img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-21ba0edbc9a06b9fa8f241337303b4bf212fdefa%2FCAN-4-channels-2.png?alt=media" alt=""><figcaption><p>Result for channel 0, that all values sent match with those received:</p></figcaption></figure>

The expected result is that transmitted values match received values on each loopback pair. The *Flags* and *Statuses* tabs provide diagnostic information for troubleshooting if loopback communication is not established.

<figure><img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-8d691281b56657a24d0d5489741393b5be8cec81%2FCAN-4-channels-3.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-9fbc7d3e511af46e43a173de271649713cf46afa%2FCAN-4-channels-4.png?alt=media" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.opal-rt.com/docs/hypersim/examples/i-o-interfaces/can-4-channels.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
