Skip to main content
ma.alam9
Associate II
Mar 29, 2021 11:16 AM UTC
Question

STM32G474 FDCAN BitTiming Register values?

Hello All,

I got Classic CAN running on the FDCAN3 module of STM32G474CE device using MXCube and other example projects for STM32G474 devices.

Problem is, all these example codes have a fixed baud rate of 1Mbps. My application requires thebaud rate be configurable. Until now, I have not been able to find any table / calculator on the internet that could calculate the bit timing register values for me, based on kernel clock and required baud rate etc... Does anyone here have any clue on this?

This topic has been closed for replies.

4 replies

Bowman32
ST Employee
Mar 31, 2021 4:23 PM UTC

Hello @Community member​ 

You can refer to section "44 FD controller area network (FDCAN)" of STM32G4 reference manual with focus on section "44.3.1 Bit timing".

Bouraoui

PHryn
Associate III
Nov 12, 2021 12:03 PM UTC
Associate
Sep 2, 2023 10:43 PM UTC

You are a beast. This calculator is amazing!!

Visitor II
Jul 30, 2025 12:45 PM UTC
#define CAN_BITRATE ((uint32_t)500000)
#define CAN_SAMPLE_POINT ((uint8_t)75)
#define CAN_CLOCK ((uint32_t)60000000)
#define CAN_PRESCALER ((uint16_t)2)

/**
 * @brief CAN bit timing calculation
 * @PAram uint32_t: Bitrate (bit/s)
 * @PAram uint8_t: Sample point (%) 
 * @PAram uint32_t: Can clock (Hz)
 * @PAram uint16_t: Prescaler
 * @retval uint32_t: NBTP data
 */
uint32_t CanBitTimingCalculation(uint32_t bitrate, uint8_t samplePoint, 
 uint32_t canClock, uint16_t prescaler)
{
 uint32_t nbt = (uint32_t)(canClock / prescaler / bitrate);
 uint32_t seg2 = (uint32_t)(nbt * (100 - samplePoint) / 100);
 uint32_t seg1 = (uint32_t)(nbt - seg2 - 1);
 
 return ((uint32_t)(((seg1 - 1) << FDCAN_NBTP_NTSEG1_Pos) |
 ((seg2 - 1) << FDCAN_NBTP_NTSEG2_Pos) |
 ((prescaler - 1) << FDCAN_NBTP_NBRP_Pos)));
}

void CanInitNbtp(void)
{
 FDCAN1->NBTP = CanBitTimingCalculation(CAN_BITRATE, CAN_SAMPLE_POINT, 
 CAN_CLOCK, CAN_PRESCALER);
}