2018-12-10 09:10 AM
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
Solved! Go to Solution.
2018-12-11 09:23 AM
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.
2018-12-10 10:08 AM
I'm wondering if what you are asking about has anything to do with MASTER and SLAVE CAN peripheral nomenclature too ?
2018-12-10 10:31 AM
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.
2018-12-10 10:59 AM
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.
2018-12-10 11:24 AM
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
2018-12-10 11:29 AM
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.
2018-12-10 02:49 PM
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 ?
2018-12-10 03:29 PM
Doesn't it place the pin initialization stuff in the MSP file?
2018-12-10 03:31 PM
The prescaler divides the APB clock down, the baud/bitrate can then be deduced by summing the quanta settings and dividing the clock again.
2018-12-10 11:39 PM
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