完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include "DSP2833x_Device.h"
#include "DSP2833x_Examples.h" interrupt void ECanT_ISR(void); interrupt void ECanR_ISR(void); Uint32 Counts = 0; Uint32 Counts1 = 0; int j =0; int ii; int jj; Uint32 MSGL = 0; Uint32 MSGH = 0; struct ECAN_REGS ECanbShadow; void main(void) { InitSysCtrl(); //系统初始化 InitXintf16Gpio(); //初始化配置总线 InitECanbGpio(); //初始化ECanb模块 DINT; //总中断关闭 InitPieCtrl(); //PIE模块初始化 InitPieVectTable(); //初始化中断向量表 IER=0x0000; IFR=0x0000; EALLOW; PieVectTable.ECAN0INTB = &ECanT_ISR; PieVectTable.ECAN1INTB = &ECanR_ISR; PieCtrlRegs.PIECTRL.bit.ENPIE=1; //使能PIE模块 PieCtrlRegs.PIEIER9.bit.INTx7=1; PieCtrlRegs.PIEIER9.bit.INTx8=1; //使能INT9.7和INT9.8,即使能ECAN0INTB和ECAN1INTB EDIS; IER|=M_INT9; //启用CAN模块对应的CPU中断线路 EINT; //使能全局中断 ERTM; //使能全局实时中断 EALLOW; // GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 2; GpioCtrlRegs.GPAQSEL2.bit.GPIO16 = 3; GpioCtrlRegs.GPAPUD.bit.GPIO16 = 0; GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 2; GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3; GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0; ECanbShadow.CANtiOC.all=ECanbRegs.CANTIOC.all; ECanbShadow.CANTIOC.bit.TXFUNC=1; //CANTX引脚用于CAN传输功能 ECanbRegs.CANTIOC.all=ECanbShadow.CANTIOC.all; ECanbShadow.CANRIOC.all=ECanbRegs.CANRIOC.all; ECanbShadow.CANRIOC.bit.RXFUNC=1; //CANRX引脚用于CAN接受功能 ECanbRegs.CANRIOC.all=ECanbShadow.CANRIOC.all; EDIS; // EALLOW; ECanbShadow.CANMC.all=ECanbRegs.CANMC.all; ECanbShadow.CANMC.bit.CCR=1; ECanbRegs.CANMC.all=ECanbShadow.CANMC.all; EDIS; do { ECanbShadow.CANES.all = ECanbRegs.CANES.all; } while(ECanbShadow.CANES.bit.CCE != 1 );//等待CPU禁止对配置寄存器写操作,当CCE=1时,执行以下程序 //CPU统一对CANBTC进行更改; EALLOW; ECanbShadow.CANBTC.all=ECanbRegs.CANBTC.all; ECanbShadow.CANBTC.bit.BRPREG=9; //BRP=BRPREG+1,相当于提供一个15MHz的CAN模块时钟 //因为 SYSCLKOUT=150MHz 150/10=15 ECanbShadow.CANBTC.bit.TSEG1REG=10; ECanbShadow.CANBTC.bit.TSEG2REG=2; ECanbShadow.CANBTC.bit.SAM = 1; //采样三次取多数 ECanbRegs.CANBTC.all=ECanbShadow.CANBTC.all; //Bit Tine=15 , 采样点SP=80% , 波特率Bit rat=500k EDIS; EALLOW; ECanbShadow.CANMC.all=ECanbRegs.CANMC.all; ECanbShadow.CANMC.bit.CCR=0; //CPU进入正常运行,不再有权配置位时序寄存器 ECanbShadow.CANMC.bit.SCB=1; //选择eCAN模式,而不是SCC模式 ECanbShadow.CANMC.bit.SUSP = 1; //挂起模式下继续运行 ECanbShadow.CANMC.bit.PDR=0; ECanbShadow.CANMC.bit.DBO=0; ECanbShadow.CANMC.bit.WUBA=0; ECanbShadow.CANMC.bit.CDR=0; ECanbShadow.CANMC.bit.ABO=1; //识别到总线自动恢复 ECanbShadow.CANMC.bit.STM=0; //CAN模块处于正常模式 ECanbShadow.CANMC.bit.SRES=0; ECanbShadow.CANMC.bit.MBNR=0; ECanbRegs.CANMC.all=ECanbShadow.CANMC.all; EDIS; //对主控制寄存器(CANMC)及进行编程 do { ECanbShadow.CANES.all = ECanbRegs.CANES.all; } while(ECanbShadow.CANES.bit.CCE != 0 ); //等待CCE位清零 ECanbMboxes.MBOX0.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX1.MSGCTRL.all = 0x00000000; /* ECanbMboxes.MBOX2.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX3.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX4.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX5.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX6.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX7.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX8.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX9.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX10.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX11.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX12.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX13.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX14.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX15.MSGCTRL.all = 0x00000000; */ ECanbMboxes.MBOX16.MSGCTRL.all = 0x00000000; /* ECanbMboxes.MBOX17.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX18.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX19.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX20.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX21.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX22.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX23.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX24.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX25.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX26.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX27.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX28.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX29.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX30.MSGCTRL.all = 0x00000000; ECanbMboxes.MBOX31.MSGCTRL.all = 0x00000000; //将MSGCTRL寄存器所有位清零进行初始化 */ ECanbRegs.CANME.all=0; //清除邮箱使能寄存器CANME中相应的位,屏蔽邮箱 ECanbMboxes.MBOX0.MSGID.bit.IDE = 0; //要被接受的消息为标准标识符 ECanbMboxes.MBOX0.MSGID.bit.STDMSGID=0x0226; //邮箱ID ECanbMboxes.MBOX0.MSGID.bit.AAM = 0; ECanbMboxes.MBOX0.MSGID.bit.AME = 0; ECanbMboxes.MBOX1.MSGID.bit.IDE = 0; //要被接受的消息为标准标识符 ECanbMboxes.MBOX1.MSGID.bit.STDMSGID = 0x0314; //邮箱ID ECanbMboxes.MBOX1.MSGID.bit.AAM = 0; ECanbMboxes.MBOX1.MSGID.bit.AME = 0; ECanbMboxes.MBOX16.MSGID.bit.IDE = 0; //要被接收的消息为标准标识符 ECanbMboxes.MBOX16.MSGID.bit.STDMSGID=0x0314; //邮箱ID ECanbMboxes.MBOX16.MSGID.bit.AAM = 0; ECanbMboxes.MBOX16.MSGID.bit.AME = 0; ECanbRegs.CANMD.all=0xFFFF0000; // 设置邮箱方向,将邮箱0-15配置为Tx,将16-31配置为Rx /*ECanbShadow.CANOPC.all = ECanbRegs.CANOPC.all; ECanbShadow.CANOPC.bit.OPC16 = 0; //设置为没有写覆盖保护 ECanbRegs.CANOPC.all = ECanbShadow.CANOPC.all; */ ECanbShadow.CANME.all=ECanbRegs.CANME.all; ECanbShadow.CANME.bit.ME0 = 1; ECanbShadow.CANME.bit.ME1 = 1; ECanbShadow.CANME.bit.ME16 = 1; //使能邮箱 ECanbRegs.CANME.all = ECanbShadow.CANME.all; ECanbMboxes.MBOX0.MSGCTRL.bit.DLC=8; //设置接受或发送的数据长度,此时设置为8字节 ECanbMboxes.MBOX1.MSGCTRL.bit.DLC=8; /*ECanbMboxes.MBOX2.MSGCTRL.bit.DLC=8; ECanbMboxes.MBOX3.MSGCTRL.bit.DLC=8; ECanbMboxes.MBOX4.MSGCTRL.bit.DLC=8; ECanbMboxes.MBOX5.MSGCTRL.bit.DLC=8; ECanbMboxes.MBOX6.MSGCTRL.bit.DLC=8; ECanbMboxes.MBOX7.MSGCTRL.bit.DLC=8; ECanbMboxes.MBOX8.MSGCTRL.bit.DLC=8; ECanbMboxes.MBOX9.MSGCTRL.bit.DLC=8; ECanbMboxes.MBOX10.MSGCTRL.bit.DLC=8; ECanbMboxes.MBOX11.MSGCTRL.bit.DLC=8; ECanbMboxes.MBOX12.MSGCTRL.bit.DLC=8; ECanbMboxes.MBOX13.MSGCTRL.bit.DLC=8; ECanbMboxes.MBOX14.MSGCTRL.bit.DLC=8; ECanbMboxes.MBOX15.MSGCTRL.bit.DLC=8; */ ECanbMboxes.MBOX16.MSGCTRL.bit.DLC=8; //设置接受或发送的数据长度,此时设置为8字节 ECanbMboxes.MBOX0.MSGCTRL.bit.RTR=0; //设置为没有远程帧传输请求 ECanbMboxes.MBOX1.MSGCTRL.bit.RTR=0; /*ECanbMboxes.MBOX2.MSGCTRL.bit.RTR=0; ECanbMboxes.MBOX3.MSGCTRL.bit.RTR=0; ECanbMboxes.MBOX4.MSGCTRL.bit.RTR=0; ECanbMboxes.MBOX5.MSGCTRL.bit.RTR=0; ECanbMboxes.MBOX6.MSGCTRL.bit.RTR=0; ECanbMboxes.MBOX7.MSGCTRL.bit.RTR=0; ECanbMboxes.MBOX8.MSGCTRL.bit.RTR=0; ECanbMboxes.MBOX9.MSGCTRL.bit.RTR=0; ECanbMboxes.MBOX10.MSGCTRL.bit.RTR=0; ECanbMboxes.MBOX11.MSGCTRL.bit.RTR=0; ECanbMboxes.MBOX12.MSGCTRL.bit.RTR=0; ECanbMboxes.MBOX13.MSGCTRL.bit.RTR=0; ECanbMboxes.MBOX14.MSGCTRL.bit.RTR=0; ECanbMboxes.MBOX15.MSGCTRL.bit.RTR=0; */ ECanbMboxes.MBOX16.MSGCTRL.bit.RTR=0; //设置为没有远程帧传输请求 ECanbMboxes.MBOX0.MDL.all=0x00005698; //向指定邮箱写入数据 ECanbMboxes.MBOX0.MDH.all=0x0FFF0000; ECanbMboxes.MBOX1.MDL.all=0x00001226; ECanbMboxes.MBOX1.MDH.all=0x19950000; /*ECanbMboxes.MBOX2.MDL.all=0x19951226; ECanbMboxes.MBOX2.MDH.all=0x19960214; ECanbMboxes.MBOX3.MDL.all=0x19951226; ECanbMboxes.MBOX3.MDH.all=0x19960214; ECanbMboxes.MBOX4.MDL.all=0x19951226; ECanbMboxes.MBOX4.MDH.all=0x19960214; ECanbMboxes.MBOX5.MDL.all=0x19951226; ECanbMboxes.MBOX5.MDH.all=0x19960214; ECanbMboxes.MBOX6.MDL.all=0x19951226; ECanbMboxes.MBOX6.MDH.all=0x19960214; ECanbMboxes.MBOX7.MDL.all=0x19951226; ECanbMboxes.MBOX7.MDH.all=0x19960214; ECanbMboxes.MBOX8.MDL.all=0x19951226; ECanbMboxes.MBOX8.MDH.all=0x19960214; ECanbMboxes.MBOX9.MDL.all=0x19951226; ECanbMboxes.MBOX9.MDH.all=0x19960214; ECanbMboxes.MBOX10.MDL.all=0x19951226; ECanbMboxes.MBOX10.MDH.all=0x19960214; ECanbMboxes.MBOX11.MDL.all=0x19951226; ECanbMboxes.MBOX11.MDH.all=0x19960214; ECanbMboxes.MBOX12.MDL.all=0x19951226; ECanbMboxes.MBOX12.MDH.all=0x19960214; ECanbMboxes.MBOX13.MDL.all=0x19951226; ECanbMboxes.MBOX13.MDH.all=0x19960214; ECanbMboxes.MBOX14.MDL.all=0x19951226; ECanbMboxes.MBOX14.MDH.all=0x19960214; ECanbMboxes.MBOX15.MDL.all=0x19951226; ECanbMboxes.MBOX15.MDH.all=0x19960214; //向指定邮箱写入数据 */ ECanbRegs.CANMIL.all=0xFFFF0000; //发送邮箱中断产生在中断线路0上 //接受邮箱中断产生在中断线路1上 ECanbRegs.CANMIM.all=0xFFFFFFFF; //启用所有的邮箱中断 //ECanbRegs.CANTA.all= 0x00000000; //置位发送成功位 //ECanbRegs.CANRMP.all= 0x00000000; //置位接收消息待决 ECanbRegs.CANGIF0.all=0xFFFFFFFF; //全局中断标志寄存器置位 ECanbRegs.CANGIF1.all=0xFFFFFFFF; EALLOW; ECanbShadow.CANGIM.all = ECanbRegs.CANGIM.all; ECanbShadow.CANGIM.bit.AAIM = 1; ECanbShadow.CANGIM.bit.WUIM = 1; ECanbShadow.CANGIM.bit.WDIM = 1; ECanbShadow.CANGIM.bit.BOIM = 1; ECanbShadow.CANGIM.bit.EPIM = 1; ECanbShadow.CANGIM.bit.WLIM = 1; ECanbShadow.CANGIM.bit.I0EN = 1; //使能中断线路0 ECanbShadow.CANGIM.bit.I1EN = 1; //使能中断线路1 //ECanbShadow.CANGIM.bit.GIL = 1; ECanbRegs.CANGIM.all = ECanbShadow.CANGIM.all; EDIS; //配置全局中断屏蔽寄存器 ECanbRegs.CANRMP.all = 0xFFFFFFFF; //复位接收挂起标志寄存器 ECanbRegs.CANTA.all = 0xFFFFFFFF; //复位发送挂起标志寄存器 /////开始传输数据///// for(;;) { //if(ECanbRegs.CANTA.all == 0x00000000) EALLOW; ECanbShadow.CANTRS.all=ECanbRegs.CANTRS.all; //ECanbShadow.CANTRS.all=0x00000000; ECanbShadow.CANTRS.bit.TRS0=1; //发送请求置位寄存器置位为1。启动发送 ECanbRegs.CANTRS.all=ECanbShadow.CANTRS.all; EDIS; for(ii=0; ii<100; ii++)//延时 { for(jj=0; jj<1000; jj++){} } ECanbRegs.CANTRS.all = 0x00000002;//发送请求box1 for(ii=0; ii<100; ii++)//延时 { for(jj=0; jj<1000; jj++){} } j++; if(j > 2000) { j = 0; } } } interrupt void ECanT_ISR(void) { if(ECanbRegs.CANTA.all == 0x00000003 ) { ECanbRegs.CANTA.all=0x00000003; //写1清零,为了下一个发送确认 } Counts++; PieCtrlRegs.PIEACK.bit.ACK9=1; } interrupt void ECanR_ISR(void) { if(ECanbRegs.CANRMP.all == 0x00010000) { ECanbRegs.CANRMP.all = 0x00010000; while(ECanbRegs.CANRMP.all == 0x00000000); MSGL = ECanbMboxes.MBOX16.MDL.all; MSGH = ECanbMboxes.MBOX16.MDH.all; Counts1++; } PieCtrlRegs.PIEACK.bit.ACK9=1; }
|
|
相关推荐
3个回答
|
|
在通讯过程中,我把断点打在发送中断程序的Counts上,第一次运行的时候程序会停在那里,再次运行的时候程序进一直在循环发送,不进入中断了,Counts的数值也只显示为1
而且上位机给它发消息它也收不到 |
|
|
|
|
|
|
|
如果我在程序第一次运行的时候不打断点,那Counts的值就一直显示为0
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 18:32 , Processed in 0.760487 second(s), Total 81, Slave 63 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号