I can recommend the following projects for a CAN example:
STM32-baudrate-calculation-1.0.zip
Circle_4.11/OS/library/stm32f10x_can.c
int CAN_driver_init(BaudRateT rate)
{
comBaudRate = rate;
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
/* CAN register init */
CAN_DeInit(CAN1);
CAN_StructInit(&CAN_InitStructure);
/* CAN cell init */
// Reference Manual: If ABOM is set, the bxCAN will start the recovering
// sequence automatically after it has entered Bus-Off state.
CAN_InitStructure.CAN_TTCM = DISABLE;
CAN_InitStructure.CAN_ABOM = ENABLE; // ENABLE
CAN_InitStructure.CAN_AWUM = DISABLE;
CAN_InitStructure.CAN_NART = DISABLE;
CAN_InitStructure.CAN_RFLM = DISABLE;
CAN_InitStructure.CAN_TXFP = DISABLE;
CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
switch (rate)
{
case BAUD_10KBIT:
// LCD_display_Text(0,40," 10kBit");
CAN_InitStructure.CAN_Prescaler = 200;
CAN_InitStructure.CAN_BS1 = 8;
CAN_InitStructure.CAN_BS2 = 7;
break;
case BAUD_20KBIT:
// LCD_display_Text(0,40," 20kBit");
CAN_InitStructure.CAN_Prescaler = 100;
CAN_InitStructure.CAN_BS1 = 8;
CAN_InitStructure.CAN_BS2 = 7;
break;
case BAUD_50KBIT:
// LCD_display_Text(0,40," 50kBit");
CAN_InitStructure.CAN_Prescaler = 40;
CAN_InitStructure.CAN_BS1 = 8;
CAN_InitStructure.CAN_BS2 = 7;
break;
case BAUD_125KBIT:
// LCD_display_Text(0,40,"125kBit");
CAN_InitStructure.CAN_Prescaler = 16;
CAN_InitStructure.CAN_BS1 = 8;
CAN_InitStructure.CAN_BS2 = 7;
break;
case BAUD_250KBIT:
// LCD_display_Text(0,40,"250kBit");
CAN_InitStructure.CAN_Prescaler = 8;
CAN_InitStructure.CAN_BS1 = 8;
CAN_InitStructure.CAN_BS2 = 7;
break;
case BAUD_500KBIT:
// LCD_display_Text(0,40,"500kBit");
CAN_InitStructure.CAN_Prescaler = 4;
CAN_InitStructure.CAN_BS1 = 8;
CAN_InitStructure.CAN_BS2 = 7;
break;
case BAUD_800KBIT:
// LCD_display_Text(0,40,"800kBit");
CAN_InitStructure.CAN_Prescaler = 3;
CAN_InitStructure.CAN_BS1 = 7;
CAN_InitStructure.CAN_BS2 = 5;
break;
case BAUD_1MBIT:
// LCD_display_Text(0,40," 1MBit");
CAN_InitStructure.CAN_Prescaler = 2;
CAN_InitStructure.CAN_BS1 = 8;
CAN_InitStructure.CAN_BS2 = 7;
break;
default:
// LCD_display_Text(0,40,"defBaud");
// 500kBit
CAN_InitStructure.CAN_Prescaler = 4;
CAN_InitStructure.CAN_BS1 = 8;
CAN_InitStructure.CAN_BS2 = 7;
break;
}
CAN_Init(CAN1, &CAN_InitStructure);
/* CAN filter init */
CAN_FilterInitStructure.CAN_FilterNumber = 0;
CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;
CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;
CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0000;
CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment = 0;
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
// CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);
return 0;
}