can_nominal_bit_rate_set()

can_nominal_bit_rate_set()

Description

Sets (or overrides) the nominal arbitration-phase bit rate of an already-initialized CAN interface.

Syntax

can_nominal_bit_rate_set(can_interface, can_bit_rate);

Parameters

Parameter

Description

can_interface

CAN interface to configure – CAN1 or CAN2.

can_bit_rate

Nominal bit rate, in bit/s (e.g. 500000 for 500 kbit/s).

Returns

Return value

Return explanation

SCRIPT_OPERATION_SUCCESS

The operation completed successfully.

SCRIPT_OPERATION_FAILED

The operation could not be completed (invalid state, hardware error, etc.).

SCRIPT_NO_ACCESS

The CAN interface has not been initialized (call can_fd_init first).

SCRIPT_PARAM_INVALID

One or more passed parameters are invalid.

Function call example

#include <io> #include <read> #include <float> #include <string> #include <core> #include <write> #include <define> #include <socket> #include <can> #define CAN_BUS CAN1 new can_rx_buffer{4096}; main() { can_fd_init(CAN_BUS, CAN_CTRL_MODE_NORMAL | CAN_CTRL_MODE_ONE_SHOT | CAN_CTRL_MODE_FD_BRS, 2000, 500000, can_rx_buffer); can_nominal_bit_rate_set(CAN_BUS, 500000); for(;;) { Delay(1000); } }

Notes and Warnings

  • The value is in bit/s, not kbit/s. Passing 500 instead of 500000 silently configures a 500 bit/s bus, which will fail to communicate with any real node.