|
emCANSetup
set up embedded CAN bus.
Since R2019b
Library: embeddedCreatorLib ( Dafulai Electronics) / Embedded CAN Bus / emCANSetup

Description
Set up embedded CAN bus (CAN 2.0 A & B), and If it has not received any CAN bus packet for some specified time (Time out), output port "Fault" will be true (like communication Watchdog)
Let's introduce Our CAN bus blocks.
CAN Bus Transmission uses Channel conception.
There are 3 Transmission Channels: Channel A, Channel B and Channel C.
Every Channel can have as many as 31 sequences (Seq No is from 0 to 30).
Small Sequence Number has higher priority for transmitting. Every Sequence transmits one CAN bus RTR/Data frame. Or every Sequence can also transmit multiple frames with the same CAN ID but different frame Number in 1st data.
In one channel, transmit CAN bus frame one by one according to Sequence Number from 0 to 30.
All Channels can run at the same time. And they share CAN Bus hardware, Channel A has high priority. Channel B has middle priority, Channel C has low priority
The Seq Number 0 to Seq Number 3 of all channels can also transmit one data frame (short or long) which needs external node respond to. In this situation, only when CAN bus receives response CAN frame(s) or timeout, will this sequence end and start next sequence.
Received CAN bus frames are divided into 2 classes:
Short frame (Data byte length is 0 to 8, or RTR frame)
Long frame (Data byte length is 9 or more, first data byte is used as Frame Number).
CAN bus receives all interesting frame automatically, you just set up your interesting CAN ID for both short and long frame.
You just use "emCANReadRxFrame" block to get Data Values.
Notes: You must set up CAN bus receiver interrupt enable in MCU Configuration software such as MPLABX IDE MCC for Microchip technology MCUs.
Parameters
Please double click this block to open parameters dialog below:

Let us explain parameters.
| • | Peripheral CAN bus Number — tell system this block is which CAN controller peripheral used. You just choose from drop list items: 1 or 2. |
| • | Settings input data format — radio button to select CAN ID and Mask Data format is Hex or decimal data. You can change this setting in any time to see data in Hex or Decimal way. |
| • | Mask0 — CAN Bus receiver's the 1st Mask register. If bit of Mask register is 1, CAN Bus receiver will only receive CAN ID which related bit is equal to filter bit value. Suffix "X" or "x" denotes Mask is Extended 29 bits of data. Mask0/1/2 are only used for dspic33. For other platforms, just ignore them. |
| • | Mask1 — CAN Bus receiver's the 2nd Mask register. If bit of Mask register is 1, CAN Bus receiver will only receive CAN ID which related bit is equal to filter bit value. Suffix "X" or "x" denotes Mask is Extended 29 bits of data. Mask0/1/2 are only used for dspic33. For other platforms, just ignore them. |
| • | Mask2 — CAN Bus receiver's the 3rd Mask register. If bit of Mask register is 1, CAN Bus receiver will only receive CAN ID which related bit is equal to filter bit value. Suffix "X" or "x" denotes Mask is Extended 29 bits of data. Mask0/1/2 are only used for dspic33. For other platforms, just ignore them. |
| • | Rx CAN ID for short frame or RTR — It is CAN IDs for receiver's short frame. Short frame means RTR frame or Data frame with data byte QTY<=8. You should use row vector for all CAN IDs. If only one CAN ID you are interested in, you can use scalar. If CAN ID is extended frame, please use suffix "X" or "x". Please don't use any quotation mark. And you must make sure received CAN IDs from the filters and masks in IDE GUI Configuration tool (such as MCC for microchip MCU) cover these parameters. |
| • | Rx CAN ID for long frame — It is CAN IDs for receiver's long frames. Long frame means multiple data frames and the first data byte is frame number. It can be used Data bytes QTY is bugger than 8. You should use row vector for all CAN IDs. If only one CAN ID you are interested in, you can use scalar. If CAN ID is extended frame, please use suffix "X" or "x". Please don't use any quotation mark. And you must make sure received CAN IDs from the filters and masks in IDE GUI Configuration tool (such as MCC for Microchip MCU) cover these parameters. |
| • | Frame Number — It is radio button to select the first frame number for long frame. Two different first frame numbers are 0 and 1. |
| • | Max frame Qty for long frame Rx/Tx — Because frame number for long frame occupies 1 byte, so for 0-based frame number, you can have maximum 256 frames for one long frame. For 1-based frame number, you can have maximum 255 frames for one long frame. Actually, for specific project, we only need a few of frames for one long frame. This parameter specifies the maximum frame Qty for long frame transmitting and receiving in order to save embedded MCU memory resource. |
| • | Sync Enable — When it is true, embedded CAN Bus controller only transmits when it receives a special CAN ID called "Sync Rx frame". In general, if we only have One transmitting Channel, then received Sync CAN ID rate is usually a little smaller than Channel transmitting rate. In this way, Every transmitting will occur when received "Sync Rx frame". If we have multiple transmitting Channels, and received Sync CAN ID rate is a little smaller than the one of the most slowest transmitting rate Channel. Then only the most slowest transmitting rate Channel will synchronize with "Sync Rx frame". The other channels will transmit at any time no matter whether it received "Sync Rx frame" periodically if it received one time "Sync Rx frame". |
| • | Sync Rx CAN ID — CAN ID of "Sync Rx frame'". Suffix "x" or "X" denotes extended 29 bits CAN ID. If "Sync Enable" is true, embedded CAN Bus controller only transmits when it receives this CAN ID frame. |
| • | CAN bus communication fault detection time in ms: — When embedded CAN bus Controller didn't receive any valid CAN bus frame which is filtered by Filter and mask registers in specified time, this block output port "Fault" becomes "true" to indicate "CAN Bus communication fault". This specified time is called "CAN bus communication fault detection time". It is similar to communication "Watchdog". |
| • | Max Sequence Qty for CAN BUS transmit A Channel — We have introduced this embedded CAN bus function at beginning. Every Channel can have as many as 31 sequences (Seq No is from 0 to 30). However, in order to decrease memory consumption for embedded target, we can specify small sequences QTY. This parameter specifies actual sequences QTY for Channel A. |
| • | Max Sequence Qty for CAN BUS transmit B Channel — We have introduced this embedded CAN bus function at beginning. Every Channel can have as many as 31 sequences (Seq No is from 0 to 30). However, in order to decrease memory consumption for embedded target, we can specify small sequences QTY. This parameter specifies actual sequences QTY for Channel B. |
| • | Max Sequence Qty for CAN BUS transmit C Channel — We have introduced this embedded CAN bus function at beginning. Every Channel can have as many as 31 sequences (Seq No is from 0 to 30). However, in order to decrease memory consumption for embedded target, we can specify small sequences QTY. This parameter specifies actual sequences QTY for Channel C. |
| • | Sample time in sec (-1 for inherited): — Sample time for this block. It is the same meaning as general Simulink block . |
Ports
Input
None
Outport
| • | Fault — "logical" data type's scalar. "True" means CAN bus controller didn't receive any valid CAN bus frame which is filtered by Filter and mask registers in time specified by parameter "CAN bus communication fault detection time in ms". |
Examples
|