Calculate CAN bit timing
calc_can_bit_timingComputes the CAN bit timing for a clock, a bit rate and a sample point: prescaler, time quanta, both segments and the jump width, with the real bit rate, the real sample point and the register value. Use it when setting up CAN or CAN FD instead of working the values out by hand. The controller classic gives the counts for a classic CAN controller whose time quantum is the prescaler times the clock period, within the fields most of them have: a prescaler up to 64, segments up to 16 and 8 quanta, and a jump width up to 4. sja1000 and mcp2515 are those two controllers, which halve the oscillator before the prescaler and have limits of their own. With bxcan (CAN_BTR of STM32) or mcan-nominal and mcan-data (NBTP and DBTP of Bosch M_CAN, which several vendors use for CAN FD), it also packs the register value.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"controller": "<controller>",
"clock_hz": "<clock_hz>",
"bit_rate": "<bit_rate>"
},
"name": "calc_can_bit_timing"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bit_rate | Yes | The bit rate in bits per second, for example 500000. Above 1000000 only for mcan-data. | |
| clock_hz | Yes | The clock that feeds the bit timing logic of the CAN controller, in Hz. It is often not the core clock. For sja1000 and mcp2515, the frequency of the oscillator. | |
| controller | Yes | classic (counts only, a plain prescaler), sja1000 or mcp2515 (counts only), bxcan, mcan-nominal (arbitration phase) or mcan-data (the data phase of CAN FD). | |
| sample_point | No | The wanted sample point as a fraction of the bit. Default 0.875, which CANopen and DeviceNet use. |