本人使用英飞凌的xc886
单片机,此单片机内含muliCAN模块。请教下:can发送报文能连续发多个报文吗(非FIFO模式,就是一帧一帧的发)?因为我写了个例子:发送方:用报文1、2、3发送数据;接收方:用报文1、2、3接收,结果只有报文1收到数据,另两个没收到(报文ID,优先级按列表顺序,)。
发送方:
部分主程序
CAN_vLoadData(1,MO1);
CAN_vLoadData(2,MO2);
CAN_vLoadData(3,MO3);
CAN_vTransmit(1);
部分中断程序
switch(sucCanNum)
{
case 0: CAN_vTransmit(2);
sucCanNum++;
Tr_flag++;
break;
case 1:
CAN_vTransmit(3);
sucCanNum++;
Tr_flag++;
break;
case 2:
sucCanNum++;
Tr_flag++;
break;
}
接收方
部分中断程序
switch(sucCanNum)
{
case 0:
CAN_vWriteCANAddress(CAN_MODATAL1);
CAN_vReadEN();
MO1L.ubDB[3]=CAN_DATA0;
MO1L.ubDB[2]=CAN_DATA1;
MO1L.ubDB[1]=CAN_DATA2;
MO1L.ubDB[0]=CAN_DATA3;
CAN_ADCON = ADR_INC;
CAN_vReadEN();
MO1H.ubDB[3]=CAN_DATA0;
MO1H.ubDB[2]=CAN_DATA1;
MO1H.ubDB[1]=CAN_DATA2;
MO1H.ubDB[0]=CAN_DATA3;
sucCanNum++;
CAN_vWriteCANAddress(CAN_MOCTR1);
CAN_vWriteAMData(0x000000A0); // 清零MSGVAL
break;
case 1:
CAN_vWriteCANAddress(CAN_MODATAL2);
CAN_vReadEN();
MO2L.ubDB[3]=CAN_DATA0;
MO2L.ubDB[2]=CAN_DATA1;
MO2L.ubDB[1]=CAN_DATA2;
MO2L.ubDB[0]=CAN_DATA3;
CAN_ADCON = ADR_INC;
CAN_vReadEN();
MO2H.ubDB[3]=CAN_DATA0;
MO2H.ubDB[2]=CAN_DATA1;
MO2H.ubDB[1]=CAN_DATA2;
MO2H.ubDB[0]=CAN_DATA3;
sucCanNum++;
CAN_vWriteCANAddress(CAN_MOCTR2);
CAN_vWriteAMData(0x00000020); // 清零MSGVAL
break;
case 2:
CAN_vWriteCANAddress(CAN_MODATAL3);
CAN_vReadEN();
MO3L.ubDB[3]=CAN_DATA0;
MO3L.ubDB[2]=CAN_DATA1;
MO3L.ubDB[1]=CAN_DATA2;
MO3L.ubDB[0]=CAN_DATA3;
CAN_ADCON = ADR_INC;
CAN_vReadEN();
MO3H.ubDB[3]=CAN_DATA0;
MO3H.ubDB[2]=CAN_DATA1;
MO3H.ubDB[1]=CAN_DATA2;
MO3H.ubDB[0]=CAN_DATA3;
sucCanNum=0;
break;
}
一周热门 更多>