CAN receive
Block to receive CAN messages
Description
A 'CAN Receive' block instructs the code generator to include CAN support.
Each time the block is evaluated, the last message with the given CAN ID is used
to get the output values. The 'new data' output gives a 1 or higher (true) if new data
was received since the last evaluation, otherwise a 0 (false).
Remarks
- Always use a CAN config block to configure the CAN channel enabling and used baud rate.
- Two IDs are reserved for the XCP protocol by design, the CAN channel depends on the 'XCP Config' block.
- The receive mechanism adds and reserves 1 slot for each receive ID used, the number of ID's is limited by the amount of available memory (heap).
- The CAN message supports a message up to 8 bytes. This block
enables the user to specify the classification.
- The CAN receive block has build-in support for endianes conversion.
Use this support if the sending system uses a different endianes.
The STM32 is Little-endian (LSB first).
- Connect the 'new data' output to a terminator if it is not used.
- A 'new data' value exceeding 1 indicates that messages where lost (only the most recent message is preserved). Consider increasing the sample rate of the CAN receive block.
- A 'new data' value of -1 indicates a error.
- The 'new data' is maxed at 127 (so more messages might be received since the last sample).
Declaration
Use the CAN config block:
- To set the baud rate for the selected CAN channel.
- To enable the specific CAN channel.
Input
The input port specifies the CAN ID of the message in hexadecimal format. The CAN ID must be applied in a UINT32 signal.
Set the 32nd bit to 1 in the CAN ID to configure it as a 29-bit Extended CAN identifier. For example 0x80000200 for CAN ID 0x200 as
29-bit identifier.
Output
- Output 1
- The first output indicates new data was received; a 0 (false) represents no new data, > 0 (true) represents the number of new messages and -1 indicates a error.
- This will be returned as an int8. Important: note that the message data outputs only contain valid data if this output is > 0 (true).
- Remaining outputs
- The remaining 1 up to 8 outputs are for data,
- the number of ports and the port type depends on the configuration.
Parameters
- CAN channel
- Select the used channel.
- Output ports
- Select the amount of ports you want from the given output type.
You can use only up to 8 bytes.
- Output type
- Select the data type each output port will use.
- Byte ordering
- Set the appropriate byte ordering for your CAN message:
- Checkbox checked = Most Significant Bit (MSB) is received first (Motorola format).
- Checkbox unchecked = Least Significant Bit (LSB) is received first (Intel format).
- Sample time
- Sample time of the block. The Sample time (in seconds) defines
the rate at which the block is visited by the real-time scheduler of
the target. The value of the Sample time has to be an integer multiple
of the base sample time of the model.