硬件:DSP28335的eCAN-B与vp230连接,USBcan采用的是周立功的usbcan-i与上位机连接。
出现的问题是上位机上的监控软件没法接受到DSP的eCAN模块发过来的数据。
下面是代码:
void main(void)
{
struct ECAN_REGS ECanbShadow;
InitSysCtrl();//开启系统时钟和外设时钟
InitECanGpio();//这里用到的是ecan-b的GPIO12和GPIO13
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
MessageReceivedCount = 0;
EALLOW;
ECanbShadow.CANTIOC.all = ECanbRegs.CANTIOC.all;
ECanbShadow.CANTIOC.bit.TXFUNC = 1;
ECanbRegs.CANTIOC.all = ECanbShadow.CANTIOC.all;
ECanbShadow.CANRIOC.all = ECanbRegs.CANRIOC.all;
ECanbShadow.CANRIOC.bit.RXFUNC = 1;
ECanbRegs.CANRIOC.all = ECanbShadow.CANRIOC.all;
EDIS;
ECanbRegs.CANME.all = 0;
ECanbMboxes.MBOX0.MSGID.all = 0x01C40000;//发送 标准帧
ECanbMboxes.MBOX1.MSGID.all = 0x18040000;//接受
ECanbRegs.CANMD.all=0x00000002;//1->RX 0->tx
ECanbRegs.CANME.all = 0x00000003;
ECanbMboxes.MBOX0.MSGCTRL.bit.DLC = 8;
ECanbMboxes.MBOX1.MSGCTRL.bit.DLC = 8;
ECanbMboxes.MBOX0.MSGCTRL.bit.RTR = 0;
ECanbMboxes.MBOX1.MSGCTRL.bit.RTR = 0;
ECanbMboxes.MBOX0.MDL.all = 0x9555AAA0;
ECanbMboxes.MBOX0.MDH.all = 0x89ABCDEF;
EALLOW;
ECanbRegs.CANMIM.all = 0xFFFFFFFF;
ECanbRegs.CANMIL.all = 0;
ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.CCR = 1;
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;
EDIS;
// Wait for CCE bit to be set..
do
{
ECanbShadow.CANES.all = ECanbRegs.CANES.all;
} while(ECanbShadow.CANES.bit.CCE != 1 );
// Configure the eCAN timing
EALLOW;
ECanbShadow.CANBTC.all = ECanbRegs.CANBTC.all;
ECanbShadow.CANBTC.bit.BRPREG = 9; // (BRPREG + 1) = 1
ECanbShadow.CANBTC.bit.TSEG2REG = 1 ; // to the CAN module
ECanbShadow.CANBTC.bit.TSEG1REG = 6; // Bit time = 2us,则为500kbps
ECanbShadow.CANBTC.bit.SAM = 1;
ECanbRegs.CANBTC.all = ECanbShadow.CANBTC.all;
ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.CCR = 0;
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;
EDIS;
do
{
ECanbShadow.CANES.all = ECanbRegs.CANES.all;
} while(ECanbShadow.CANES.bit.CCE != 0 );
// Configure the eCAN for self test mode
// Enable the enhanced features of the eCAN.
EALLOW;
ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.ABO = 1;
ECanbShadow.CANMC.bit.STM = 0; // Configure CAN for self-test mode
ECanbShadow.CANMC.bit.SCB = 1; // eCAN mode (reqd to access 32 mailboxes)
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;
EDIS;
// Begin transmitting
for(;;)
{
ECanbRegs.CANTRS.all = 0x00000001; // Set TRS for all transmit mailboxes,MX0开始发送
while(ECanbRegs.CANTA.all != 0x00000001 ) {} // Wait for all TAn bits to be set..发送完成后对应的位被置1
ECanbRegs.CANTA.all = 0x0000FFFF; // Clear all TAn
MessageReceivedCount++;
//Read from Receive mailboxes and begin checking for data */
}
}
我的想法是邮箱0设为发送邮箱,邮箱1设为接受。系统频率为100Mhz,can波特率为500k.程序运行后一直等待在while(ECanbRegs.CANTA.all != 0x00000001 ) {}这一步,也就是说没有发送完成等待置位 |