新手请教大家,stm32f4xx_dsp_stdperiph_lib_um.chm这个官方帮助文档里面CAN Networking example这个例子,
在配置时钟和can波特率的时候看不明白了!
system_stm32f4xx.c里面是这样配置的:
00045 * Supported STM32F40xx/41xx/427x/437x devices
00046 *-----------------------------------------------------------------------------
00047 * System Clock source | PLL (HSE)
00048 *-----------------------------------------------------------------------------
00049 * SYSCLK(Hz) | 168000000
00050 *-----------------------------------------------------------------------------
00051 * HCLK(Hz) | 168000000
00052 *-----------------------------------------------------------------------------
00053 * AHB Prescaler | 1
00054 *-----------------------------------------------------------------------------
00055 * APB1 Prescaler | 4
00056 *-----------------------------------------------------------------------------
00057 * APB2 Prescaler | 2
00058 *-----------------------------------------------------------------------------
00059 * HSE Frequency(Hz) | 25000000
00060 *-----------------------------------------------------------------------------
00061 * PLL_M | 25
00062 *-----------------------------------------------------------------------------
00063 * PLL_N | 336
00064 *-----------------------------------------------------------------------------
00065 * PLL_P | 2
00066 *-----------------------------------------------------------------------------
00067 * PLL_Q | 7
我的理解是,晶振25M,25/25*336/2=168M是PLL频率,作为系统工作频率。然后AHB分频1,还是168M。
再分频 ,APB1 Prescaler=4,所以APB1是168/4=42M。can就接在APB1上,所以也应该是42M。(应该没错吧?)
但是,不明白的地方来了,main.c里面又是这样配置can的:
00153 CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
00154
00155 /* CAN Baudrate = 1 MBps (CAN clocked at 30 MHz) */
00156 CAN_InitStructure.CAN_BS1 = CAN_BS1_6tq;
00157 CAN_InitStructure.CAN_BS2 = CAN_BS2_8tq;
00158 CAN_InitStructure.CAN_Prescaler = 2;
00159 CAN_Init(CANx, &CAN_InitStructure);
注释说CAN clocked at 30 MHz,然后也确实30/((1+6+8)*2)=1M,CAN的波特率就是1M了。。。
那APB1=42M又是怎么回事?新手请教大家,现在自己的程序都不知道怎么配置了……
|