各位达人,我在做CAN1回环测试时,能正常收发数据;但改成正常模式时不能收发;CAN2回环模式和正常都不能正常收发。
/* CAN1 register init */
CAN_DeInit(CAN1);
CAN_StructInit(&CAN_InitStructure);
/* CAN1 cell init */
/* CAN1 cell init */
CAN_InitStructure.CAN_TTCM=DISABLE; // ê±¼ä′¥·¢
CAN_InitStructure.CAN_ABOM=DISABLE; // ×Ô¶ˉàëÏß1üàí
CAN_InitStructure.CAN_AWUM=DISABLE; // ×Ô¶ˉ»½DÑ
CAN_InitStructure.CAN_NART=ENABLE; // ENABLE;′íÎó2»×Ô¶ˉÖØ′«£¬DISABLE:ÖØ′«
CAN_InitStructure.CAN_RFLM=DISABLE;
CAN_InitStructure.CAN_TXFP=DISABLE;
CAN_InitStructure.CAN_Mode=CAN_Mode_LoopBack; //Õy3£′«êäÄ£ê½ CAN_Mode_Normal;»Ø»·Ä£ê½×Ô·¢×ÔêÕ CAN_Mode_LoopBack
CAN_InitStructure.CAN_SJW=CAN_SJW_2tq; //1-4
CAN_InitStructure.CAN_BS1=CAN_BS1_12tq; //1-16
CAN_InitStructure.CAN_BS2=CAN_BS2_6tq; //1-8
CAN_InitStructure.CAN_Prescaler=6; // 2¨ìØÂê= 36/(9*(1+12+7))=200k
CAN_Init(CAN1,&CAN_InitStructure);
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=CAN_FIFO0;
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
CAN_ITConfig(CAN1,CAN_IT_FMP0, ENABLE);
CAN_ClearFlag(CAN1,CAN_FLAG_RQCP0);
CAN2和上面的设置差不多,只是
CAN_FilterInitStructure.CAN_FilterNumber=14;
主流程中每隔500毫秒发送一次
TxMessage.StdId = 0x01; TxMessage.RTR = CAN_RTR_DATA;
TxMessage.IDE = CAN_ID_STD; // CAN_ID_EXT CAN_ID_STD
TxMessage.DLC = 1;
TxMessage.Data[0] = 0x08;
CAN_Transmit(CAN1,&TxMessage);
中断函数 分别是在void CAN1_RX0_IRQHandler(),void CAN2_RX0_IRQHandler()中读数据,判断RxMessage.StdId是否==0x01 ;
求大虾门指点···························
此帖出自
小平头技术问答
你可以借鉴一下!
一周热门 更多>