在调试28335的ACN通讯中,在自响应模式下调试远程帧,想实现MBOX16向MBOX0发送远程帧并接收MBOX0发出的数据。在给接收邮箱的TRS16置位后,TA 端始终无法得到接收响应,程序卡死了。设置的是MBOX0和MBOX16分别为远程帧的传输和接收邮箱,MSGID分别设置为MBOX0:0xB5550093,MBOX16:0xD5550093。给MBOX0和MBOX16的RTR位也都进行了置位。想请教一下各位大佬,问题出在哪里了。相关的代码节选如下,请各位大佬帮忙指点一下!感谢!void main(void)
{
Uint16 j;
struct ECAN_REGS ECanaShadow;
InitSysCtrl();
InitECanGpio();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
MessageReceivedCount = 0;
ErrorCount = 0;
PassCount = 0;
// Configure the eCAN RX and TX pins for eCAN transmissions
EALLOW;
ECanaShadow.CANTIOC.all = ECanaRegs.CANTIOC.all;
ECanaShadow.CANTIOC.bit.TXFUNC = 1;
ECanaRegs.CANTIOC.all = ECanaShadow.CANTIOC.all;
ECanaShadow.CANRIOC.all = ECanaRegs.CANRIOC.all;
ECanaShadow.CANRIOC.bit.RXFUNC = 1;
ECanaRegs.CANRIOC.all = ECanaShadow.CANRIOC.all;
EDIS;
// Disable all Mailboxes
// Since this write is to the entire register (instead of a bit
// field) a shadow register is not required.
ECanaRegs.CANME.all = 0;
// Mailboxs can be written to 16-bits or 32-bits at a time
// Write to the MSGID field of TRANSMIT mailboxes MBOX0 - 15
ECanaMboxes.MBOX0.MSGID.all = 0xB5550093;
ECanaMboxes.MBOX1.MSGID.all = 0x95550094;
ECanaMboxes.MBOX2.MSGID.all = 0x95550122;
//中间代码略
ECanaMboxes.MBOX15.MSGID.all = 0x9555AAAF;
// Write to the MSGID field of RECEIVE mailboxes MBOX16 - 31
ECanaMboxes.MBOX16.MSGID.all = 0xD5550093;
ECanaMboxes.MBOX17.MSGID.all = 0x95550094;
ECanaMboxes.MBOX18.MSGID.all = 0x95550122;
ECanaMboxes.MBOX19.MSGID.all = 0xD5550125;
//中间代码略
ECanaMboxes.MBOX31.MSGID.all = 0x9555AAAF;
// Configure Mailboxes 0-15 as Tx, 16-31 as Rx
// Since this write is to the entire register (instead of a bit
// field) a shadow register is not required.
ECanaRegs.CANMD.all = 0xFFFF0000;
// Enable all Mailboxes */
// Since this write is to the entire register (instead of a bit
// field) a shadow register is not required.
ECanaRegs.CANME.all = 0xFFFFFFFF;
// Specify that 8 bits will be sent/received
ECanaMboxes.MBOX0.MSGCTRL.bit.DLC = 8;
ECanaMboxes.MBOX1.MSGCTRL.bit.DLC = 8;
//中间代码略
ECanaMboxes.MBOX15.MSGCTRL.bit.DLC = 8;
// No remote frame is requested
// Since RTR bit is undefined upon reset,
// it must be initialized to the proper value
ECanaMboxes.MBOX0.MSGCTRL.bit.RTR = 1;
ECanaMboxes.MBOX1.MSGCTRL.bit.RTR = 0;
//中间代码略
ECanaMboxes.MBOX15.MSGCTRL.bit.RTR = 0;
ECanaMboxes.MBOX16.MSGCTRL.bit.RTR = 1;//发起远程帧
// Write to the mailbox RAM field of MBOX0 - 15
ECanaMboxes.MBOX0.MDL.all = 0x00;
ECanaMboxes.MBOX0.MDH.all = 0x00;
ECanaMboxes.MBOX1.MDL.all = 0x1111;
ECanaMboxes.MBOX1.MDH.all = 0x1111;
//中间代码略
ECanaMboxes.MBOX15.MDL.all = 0x9555AAAF;
ECanaMboxes.MBOX15.MDH.all = 0x89ABCDEF;
EALLOW;
ECanaRegs.CANMIM.all = 0xFFFFFFFF;
// Request permission to change the configuration registers
ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
ECanaShadow.CANMC.bit.CCR = 1;
ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
EDIS;
do
{
ECanaShadow.CANES.all = ECanaRegs.CANES.all;
} while(ECanaShadow.CANES.bit.CCE != 1 );
// Configure the eCAN timing
EALLOW;
ECanaShadow.CANBTC.all = ECanaRegs.CANBTC.all;
ECanaShadow.CANBTC.bit.BRPREG = 9; // (BRPREG + 1) = 10 feeds a 15 MHz CAN clock
ECanaShadow.CANBTC.bit.TSEG2REG = 5 ; // to the CAN module. (150 / 10 = 15)
ECanaShadow.CANBTC.bit.TSEG1REG = 7; // Bit time = 15
ECanaRegs.CANBTC.all = ECanaShadow.CANBTC.all;
ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
ECanaShadow.CANMC.bit.CCR = 0;
ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
EDIS;
// Wait until the CPU no longer has permission to change the
// configuration registers
do
{
ECanaShadow.CANES.all = ECanaRegs.CANES.all;
} while(ECanaShadow.CANES.bit.CCE != 0 );
// Configure the eCAN for self test mode
// Enable the enhanced features of the eCAN.
EALLOW;
ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
ECanaShadow.CANMC.bit.STM = 1; // Configure CAN for ACK mode
ECanaShadow.CANMC.bit.SCB = 1; // eCAN mode (reqd to access 32 mailboxes)
ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
EDIS;
// Begin transmitting
for(;;)
{
ECanaRegs.CANTRS.all = 0x0000FFFF; // Set TRS for all transmit mailboxes
//ECanaRegs.CANTRS.bit.TRS3=0;
while(ECanaRegs.CANTA.all != 0x0000FFFF ) {} // Wait for all TAn bits to be set..
ECanaRegs.CANTA.all = 0x0000FFFF; // Clear all TAn
MessageReceivedCount++;
ECanaRegs.CANTRS.all = 0x0000FFFF; // Set TRS for all transmit mailboxes
ECanaRegs.CANTRS.bit.TRS16=1;
while(ECanaRegs.CANTA.bit.TA16 != 1 ) {} // 卡在了这一步过不去
ECanaRegs.CANTA.bit.TA16 = 1; // Clear all TAn
ErrorCount++;
}
}
|