#include "DSP280x_Device.h"
#include "DSP280x_Examples.h"
interrupt void ECAN0INTA(void) ;
long candatahighword=0;
long candatalowword =0;
#define LED3 GpioDataRegs.GPADAT.bit.GPIO23 //工作指示灯,LED3
void main(void)
{
InitSysCtrl();
InitGpio();
DINT;
IER = 0x0000;
IFR = 0x0000;
InitPieCtrl();
InitPieVectTable();
EALLOW;
PieVectTable.ECAN0INTA = &ECAN0INTA;
EDIS;
InitECan();
PieCtrlRegs.PIEIER9.bit.INTx5=1;
IER|=M_INT9;
EINT;
ERTM;
LED3=1;
int i ;
while(1)
{
i++;
if (i>100)
i--;
}
}
interrupt void ECAN0INTA(void) // eCAN-A
{
LED3=0;
while(ECanaRegs.CANRMP.bit.RMP16!=1);
ECanaRegs.CANRMP.all=0x00010000;
candatahighword=ECanaMboxes.MBOX16.MDH.all;
candatalowword =ECanaMboxes.MBOX16.MDL.all;
PieCtrlRegs.PIEACK.bit.ACK9=1;
EINT;
}
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=1;
GpioCtrlRegs.GPAMUX2.bit.GPIO31=1;
//配置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;
ECanaRegs.CANMC.all=0;//主控寄存器各位清
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;
//清除所有的TA位
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;
do
{
ECanaShadow.CANES.all = ECanaRegs.CANES.all;
}
while(ECanaShadow.CANES.bit.CCE != 1);
EALLOW;
//(BRPREG+1)=100 ,CAN时钟为100MHz
ECanaShadow.CANBTC.bit.BRPREG = 99;
//CAN通信的波特率为100kbps
ECanaShadow.CANBTC.bit.TSEG2REG = 2;
ECanaShadow.CANBTC.bit.TSEG1REG = 5;
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;
ECanaRegs.CANMD.all = ECanaShadow.CANMD.all;
//全局接受屏蔽,标示符位必须一一匹配
ECanaRegs.CANGAM.all=0;
//设置接收邮箱的ID,扩展帧,IDE,
ECanaMboxes.MBOX16.MSGID.all = 0x80C80000;
//数据长度 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;
ECanaRegs.CANME.all=ECanaShadow.CANME.all;
EALLOW;
ECanaRegs.CANMIM.all = 0xFFFFFFFF;
ECanaRegs.CANMIL.all = 0;
ECanaRegs.CANGIF0.all= 0xFFFFFFFF;
ECanaRegs.CANGIM.bit.I0EN = 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;
}
/*************************************************************no more **********************************************************************/
前边是主接受函数,后边是配置。现在数据能从上位机发送到dsp的输入引脚上了,但是dsp就是不进入接受中断。请高手帮忙一下。跪谢!
|