cancel
Showing results for 
Search instead for 
Did you mean: 

Can bit segments?

turboscrew
Senior III

What are the CAN bit segment 1 and 2?

CAN specification doesn't use those names.

Are they PROP_SEG and PHASE_SEG1 or PHASE_SEG1 and PHASE_SEG2?

All three are programmable by the CAN spec, but PHASE_SEG2 should be max. of PHASE_SEG1 and INFORMATION PROCESSING TIME which is "less than or equal to 2 time quanta".

I would guess that bit segment 1 = PROP_SEG and bit segment 2 = PHASE_SEG1. PHASE_SEG2 is then probably equal to PHASE_SEG1.

Is that right?

I also realized that in STM32F427 data sheets it says that CAN can work upto 1Mbps.

I wonder how? Is there Cube restriction or why it seems impossible?

With "full speed" (APB1@45MHz) I tried to set prescaler to 5, bit segment1 to 2 and bit segment2 to 3, but CubeMX says they are too small values.

I'd think that it would mean:

Tq=111.11 ns,

SYNC_SEG = 1Tq

PROP_SEG = 2Tq

PHASE_SEG1=3Tq

PHASE_SEG2=3Tq

Total 9Tq/bit = 999.99ns

1 ACCEPTED SOLUTION

Accepted Solutions
turboscrew
Senior III

Funny. At work CubeMX accepted my settings, and also the prescaler was decremented.

Maybe I have some very old version at home...?

With the chip mentioned, the APB clock is 45MHz (max), and prescaler 5 and bit segments 5 and 3 gave 1Mbps rate. No errors - at least in the first about 130000 messages.

View solution in original post

12 REPLIES 12
Gudgel.boB
Senior

I'm wondering if what you are asking about has anything to do with MASTER and SLAVE CAN peripheral nomenclature too ?

turboscrew
Senior III

Both have their own bitrates.

And to my knowledge, the difference is that MASTER controls the common resources. The activity is independent. (The limitation of master to 14 filter banks is due to Cube. HW allows all 28 to be used by master.)

To be clear, I'm only using master.

turboscrew
Senior III

Aha, this seems to be one of those things again: the moment you ask, you find the info. :D

It says in the reference manual:

"Bit segment 1 (BS1): defines the location of the sample point. It includes the

PROP_SEG and PHASE_SEG1 of the CAN standard"

And the values are one less than what's used.

If I want a prescaler 5, I put 4 in the BRP and the same goes with TS1 and TS2 fields (in CAN_BTR).

But cube still doesn'ẗ let me put TS1 to 4 and TS2 to 2 when BRP is 4.

I guess that would mean:

Tq=111.11 ns,

SYNC_SEG = 1Tq

PROP_SEG + PHASE_SEG1=5Tq

PHASE_SEG2=3Tq

Total 9Tq/bit = 999.99ns

OMG: Cube wants the actual prescaler - it decrements one from it...

 And it still doesn't accept bit segment2 = 2.

turboscrew
Senior III

I generated the code and I'm now even more confused.

It looks like Cube puts the prescaler in the register "as is", but decrements one from the quanta-values.

So the quantum length seems to be wrong?

45 MHz = 22.22 ns, 5*22,22ns = 111.11ns, as CubeMX calculates - except:

"BRP[9:0]: Baud rate prescaler

These bits define the length of a time quanta.

tq = (BRP[9:0]+1) x tPCLK"

So actually the the prescaler is 22.22ns * 6 = 133.33ns not 111,11ns

Gudgel.boB
Senior

Thank you Turbo ! I'm using CAN 1 Master as well which is good (I think).... Haven't actually programmed that part yet but did add the HAL code and initialization code to my IAR project and after a short bit of hair tearing out, got it to all compile and work to the previous way.

Gudgel.boB
Senior

I have found that it seems that the Cube Code generated is not always "complete". For instance, I have always had to add the GPIO pin enables portion of the code by hand.

I suppose that for CAN, a similar thing could happen where the timing is not quite right.

Have you gone to the Cube timing page to see if the timers are configured properly ?

I don't remember off hand if that is the way to go for the CAN or UART peripherals but maybe ?

Doesn't it place the pin initialization stuff in the MSP file?​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

The prescaler divides the APB clock down, the baud/bitrate can then be deduced by summing the quanta settings and dividing the clock again.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Mark Shoe
Senior

You can calculate the baudrate of CAN clock

APB1 / (1 + seg1+ seg2) / prescaler

For example my APB1 is 37.5 mhz

37.5mhz / 1 + 8 +1 / 30 =  125khz bittime is 8000ns

Now cube shows Time Quantum 800.0 ns I do not know what this is, better show the CAN baudrate!

On http://www.bittiming.can-wiki.info/ is a calculator for the ST settings. Please ST include this calculator in CubeMX