CAN_Init(CAN0);//初始化CAN0
CAN_Open(CAN0, 125000, CAN_NORMAL_MODE);//配置模式
M_RUN();//电机启动
M_Zero();//电机归零
Test_NormalMode_Rx();//配置接收
首先,电机可以保证正常,驱动器是可以收到数据并且响应的。证明了发送数据 没问题。
我配置的接收以及接收过程是以下过程,发现发出去的数据,可以起到触发中断,但是收不到驱动器收到的数据;驱动器的ID设置位了1;并不能收到这个响应;
CAN发送使用MSG[0]
void M_RUN(void)
{
/* Send a 11-bits message */
tMsg.FrameType = CAN_DATA_FRAME;
tMsg.IdType = CAN_STD_ID;
tMsg.Id = 0x01;
tMsg.DLC = 8;
tMsg.Data[0] = 0X00;
tMsg.Data[1] = 0X1A;
tMsg.Data[2] = 0X00;
tMsg.Data[3] = 0X00;
tMsg.Data[4] = 0X01;
tMsg.Data[5] = 0X00;
tMsg.Data[6] = 0X00;
tMsg.Data[7] = 0X01;
if(CAN_Transmit(CAN0, MSG(0), tMsg) == FALSE) // Configure Msg RAM and send the Msg in the RAM
{
printf("Set Tx Msg Object failedn");
}
}
//接收使用MSG[1]
void Test_NormalMode_Rx(void)
{
if(CAN_SetRxMsg(CAN0, MSG(1), CAN_STD_ID, 0X7FFF) == FALSE)
{
printf("Set Rx Msg Object failedn");
return;
}
/*Choose one mode to test*/
/* INT Mode */
CAN_EnableInt(CAN0, CAN_CON_IE_Msk);
NVIC_SetPriority(CAN0_IRQn, (1 << __NVIC_PRIO_BITS) - 2);
NVIC_EnableIRQ(CAN0_IRQn);
}
void CAN_ShowMsg(STR_CANMSG_T *Msg)
{
uint8_t i;
printf("Read ID=%8X, Type=%s, DLC=%d,Data=", Msg->Id, Msg->IdType ? "EXT" : "STD", Msg->DLC);
for(i = 0; i < Msg->DLC; i++)
printf("%02X,", Msg->Data[i]);
printf("nn");
}
void CAN_MsgInterrupt(CAN_T *tCAN, uint32_t u32IIDR)
{
if(u32IIDR==1)
{
printf("Msg-0 INT and Callbackn");
CAN_Receive(tCAN, 0, rrMsg);
CAN_ShowMsg( rrMsg);
}
if(u32IIDR==2)
{
printf("Msg-1 INT and Callbackn");
CAN_Receive(tCAN, 1, rrMsg);
CAN_ShowMsg( rrMsg);
}
if(u32IIDR==5+1)
{
printf("Msg-5 INT and Callback n");
CAN_Receive(tCAN, 5, rrMsg);
CAN_ShowMsg( rrMsg);
}
if(u32IIDR==31+1)
{
printf("Msg-31 INT and Callback n");
CAN_Receive(tCAN, 31, rrMsg);
CAN_ShowMsg( rrMsg);
}
}
/**
* @brief CAN0_IRQ Handler.
* @param None.
* @return None.
*/
void CAN0_IRQHandler(void)
{
uint32_t u8IIDRstatus;
u8IIDRstatus = CAN0->IIDR;
if(u8IIDRstatus == 0x00008000) /* Check Status Interrupt Flag (Error status Int and Status change Int) */
{
/**************************/
/* Status Change interrupt*/
/**************************/
if(CAN0->STATUS CAN_STATUS_RXOK_Msk)
{
CAN0->STATUS = ~CAN_STATUS_RXOK_Msk; /* Clear Rx Ok status*/
printf("RX OK INTn") ;
}
if(CAN0->STATUS CAN_STATUS_TXOK_Msk)
{
CAN0->STATUS = ~CAN_STATUS_TXOK_Msk; /* Clear Tx Ok status*/
printf("TX OK INTn") ;
}
/**************************/
/* Error Status interrupt */
/**************************/
if(CAN0->STATUS CAN_STATUS_EWARN_Msk)
{
printf("EWARN INTn") ;
/* Do Init to release busoff pin */
CAN0->CON = (CAN_CON_INIT_Msk | CAN_CON_CCE_Msk);
CAN0->CON = (~(CAN_CON_INIT_Msk | CAN_CON_CCE_Msk));
while(CAN0->CON CAN_CON_INIT_Msk);
}
if(CAN0->STATUS CAN_STATUS_BOFF_Msk)
{
printf("BOFF INTn") ;
}
}
else if (u8IIDRstatus != 0)
{
printf("=> Interrupt Pointer = %d-%dn", CAN0->IIDR - 1, u8IIDRstatus);
CAN_MsgInterrupt(CAN0, u8IIDRstatus);
CAN_CLR_INT_PENDING_BIT(CAN0, ((CAN0->IIDR) - 1)); /* Clear Interrupt Pending */
}
else if(CAN0->WU_STATUS == 1)
{
printf("Wake upn");
CAN0->WU_STATUS = 0; /* Write '0' to clear */
}
}
2024-1-16 15:06:40
1、从代码上看要接收ID = 0x7FFF的消息 ,请问消息ID是否正确。
2、确认一下对方是在Test_NormalMode_Rx调用之前还是之后发送的数据。 一般建议先配置接收再配置发送
3、另外可以示波器看一下对方是否有发数据出来
1、从代码上看要接收ID = 0x7FFF的消息 ,请问消息ID是否正确。
2、确认一下对方是在Test_NormalMode_Rx调用之前还是之后发送的数据。 一般建议先配置接收再配置发送
3、另外可以示波器看一下对方是否有发数据出来
举报