void InitECana(void);
void InitECanGpio(void);
void InitECan(void)
{
InitECanGpio();
InitECana();
}
void InitECana(void) // Initialize eCAN-A module
{
struct ECAN_REGS ECanaShadow;
EALLOW; // EALLOW enables access to protected bits
GpioCtrlRegs.GPAMUX2.bit.GPIO30=2;
GpioCtrlRegs.GPAMUX2.bit.GPIO31=2;
//配置eCAN的RX和TX分别为eCAN的接收和发送引脚
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;
//不使能邮箱,在写MSGID之前要完成该操作
EALLOW;
//主控寄存器的配置
ECanaRegs.CANMC.all=0;//主控寄存器各位清〇
EDIS;
EALLOW;
ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
//工作在正常模式
ECanaShadow.CANMC.bit.STM = 0;
//工作在eCAN模式
ECanaShadow.CANMC.bit.SCB=1;
ECanaShadow.CANMC.bit.DBO = 0;
ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
EDIS;
ECanaMboxes.MBOX16.MSGCTRL.all = 0x00000000;
ECanaRegs.CANTA.all = 0xFFFFFFFF;
//清除所有的RMP位
ECanaRegs.CANRMP.all = 0xFFFFFFFF;
//配置时钟参数
ECanaRegs.CANGIF0.all= 0xFFFFFFFF;
ECanaRegs.CANGIF1.all= 0xFFFFFFFF;
EALLOW;
ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
ECanaShadow.CANMC.bit.CCR = 1;
ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
EDIS;
//CPU请求向CANBTC和CANGAM写配置信息,该位置1后必须等到CANED.CCE为1,才能
//对CANBTC进行操作。
do
{
ECanaShadow.CANES.all = ECanaRegs.CANES.all;
}
while(ECanaShadow.CANES.bit.CCE != 1);
EALLOW;
//(BRPREG+1)=100 ,CAN时钟为1MHz
ECanaShadow.CANBTC.bit.BRPREG = 99;
//CAN通信的波特率为100kbps
ECanaShadow.CANBTC.bit.TSEG2REG = 5;
ECanaShadow.CANBTC.bit.TSEG1REG = 12;
ECanaRegs.CANBTC.all=ECanaShadow.CANBTC.all;
//CPU请求正常操作
ECanaShadow.CANMC.all=ECanaRegs.CANMC.all;
ECanaShadow.CANMC.bit.CCR = 0;
ECanaRegs.CANMC.all=ECanaShadow.CANMC.all;
EDIS;
do
{
ECanaShadow.CANES.all = ECanaRegs.CANES.all;
}
while(ECanaShadow.CANES.bit.CCE != 0);
//设置邮箱16为接收邮箱
ECanaRegs.CANME.all = 0;
//ECanaShadow.CANMD.all = ECanaRegs.CANMD.all;
ECanaShadow.CANMD.bit.MD16 =1;
ECanaShadow.CANMD.all=1;
ECanaRegs.CANMD.all = ECanaShadow.CANMD.all;
//全局接受屏蔽,标示符位必须一一匹配
// ECanaRegs.CANGAM.all=0;
//设置接收邮箱的ID,扩展帧,IDE,
ECanaMboxes.MBOX16.MSGID.all = 0x00C80000;
//数据长度 8个BYTE
ECanaMboxes.MBOX16.MSGCTRL.bit.DLC = 8;
//有远方应答帧被请求
ECanaMboxes.MBOX16.MSGCTRL.bit.RTR = 0;
//邮箱16使能
ECanaShadow.CANME.all=ECanaRegs.CANME.all;
ECanaShadow.CANME.bit.ME16=1;
// ECanaShadow.CANME.all=1; //使能所有邮箱
ECanaRegs.CANME.all=ECanaShadow.CANME.all;
EALLOW;
ECanaRegs.CANMIM.all = 0xFFFFFFFF;
ECanaRegs.CANMIL.all = 0;
ECanaRegs.CANGIF1.all= 0xFFFFFFFF;
ECanaRegs.CANGIM.bit.I1EN = 1;
EDIS;
}
void InitECanGpio(void)
{
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO30 = 0; // Enable pull-up for GPIO30 (CANRXA)
GpioCtrlRegs.GPAPUD.bit.GPIO31 = 0; // Enable pull-up for GPIO31 (CANTXA)
GpioCtrlRegs.GPAQSEL2.bit.GPIO30 = 3;
// Asynch qual for GPIO30 (CANRXA)
GpioCtrlRegs.GPAMUX2.bit.GPIO30 = 1; // Configure GPIO30 for CANTXA operation
GpioCtrlRegs.GPAMUX2.bit.GPIO31 = 1;
EDIS;
}
#include "DSP280x_Device.h"
#include "DSP280x_Examples.h"
#pragma CODE_SECTION(ECAN0INTA, "ramfuncs");
interrupt void ECAN0INTA(void) ;
long candatahighword=0;
long candatalowword =0;
int LEDcount;
#define LED3ON() GpioDataRegs.GPASET.bit.GPIO23=1 //工作指示灯,LED3
#define LED3OFF() GpioDataRegs.GPASET.bit.GPIO23=1 //工作指示灯,LED3
void main(void)
{
InitSysCtrl();
InitGpio();
// MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);
// InitFlash();
/*关中断*/
DINT;
IER = 0x0000;
IFR = 0x0000;
/*初始化PIE中断*/
InitPieCtrl();
/*初始化PIE中断矢量表*/
InitPieVectTable();
/*初始化SCIA寄存器*/
EALLOW;
PieVectTable.ECAN1INTA = &ECAN0INTA;
EDIS;
InitECan();
PieCtrlRegs.PIEIER9.bit.INTx5=1;
IER|=M_INT9;
EINT;
ERTM;
LED3ON();
// EnableDog();
int i ;
while(1)
{
i++;
if (i>100)
i--;
//ServiceDog();
//interrupt void ECAN0INTA(void) // eCAN-A
if(ECanaRegs.CANRMP.all!=0)
{
ECanaRegs.CANRMP.bit.RMP16=0;
LEDcount++;
if(LEDcount<1024)
{
LED3OFF();
}
else if(LEDcount<2048)
{
LED3ON();
}
if(LEDcount>2048)
{
LEDcount=0;
}
//while(ECanaRegs.CANRMP.bit.RMP16!=1);
candatahighword=ECanaMboxes.MBOX16.MDH.all;
candatalowword =ECanaMboxes.MBOX16.MDL.all;
ECanaRegs.CANRMP.bit.RMP16=1;
PieCtrlRegs.PIEACK.bit.ACK9=1;
EINT;
}
}
}
interrupt void ECAN0INTA(void) // eCAN-A
{
ECanaRegs.CANRMP.bit.RMP16=1;
LEDcount++;
if(LEDcount<1024)
{
LED3OFF();
}
else if(LEDcount<2048)
{
LED3ON();
}
if(LEDcount>2048)
{
LEDcount=0;
}
//while(ECanaRegs.CANRMP.bit.RMP16!=1);
candatahighword=ECanaMboxes.MBOX16.MDH.all;
candatalowword =ECanaMboxes.MBOX16.MDL.all;
ECanaRegs.CANRMP.bit.RMP16=0x01;
PieCtrlRegs.PIEACK.bit.ACK9=1;
EINT;
}
/*************************************************************no more **********************************************************************/
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
如果我是你, EALLOW;
PieVectTable.ECAN1INTA = &ECAN0INTA;
EDIS;
InitECan();
PieCtrlRegs.PIEIER9.bit.INTx5=1;
IER|=M_INT9;这里的 InitECan();我会放在前面去,不会放在这里,虽然这样没什么卵用。。目前我还没找出为什么。。你看看ecan是不是PIEIER9.bit.INTx5吧
一周热门 更多>