1
votes

I am trying to set up a CAN (Controller Area Network) communication between a STM32446E-EVAL and a software application on my PC. The problem is that as soon as I try to receive or transmit a byte, "the dominant error bit" error appears in one of the registers and I suspect it has something to do with the baud rate from what I read on other forums but I couldn't find any option in the official STM IDE to set the baud rate...Does anyone have an idea on how I can set it properly?

3
What is your value for PCLK? What have you set TS1, TS2 and BRP to in the CAN_BTR register?Clifford

3 Answers

1
votes

From the reference manual §30.7.7 Bit timing: enter image description here

Rearranging that: BRP = (FPCLK / (BaudRate x (TS1 + TS2 + 3))) - 1

Not all values of TS1 and TS2 result in an integer value for the above formula, so will not generate the correct baud rate. Moreover you have to consider the sample point - various CAN application protocols have specific preferred sample point recommendations, but must in any event be between 50% and 90%. The sample point in percentage terms is:

1 - ((TS2+1) / (TS2+TS1+3)) x 100%

So there are multiple solutions with respect to TS1/TS2 values, but each gives a different sample point, so you need to select values that:

  1. Generate exactly 500Kbps (NBT = 2 microseconds).
  2. Has a sample point as near to the preferred value as possible in the range 50 to 90%.

It is not perhaps straight-forward, and without knowing your FPCLK not possible to advise specifically. I created a spreadsheet that generates all valid possibilities with their respective sample point.

Example for FPCLK = 42MHz: enter image description here

Based on the above, TS1=10, TS2=1, BRP=5, will result in 500Kbps with a sample point of 85.7% - Close to the CANopen recommendation of 87.5%.

These values agree with the calculator at http://www.bittiming.can-wiki.info/ enter image description here Noting that the values in the table are the register values + 1.

0
votes

Step one: learn what the CAN time quanta is : http://www.bittiming.can-wiki.info/

Step two: check what your can clock is : from your project.

Step three: put this value into the page above.

Step four: get your values ready!!

Step five: program the appropriate CAN register (or struct members if you use HAL) with the step4 values.

Step six : celebrate the success.

0
votes

I had a similar problem when I was working on a project. I wasn't using the exact board as you, but it was still a STM32 and I was using CubeMx IDE. There is a .ioc file in your project most likely and there you have a field called "Parameter settings" where you will find more fields. In my case I changed the prescaler and the Bit time quanta 1 and 2, as mentioned in the answer above. Now of course, it depends on the configuration of your particular board, but in my case the "winning combination" was 8 for Prescaler and 6 and 5 for the quantas. I used an oscilloscope for measurement until I found out that those were the right values. Changing those 3 parameters should do the trick.