STM32的CAN总线初始化

void CAN_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
CAN_InitTypeDefCAN_InitStructure;
CAN_FilterInitTypeDefCAN_FilterInitStructure;
/* CAN register init */
// CAN_DeInit();
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN, ENABLE); //刚开始漏掉这句,一直无法进入初始化模式
RCC_APB2PeriphClockCmd( RCC_APB2Periph_AFIO, ENABLE ); //?′??CAN1μ??ùóD??′??÷
// RCC_APB1PeriphResetCmd(RCC_APB1Periph_CAN, ENABLE);
// CAN_StructInit(&CAN_InitStructure); //????′??÷è?2?éè??3é??è??μ
/*????CAN???úCAN pin: RX*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //IO???úμ?μú8??
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode =GPIO_Mode_IPU; // GPIO_Mode_IN_FLOATING; //???ú?£ê??aé?à-ê?è?·?ê?
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure CAN pin: TX */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //IO???úμ?μú9??
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //???ú?£ê??a?′ó?í?à-ê?3?·?ê?
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_PinRemapConfig(GPIO_Remap1_CAN , ENABLE); //???¨ò?CAN1μ?PB?ú
/* CAN cell init */
CAN_InitStructure.CAN_TTCM=DISABLE; //???1ê±??′¥·¢í¨D?·?ê?
CAN_InitStructure.CAN_ABOM=DISABLE; //???1CAN×ü??×??ˉ1?±?1üàí
CAN_InitStructure.CAN_AWUM=DISABLE; //???1×??ˉ??D??£ê?
CAN_InitStructure.CAN_NART=ENABLE; //???1·?×??ˉ??′??£ê?
CAN_InitStructure.CAN_RFLM=DISABLE; //???1?óê?FIFO???¨
CAN_InitStructure.CAN_TXFP=DISABLE; //ENABLE; //???1·¢?íFIFOó??è??
CAN_InitStructure.CAN_Mode=CAN_Mode_Normal; //CAN_Mode_LoopBack; //CAN_Mode_Normal; //éè??CAN1¤×÷·?ê??a?y3£ê?·¢?£ê?
/* CAN 2¨ì??ê */
CAN_InitStructure.CAN_SJW=CAN_SJW_1tq; //éè????D?í?2?ì?×aμ?ê±??á?×ó
CAN_InitStructure.CAN_BS1=CAN_BS1_9tq; //éè??×???1μ?ê±??á?×óêy
CAN_InitStructure.CAN_BS2=CAN_BS2_8tq; //éè??×???2μ?ê±??á?×óêy
CAN_InitStructure.CAN_Prescaler=20; //·??μ?μêy μí2¨ì??ê???àà?′?ê??ü?è?¨£?è?1??àà??ì?éò?μ÷D??a???μ
CAN_Init(&CAN_InitStructure); //ó?ò?é?2?êy3?ê??ˉCAN1???ú


/* CAN filter init */
CAN_FilterInitStructure.CAN_FilterNumber=0; //????CAN1y???÷0
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask; //3?ê??ˉ?a±êê?/?á±??£ê?
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit; //????1y???÷?a32??
CAN_FilterInitStructure.CAN_FilterIdHigh=0x0000; //1y???÷±êê?o???16??
CAN_FilterInitStructure.CAN_FilterIdLow=0x0000; //1y???÷±êê?o?μí16??
//????è?0£???1y??è?o?±êê?o?
CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0x0000; //?ù?Y?£ê?????1y???÷±êê?o??ò?á±?o?μ???16??
CAN_FilterInitStructure.CAN_FilterMaskIdLow=0x0000; //?ù?Y?£ê?????1y???÷±êê?o??ò?á±?o?μ?μí16??
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_FIFO0; //??FIFO 0·?????1y???÷0
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE; //ê1?ü1y???÷
CAN_FilterInit(&CAN_FilterInitStructure);

/* CAN FIFO0 ?óê??D??ê1?ü */
// CAN_ITConfig(CAN_IT_FMP0, ENABLE);
【STM32的CAN总线初始化】}
折腾了一天一直无法弄出来,是在以前程序上加个CAN功能,时钟使能在void RCC_Configuration(void)定义的,添加CAN忘了定义CAN时钟,弄一天都要开始怀疑人生了!!!!

    推荐阅读