大家好,我最近在调试28335的CAN模块,中断发送和中断接收都没有问题了,现在遇到的问题的想实现CAN的发送超时和接收超时的处理。发送超时处理已经实现,但是接收超时的时候,会出现时间还没有达到MOTO设置 的值就产生了接收超时中断,不知道是不是代码没有设置好?
我使用CANA的邮箱0作为发送邮箱,邮箱1作为接收邮箱。下面这个代码是我发送的函数,大家帮我看一下,有哪里设置不正确不?
void CanaSendHandle(Uint32 Value)
{
Uint32 BeginTscValue,SendTimeOut,ReceiveTimeOut;
SendTimeOut = 2000; //发送超时时间为:1*2000=2000us=2ms
ReceiveTimeOut = 100000; //接收超时时间为:1*100000us=100000us=100ms
//1.设置邮箱的值
ECanaMboxes.MBOX0.MDL.all = Value;
//=======================================================
//设置发送邮箱超时寄存器
//1.读取CANTSC值,然后设置MOTO的值
EALLOW;
BeginTscValue = ECanaRegs.CANTSC;
EDIS;
ECanaMOTORegs.MOTO0 = BeginTscValue + SendTimeOut;
ECanaMOTORegs.MOTO1 = BeginTscValue + ReceiveTimeOut;
//2.设置CANTOC的值
ECanaShadow.CANTOC.all = ECanaRegs.CANTOC.all;
ECanaShadow.CANTOC.bit.TOC0 = 1;
ECanaShadow.CANTOC.bit.TOC1 = 1;
ECanaRegs.CANTOC.all = ECanaShadow.CANTOC.all;
//3.设置TRS位
ECanaShadow.CANTRS.all = ECanaRegs.CANTRS.all;
ECanaShadow.CANTRS.bit.TRS0 = 1;
ECanaRegs.CANTRS.all = ECanaShadow.CANTRS.all;
//3.等待邮箱发送成功
do
{
ECanaShadow.CANTA.all = ECanaRegs.CANTA.all;
}while(ECanaShadow.CANTA.bit.TA0 != 1);
//4.清除TA位
ECanaShadow.CANTA.bit.TA0 = 1;
ECanaRegs.CANTA.all = ECanaShadow.CANTA.all;
//5.等待清除TA位
do{
ECanaShadow.CANTA.all = ECanaRegs.CANTA.all;
}while(ECanaShadow.CANTA.bit.TA0 != 0);
} |