首先,感谢“admin”给的解答。
我参照例程编写的程序能够接收固定的标识符数据包。我实测发现,将CAN_IFn_ARB2寄存器的Bit15设置成“0”
则接收不到数据包。
程序如下:
int32_t CAN_SetRxMsgObj(UINT32 uCAN, uint8_t u8MsgObj, uint8_t u8idType, uint32_t u32id, uint8_t u8singleOrFifoLast)
{
UINT32 uOffset = uCAN * CAN_OFFSET;
UINT32 reg;
if((inpw(REG_CAN0_IF2_CREQ+uOffset) & CAN_IF_CREQ_BUSY_Msk) != 0)
{
return FALSE;
}
/* Command Setting */
outpw((REG_CAN0_IF2_CMASK+uOffset), (CAN_IF_CMASK_WRRD_Msk | CAN_IF_CMASK_MASK_Msk | CAN_IF_CMASK_ARB_Msk |
CAN_IF_CMASK_CONTROL_Msk | CAN_IF_CMASK_DATAA_Msk | CAN_IF_CMASK_DATAB_Msk));
if (u8idType == CAN_STD_ID) { /* According STD/EXT ID format,Configure Mask and Arbitration register */
outpw((REG_CAN0_IF2_ARB1+uOffset), 0x0);
outpw((REG_CAN0_IF2_ARB2+uOffset), (CAN_IF_ARB2_MSGVAL_Msk | (u32id & 0x7FF)<< 2));
} else {
outpw((REG_CAN0_IF2_ARB1+uOffset), (u32id & 0xFFFF));
outpw((REG_CAN0_IF2_ARB2+uOffset), (CAN_IF_ARB2_MSGVAL_Msk | CAN_IF_ARB2_XTD_Msk | (u32id & 0x1FFF0000)>>16));
}
/*********************添加 使Bit15 =0*************************/
reg = inpw(REG_CAN0_IF2_ARB2+uOffset);
reg = reg & (UINT32)(~(0x01<<15));
outpw((REG_CAN0_IF2_ARB2+uOffset),reg);
/************************************************/
outpw((REG_CAN0_IF2_MCON+uOffset), (inpw(REG_CAN0_IF2_MCON+uOffset) | CAN_IF_MCON_UMASK_Msk | CAN_IF_MCON_RXIE_Msk));
if(u8singleOrFifoLast)
{
outpw((REG_CAN0_IF2_MCON+uOffset), (inpw(REG_CAN0_IF2_MCON+uOffset) | CAN_IF_MCON_EOB_Msk));
}
else
{
outpw((REG_CAN0_IF2_MCON+uOffset), (inpw(REG_CAN0_IF2_MCON+uOffset) & ~CAN_IF_MCON_EOB_Msk));
}
outpw((REG_CAN0_IF2_DAT_A1+uOffset), 0x0);
outpw((REG_CAN0_IF2_DAT_A2+uOffset), 0x0);
outpw((REG_CAN0_IF2_DAT_B1+uOffset), 0x0);
outpw((REG_CAN0_IF2_DAT_B2+uOffset), 0x0);
outpw((REG_CAN0_IF2_CREQ+uOffset), (1 + u8MsgObj));
return TRUE;
}
/****************************************************************
;函数名称: void InitControlCan0(void)
;函数功能:初始化CAN0
;输入参数:无
;返回参数:无
;版本:1.0
;编制日期:
;编写:
****************************************************************/
void InitControlCan0(void)
{
outpw(REG_SYS_GPH_MFPL, (inpw(REG_SYS_GPH_MFPL) & 0xffff00ff) | 0xCC00 ); // GPH_2,GPH_3 // RX, TX
outpw(REG_CLK_PCLKEN1, (inpw(REG_CLK_PCLKEN1) | (1 << 8) )); //开CAN0时钟
CAN_Open(CAN0, 125000, CAN_NORMAL_MODE);
CAN_SetRxMsg(CAN0, MSG(0),CAN_EXT_ID,(CAN_ID_RX_1));//0);//(unsigned int)(0x05<<26))
//CAN_SetRxMsg(CAN0, MSG(1),CAN_EXT_ID,(unsigned int)((0x05<<26)|0x16));
//CAN_SetRxMsg(CAN0, MSG(2),CAN_EXT_ID,(unsigned int)(0x05));
CAN_EnableInt(CAN0, CAN_CON_IE_Msk);
sysInstallISR((IRQ_LEVEL_6 | HIGH_LEVEL_SENSITIVE), CAN0_IRQn, (PVOID)CAN0_IRQHandler);
sysSetLocalInterrupt(ENABLE_IRQ); /* enable CPSR I bit */
sysEnableInterrupt(CAN0_IRQn);
sysprintf("Wait Msg\n");
}
|