在使用stm32的CAN的时候修改波特率除了CAN_SJW、 CAN_BS1、CAN_BS2的修改之外还需要在哪里修改吗?
我在下面这个函数将这三个参数进行修改可是却没有效果。。。。
CAN1_Mode_Init(CAN_SJW_1tq,CAN_BS2_6tq,CAN_BS1_7tq,6,CAN_Mode_LoopBack);
/*************************/
u8 CAN1_Mode_Init(u8 tsjw,u8 tbs2,u8 tbs1,u16 brp,u8 mode)
{
GPIO_InitTypeDef GPIO_InitStructure;
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
#if CAN1_RX0_INT_ENABLE
NVIC_InitTypeDef NVIC_InitStructure;
#endif
//ê1ÄüÏà1Øê±Öó
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);//ê1ÄüPORTAê±Öó
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);//ê1ÄüCAN1ê±Öó
//3õê¼»ˉGPIO
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11| GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//¸′óÃ1|Äü
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//íÆíìêä3ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//éÏà-
GPIO_Init(GPIOA, &GPIO_InitStructure);//3õê¼»ˉPA11,PA12
//òy½Å¸′óÃó3éäÅäÖÃ
GPIO_PinAFConfig(GPIOA,GPIO_PinSource11,GPIO_AF_CAN1); //GPIOA11¸′óÃÎaCAN1
GPIO_PinAFConfig(GPIOA,GPIO_PinSource12,GPIO_AF_CAN1); //GPIOA12¸′óÃÎaCAN1
//CANμ¥ÔaéèÖÃ
CAN_InitStructure.CAN_TTCM=DISABLE; //·Çê±¼ä′¥·¢í¨DÅÄ£ê½
CAN_InitStructure.CAN_ABOM=DISABLE; //èí¼t×Ô¶ˉàëÏß1üàí
CAN_InitStructure.CAN_AWUM=DISABLE;//ËˉÃßÄ£ê½í¨1yèí¼t»½DÑ(Çå3yCAN->MCRμÄSLEEPλ)
CAN_InitStructure.CAN_NART=ENABLE; //½ûÖ1±¨ÎÄ×Ô¶ˉ′«Ëí
CAN_InitStructure.CAN_RFLM=DISABLE; //±¨ÎÄ2»Ëø¶¨,DÂμĸ2¸Ç¾éμÄ
CAN_InitStructure.CAN_TXFP=DISABLE; //óÅÏ輶ó鱨Îıê궷û¾ö¶¨
CAN_InitStructure.CAN_Mode= mode; //Ä£ê½éèÖÃ
CAN_InitStructure.CAN_SJW=tsjw; //ÖØDÂí¬2½ìøÔ¾¿í¶è(Tsjw)Îatsjw+1¸öê±¼äμ¥λ CAN_SJW_1tq~CAN_SJW_4tq
CAN_InitStructure.CAN_BS1=tbs1; //Tbs1·¶Î§CAN_BS1_1tq ~CAN_BS1_16tq
CAN_InitStructure.CAN_BS2=tbs2;//Tbs2·¶Î§CAN_BS2_1tq ~ CAN_BS2_8tq
CAN_InitStructure.CAN_Prescaler=brp; //·ÖÆμÏμêy(Fdiv)Îabrp+1
CAN_Init(CAN1, &CAN_InitStructure); // 3õê¼»ˉCAN1
//ÅäÖÃ1yÂËÆ÷
CAN_FilterInitStructure.CAN_FilterNumber=0; //1yÂËÆ÷0
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask;
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit; //32λ
CAN_FilterInitStructure.CAN_FilterIdHigh=0x0000;////32λID
CAN_FilterInitStructure.CAN_FilterIdLow=0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0x0000;//32λMASK
CAN_FilterInitStructure.CAN_FilterMaskIdLow=0x0000;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_Filter_FIFO0;//1yÂËÆ÷01Øáaμ½FIFO0
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE; //¼¤»î1yÂËÆ÷0
CAN_FilterInit(&CAN_FilterInitStructure);//ÂË2¨Æ÷3õê¼»ˉ
#if CAN1_RX0_INT_ENABLE
CAN_ITConfig(CAN1,CAN_IT_FMP0,ENABLE);//FIFO0ÏûÏ¢1òoÅÖD¶ÏÔêDí.
NVIC_InitStructure.NVIC_IRQChannel = CAN1_RX0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; // Ö÷óÅÏ輶Îa1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; // ′ÎóÅÏ輶Îa0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
#endif
return 0;
}
此帖出自
小平头技术问答
一周热门 更多>