从机通过CAN卡与电脑连接起来,电脑给从机发送数据,硬件上可以检测到ARM的CAN-RX有脉冲,但是RxMassage里一直没有值,也没有进入接收中断,请大家看看我的程序有什么问题?[mw_shl_code=applescript,true]static void CAN_NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/*ÖD¶ÏéèÖÃ*/
NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn; //CAN1 RX0ÖD¶Ï
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //ÇàÕ¼óÅÏ輶0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //×óóÅÏ輶Îa0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
{
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
/************************CANí¨DÅ2ÎêyéèÖÃ**********************************/
/*CAN¼Ä′æÆ÷3õê¼»ˉ*/
CAN_DeInit(CAN1);
CAN_StructInit(&CAN_InitStructure);
/*CANμ¥Ôa3õê¼»ˉ*/
CAN_InitStructure.CAN_TTCM=DISABLE; //MCR-TTCM ê±¼ä′¥·¢í¨DÅÄ£ê½ê1Äü
CAN_InitStructure.CAN_ABOM=DISABLE; //MCR-ABOM ×Ô¶ˉàëÏß1üàí
CAN_InitStructure.CAN_AWUM=DISABLE; //MCR-AWUM ×Ô¶ˉ»½DÑÄ£ê½
CAN_InitStructure.CAN_NART=DISABLE; //MCR-NART ½ûÖ1±¨ÎÄ×Ô¶ˉÖØ′« DISABLE-×Ô¶ˉÖØ′«
CAN_InitStructure.CAN_RFLM=DISABLE; //MCR-RFLM ½óêÕFIFO Ëø¶¨Ä£ê½ DISABLE-òç3öê±D±¨ÎÄ»á¸2¸ÇÔ-óD±¨ÎÄ
CAN_InitStructure.CAN_TXFP=ENABLE; //MCR-TXFP ·¢ËíFIFOóÅÏ輶 ENABLE óé·¢ËíÇëÇó′ÎDò¾ö¶¨£¬DISABLE-óÅÏ輶衾öóú±¨Îıêê¾·û
CAN_InitStructure.CAN_Mode = CAN_Mode_Normal; //Õy3£·¢ËíÄ£ê½
CAN_InitStructure.CAN_SJW=CAN_SJW_1tq; //BTR-SJW ÖØDÂí¬2½ìøÔ¾¿í¶è 2¸öê±¼äμ¥Ôa
CAN_InitStructure.CAN_BS1=CAN_BS1_6tq; //BTR-TS1 ê±¼ä¶Î1 Õ¼óÃáË6¸öê±¼äμ¥Ôa
CAN_InitStructure.CAN_BS2=CAN_BS2_1tq; //BTR-TS1 ê±¼ä¶Î2 Õ¼óÃáË3¸öê±¼äμ¥Ôa
CAN_InitStructure.CAN_Prescaler =36; //BTR-BRP 2¨ìØÂê·ÖÆμÆ÷ ¶¨òåáËê±¼äμ¥ÔaμÄê±¼ä3¤¶è,Ïμí3ê±Öó72MHz 36/(1+6+1)/36=125Kbps,CAN2¨ìØÂê36MHz/[36*(1+6+1)]=125kHz
// CAN_InitStructure.CAN_BS1=CAN_BS1_2tq; //BTR-TS1 ê±¼ä¶Î1 Õ¼óÃáË6¸öê±¼äμ¥Ôa
// CAN_InitStructure.CAN_BS2=CAN_BS2_1tq; //BTR-TS1 ê±¼ä¶Î2 Õ¼óÃáË3¸öê±¼äμ¥Ôa
// CAN_InitStructure.CAN_Prescaler =9; //BTR-BRP 2¨ìØÂê·ÖÆμÆ÷ ¶¨òåáËê±¼äμ¥ÔaμÄê±¼ä3¤¶è 36/(1+2+1)/9=1Mbps
CAN_Init(CAN1, &CAN_InitStructure);
/*CAN1yÂËÆ÷3õê¼»ˉ*/
CAN_FilterInitStructure.CAN_FilterNumber=0; //1yÂËÆ÷×é0
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask; //1¤×÷Ôú±ê궷ûÆá±ÎλÄ£ê½
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_16bit; //1yÂËÆ÷λ¿íÎa2¸ö16λ¡£
/* ê1Äü±¨Îıêê¾·û1yÂËÆ÷°′ÕÕ±êê¾·ûμÄÄúèY½øDD±è¶Ô1yÂË£¬à©Õ1ID2»êÇèçÏÂμľíÅ×Æúμô£¬êÇμÄ»°£¬»á′æèëFIFO0¡£ */
CAN_FilterInitStructure.CAN_FilterIdHigh= 0x0000; //òa1yÂËμÄID¸ßλ
CAN_FilterInitStructure.CAN_FilterIdLow= 0x0101; //òa1yÂËμÄIDμíλ
CAN_FilterInitStructure.CAN_FilterMaskIdHigh= 0xFFFF; //1yÂËÆ÷¸ß16λÿλ±ØDëÆ¥Åä
CAN_FilterInitStructure.CAN_FilterMaskIdLow = (u16)(((u16)0xFFE0<<3)|0x07);//½öê1óÃμí5λ1|ÄüÂ룬¸ß3λ±ØDëÎa0 //(u16)(((u16)0xFF00<<3)|0x07); //1yÂËÆ÷μí16λÿλ±ØDëÆ¥Åä
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_Filter_FIFO0 ; //1yÂËÆ÷±»1Øáaμ½FIFO0
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE; //ê1Äü1yÂËÆ÷
CAN_FilterInit(&CAN_FilterInitStructure);
/*CANí¨DÅÖD¶Ïê1Äü*/
CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);
//CAN_ITConfig(CAN1, CAN_IT_EWG | CAN_IT_EPV | CAN_IT_BOF | CAN_IT_ERR | CAN_IT_LEC, ENABLE); //¿aÆô′íÎóÖD¶Ï
}[/mw_shl_code]
{
u8 FunCode;
//u16 i;
u16 CCR1;
CAN_Receive(CAN1, CAN_FIFO0, &RxMessage);
if((RxMessage.StdId!=0) && (RxMessage.IDE==CAN_ID_EXT)
&& (RxMessage.DLC!=0) && ((RxMessage.Data[1]<<8|RxMessage.Data[0])!=0))
{
flag = 0; //½óêÕ3é1|
}
else
{
flag = 0xff; //½óêÕ꧰ü
}
FunCode = RxMessage.StdId & 0x1f; //D-òéÖDê1óÃ8λ1|ÄüÂ룬¶øêμ¼êÖDÎaáËóëéy¼¶Ãüáîò»ÖÂê1óÃáË5λ1|ÄüÂë
CCR1=RxMessage.Data[3] << 24 | RxMessage.Data[2]<< 16|RxMessage.Data[1]<< 8| RxMessage.Data[0];
}[/mw_shl_code]
没有检查下硬件
一周热门 更多>