cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103VCT6 CAN Bit timing settings

chandrashekharchinta
Associate II
Posted on November 18, 2014 at 14:54

I am using STM32F103VCT6 controller in one of our product and we need to configure CAN bit timings to work at 125KBPS, 250KBPS and 500KBPS at clock frequency of 36MHz (max system clock on bus). I need to know two things:

1. I am setting CAN BTR register to value 0x034B000F to work at 125KBPS. As per settings I should get Bit Sampling point at 77% but I am getting Bit Sampling point at 72%. I don't understand why.

2. What CAN BTR register value I have to set to get Bit Sampling point at more than 85% for all three baud rates (125KBPS, 250KBPS and 500KBPS)

Please help me out.
4 REPLIES 4
Posted on November 18, 2014 at 19:06

Are you using the Standard Peripheral Library to configure the CAN interface? Is so what settings are you currently using?

Generally speaking you can control the prescaler, and quanta settings, I don't have a huge amount of CAN Bus experience, and don't plan to dig into the bit level options on the STM32, but perhaps you can explain what and how you're measuring things?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
chandrashekharchinta
Associate II
Posted on November 19, 2014 at 12:31

Hi Clive, thanks for putting time into this. I have put here quick calculations on how I have came up with CAN BTR register value from controller's datasheet

BaudRate =    1 / NominalBitTime

NominalBitTime = 1

×

tq + tBS1 + tBS2

with:

tBS1 = tq x (TS1[3:0] + 1),

tBS2 = tq x (TS2[2:0] + 1),

tq = (BRP[9:0] + 1) x tPCLK           //where tq refers to the Time quantum

tPCLK

= time period of the APB clock,

BRP[9:0], TS1[3:0] and TS2[2:0] are defined in the CAN_BTR Register.

  

Thanks!

Are you using the Standard Peripheral Library to configure the CAN interface? Is so what settings are you currently using?

Generally speaking you can control the prescaler, and quanta settings, I don't have a huge amount of CAN Bus experience, and don't plan to dig into the bit level options on the STM32, but perhaps you can explain what and how you're measuring things?

Posted on November 19, 2014 at 15:57

  /* CAN Baudrate = 1MBps*/

  CAN_InitStructure.CAN_SJW = CAN_SJW_1tq; // 1..4

  CAN_InitStructure.CAN_BS1 = CAN_BS1_3tq; // 1..16

  CAN_InitStructure.CAN_BS2 = CAN_BS2_5tq; // 1..8

  CAN_InitStructure.CAN_Prescaler = 4; // 1..1024

  CAN_Init(CANx, &CAN_InitStructure);

APB / ((SWJ + BS1 + BS2) * Prescaler)

36000000 / ((1 + 3 + 5) * 4)

36000000 / (9 * 4)

36000000 / 36

1000000

To give the maximum flexibility (finest granularity) you want to use the smallest Prescaler

How this manifests in the physical signal properties you're looking for harder for me to determine, but as best I can tell it's by playing with the ratios here.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
chandrashekharchinta
Associate II
Posted on November 20, 2014 at 12:35

I am setting bit time segments in CAN BTR register to following values so that sample point is at about 88% bit time from bit start -

Baud rate prescalar = 16,

TSEG1 = 15,

TSEG2 = 2,

SJW = 2,

1 CAN bit = 18 TQ (time quanta)

So CAN BTR register = 0x011E000F (for 125KBPS baud rate)

I need to know if anyone has verified the whether CAN Bit is being sampled at calculated Bit Sampling Point on DSO or somehow?

Thanks!