Article
CAN bit timing on STM32G4 at 500 kbit/s: a worked FDCAN example
By CAEE Engineering Team · Updated 6 Nov 2026 · 7 min read
How to set STM32G4 FDCAN bit timing for 500 kbit/s: prescaler, time segments, sample point and SJW, with worked values for 170, 80 and 24 MHz clocks.

Short answer: with a 170 MHz FDCAN kernel clock, set
NominalPrescaler = 17,NominalTimeSeg1 = 15,NominalTimeSeg2 = 4andNominalSyncJumpWidth = 4. That gives a 100 ns time quantum, 20 quanta per bit (2 µs, which is 500 kbit/s) and a sample point at 80 %.
The rest of this article shows where those numbers come from, how to pick values for other clocks, and how to check the result on a real bus.
How a CAN bit is built
The FDCAN peripheral divides every bit into equal slices called time quanta (tq). One bit has three parts:
- Sync segment — always 1 tq. Signal edges are expected here.
- Time segment 1 (TSEG1) — the propagation segment and phase segment 1 together. The bus is sampled at the end of TSEG1.
- Time segment 2 (TSEG2) — phase segment 2, after the sample point.
The formulas, using the STM32 HAL field names:
| Quantity | Formula |
|---|---|
| Time quantum | tq = NominalPrescaler ÷ f_FDCAN |
| Quanta per bit | N = 1 + NominalTimeSeg1 + NominalTimeSeg2 |
| Bit time | N × tq |
| Bit rate | 1 ÷ (N × tq) |
| Sample point | (1 + NominalTimeSeg1) ÷ N |
Here f_FDCAN is the FDCAN kernel clock after the FDCAN clock divider (ClockDivider, normally 1).
Worked example: 170 MHz to 500 kbit/s
- One bit at 500 kbit/s lasts 1 ÷ 500 000 = 2 µs.
- At 170 MHz that is 170 000 000 × 0.000002 = 340 clock cycles per bit.
- Split 340 into prescaler × quanta: 340 = 17 × 20. A prescaler of 17 gives tq = 17 ÷ 170 MHz = 100 ns, and 20 quanta make the 2 µs bit.
- Place the sample point: 1 (sync) + 15 (TSEG1) + 4 (TSEG2) = 20 tq. The bus is sampled after 16 tq, so the sample point is 16 ÷ 20 = 80 %.
- Make the synchronisation jump width (SJW) as large as allowed. It may not be longer than the shorter phase segment, so SJW = 4.
Settings for other clock frequencies
Every row gives exactly 500 kbit/s.
| FDCAN clock | Prescaler | tq | tq per bit | TSEG1 | TSEG2 | SJW | Sample point |
|---|---|---|---|---|---|---|---|
| 170 MHz | 17 | 100 ns | 20 | 15 | 4 | 4 | 80 % |
| 170 MHz | 17 | 100 ns | 20 | 16 | 3 | 3 | 85 % |
| 170 MHz | 2 | 11.76 ns | 170 | 135 | 34 | 34 | 80 % |
| 80 MHz | 1 | 12.5 ns | 160 | 127 | 32 | 32 | 80 % |
| 80 MHz | 4 | 50 ns | 40 | 31 | 8 | 8 | 80 % |
| 24 MHz | 3 | 125 ns | 16 | 13 | 2 | 2 | 87.5 % |
The HAL accepts NominalPrescaler from 1 to 512, NominalTimeSeg1 up to 256, NominalTimeSeg2 up to 128 and NominalSyncJumpWidth up to 128, so even a 170 MHz clock with a prescaler of 2 fits.
Which sample point should you use?
- All nodes on one bus should sample at (nearly) the same point. If you are joining an existing vehicle network, use the value from that network's specification.
- CAN FD networks: CiA 601-3 advises against an arbitration-phase sample point later than 80 % in automotive applications, for robustness. 80 % is a good default for a new network that may move to CAN FD later.
- Classical CANopen networks commonly use 87.5 %.
Sampling later allows a longer bus; sampling earlier improves robustness.
Clock source and clock accuracy
The FDCAN kernel clock can come from the HSE oscillator, the PLL "Q" output or PCLK1. You select it in the RCC_CCIPR register (in STM32CubeMX: the FDCAN clock mux). Use a crystal-based clock: HSE itself, or a PLL fed from HSE. The NUCLEO-G474RE has a 24 MHz crystal for HSE. The internal 16 MHz RC oscillator (HSI16) is much less accurate than a crystal and drifts with temperature, so it makes a poor CAN clock.
How much clock error does a setting tolerate? Bosch's bit-timing paper gives two conditions, and both must hold. N is the number of quanta per bit and df is the allowed deviation of each node's clock:
- df ≤ min(Phase_Seg1, Phase_Seg2) ÷ (2 × (13 × N − Phase_Seg2))
- df ≤ SJW ÷ (20 × N)
For the 20-tq setting above (Phase_Seg2 = 4, SJW = 4, with at least 4 tq of TSEG1 left for phase segment 1): 4 ÷ (2 × 256) = 0.78 % and 4 ÷ 400 = 1.0 %. Each clock may therefore be off by up to about 0.78 %, which a crystal easily meets. The 16-tq setting with SJW = 2 tolerates only about 0.49 %, which is one reason to prefer more quanta per bit and a larger SJW.
Planning the clock for CAN FD
CiA 601-2 and 601-3 recommend a 20, 40 or 80 MHz CAN clock for CAN FD networks, with the same, low prescaler in both phases. With a 170 MHz system clock made from the 24 MHz crystal, none of the FDCAN clock options gives 80 MHz. If you plan a fast CAN FD data phase, one option on the NUCLEO-G474RE is: HSE 24 MHz ÷ PLLM 6 × PLLN 80 = 320 MHz VCO, then PLLR ÷ 2 = 160 MHz system clock and PLLQ ÷ 4 = 80 MHz FDCAN clock. For classical CAN at 500 kbit/s, the 170 MHz setting above is fine.
HAL code (STM32CubeG4)
FDCAN_HandleTypeDef hfdcan1;
void MX_FDCAN1_Init(void)
{
hfdcan1.Instance = FDCAN1;
hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1;
hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
hfdcan1.Init.AutoRetransmission = ENABLE;
hfdcan1.Init.TransmitPause = DISABLE;
hfdcan1.Init.ProtocolException = DISABLE;
/* 170 MHz / 17 = 10 MHz -> tq = 100 ns; 1 + 15 + 4 = 20 tq = 2 us -> 500 kbit/s, sample point 80 % */
hfdcan1.Init.NominalPrescaler = 17;
hfdcan1.Init.NominalSyncJumpWidth = 4;
hfdcan1.Init.NominalTimeSeg1 = 15;
hfdcan1.Init.NominalTimeSeg2 = 4;
/* data-phase values are used only with FDCAN_FRAME_FD_BRS */
hfdcan1.Init.DataPrescaler = 1;
hfdcan1.Init.DataSyncJumpWidth = 1;
hfdcan1.Init.DataTimeSeg1 = 1;
hfdcan1.Init.DataTimeSeg2 = 1;
hfdcan1.Init.StdFiltersNbr = 1;
hfdcan1.Init.ExtFiltersNbr = 0;
hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
{
Error_Handler();
}
}
Two details catch people out:
- The HAL subtracts 1.
HAL_FDCAN_Init()writes NominalPrescaler − 1, NominalTimeSeg1 − 1 and so on into the FDCAN_NBTP register. If you program the register directly, write 16, 14, 3 and 3 for the example above. - ClockDivider is shared. It applies to every FDCAN instance, and the HAL writes it only while initialising FDCAN1.
Check it on a real bus
- Measure a bit. With an oscilloscope on the FDCAN TX pin or across CANH–CANL, the shortest pulse should be 2.0 µs.
- Read the error state.
HAL_FDCAN_GetProtocolStatus()returns LastErrorCode (stuff, form, ACK, bit or CRC error), ErrorPassive and BusOff.HAL_FDCAN_GetErrorCounters()returns TxErrorCnt and RxErrorCnt. On a healthy bus the counters stay at or near zero. - ACK errors on a two-node bench usually mean the other node is not receiving: it is not running, it uses a different bit rate, or its transceiver is in standby.
- Termination. With the power off, measure the resistance between CANH and CANL. About 60 Ω means both 120 Ω terminators are fitted.
- Transceiver. The NUCLEO-G474RE has no CAN transceiver, so you need one, for example a Microchip MCP2562FD. Hold its STBY pin low for normal mode (in standby it cannot transmit) and connect its VIO pin to 3.3 V to match the STM32 logic level. FDCAN1 is available on PA11 (RX) / PA12 (TX) or PB8 (RX) / PB9 (TX), alternate function 9.
Common mistakes
- Typing register values (value − 1) into the HAL fields, or HAL values into the register.
- Different sample points or quanta per bit on different nodes. The errors may only appear with a longer cable or at high temperature.
- Using HSI16 as the CAN clock.
- An SJW longer than the shorter phase segment (in practice, longer than TSEG2).
Sources
- STMicroelectronics, RM0440 Reference manual: STM32G4 Series (FDCAN and RCC chapters)
- STMicroelectronics, AN5348 Introduction to FDCAN peripherals for STM32 MCUs
- STMicroelectronics, STM32CubeG4 HAL driver, stm32g4xx_hal_fdcan.c
- STMicroelectronics, UM2505 STM32G4 Nucleo-64 boards (MB1367) user manual
- ISO 11898-1:2024 Road vehicles — Controller area network (CAN) — Part 1: Data link layer and physical coding sublayer
- CAN in Automation, CiA 601 series: CAN FD guidelines and recommendations
- H. Zeltwanger, Recommendation for the CAN FD bit-timing, CAN Newsletter, March 2018
- F. Hartwich and A. Bassemir (Robert Bosch GmbH), The Configuration of the CAN Bit Timing, 6th International CAN Conference, 1999
- Microchip, MCP2562FD high-speed CAN FD transceiver
All articles · CAN / CAN-FD Internship · FOC Motor Control Internship · Free workshops