cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F04 CAN init

danielblesener9
Associate II
Posted on April 09, 2015 at 19:43

The original post was too long to process during our migration. Please click on the attachment to read the original post.
4 REPLIES 4
Posted on April 09, 2015 at 20:51

CAN_InitStructure.CAN_Prescaler = 299;        //This is BRP reg - can be between 1 and 1024...BRP = what is in reg + 1 (1 starts at 0)

This isn't the BRP register, the SPL subtracts ONE, you don't do it here. If you're dividing the APB clock by 300, use 300

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jpeacock
Associate III
Posted on April 10, 2015 at 13:58

Do you have two CAN nodes?  Loopback will work with one node but otherwise you need two in order for transmit to work properly.  A single node will see transmit errors and stop.  Look at your transmit error count.

  Jack Peacock

richardtearle
Associate
Posted on April 10, 2015 at 14:49

Are you using a STM32F042Fx or STM32F042Gx device? If so you need to remap PA11/12 instead of pin pair PA9/10 using the SYSCFG_CFGR1 register. Page 174 of the reference manual (RM0091).  

Do you have terminators on the bus?

I have some code that has the CAN module correctly working at 125Kbit/s on a STM32F042K device, but it's all in assembler.
danielblesener9
Associate II
Posted on April 11, 2015 at 17:23

Clive - thanks for the response. You are right that TS1/TS2 and BRP define BTR. But that specific part of the initialization initialized the BRP portion doesn't it? When the structure is initialized it is combined with TBS1 (TS1) and TBS2 (TS2) to define CAN_BTR as shown by figure 317 of reference manual. I didn't notice that the init structure automatically subtracts 1 though (for BPR)! Thanks for that!