⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trprtstp.c

📁 TMS320LF2812DSP CAN总线方案。
💻 C
字号:
/*********************************************************************
* Filename: TRPRTSTP.c                                                
*                                                                    
* Description: This program illustrates the programmable transmit-priority
* and time stamping feature of the CAN module. 
* 
* When a priority is assigned, transmission will be according to the
* assigned transmit priority, not the numerical value of the mailbox ID.
* All mailboxes are configured for transmit operation and all TRS.n bits
* are set at the same time. Transmit priority is assigned randomly. 
* The received data may be monitored on the CANalyzer to check if data was
* transmitted according to the assigned priority. The MOTS registers may 
* also be checked on the transmitting node.
*
* Last update: 12/24/2002
*********************************************************************/

#include "DSP28_Device.h"

long      i;

void InitECan(void);

main() 
{

/* Initialize the CAN module */

	InitECan();
 
 /* Write to the MSGID field of TRANSMIT mailboxes MBOX0 - 31 */
    
    ECanaMboxes.MBOX0.MSGID.all = 0x9555AA00; 
    ECanaMboxes.MBOX1.MSGID.all = 0x9555AA01; 
    ECanaMboxes.MBOX2.MSGID.all = 0x9555AA02; 
    ECanaMboxes.MBOX3.MSGID.all = 0x9555AA03; 
    ECanaMboxes.MBOX4.MSGID.all = 0x9555AA04; 
    ECanaMboxes.MBOX5.MSGID.all = 0x9555AA05; 
    ECanaMboxes.MBOX6.MSGID.all = 0x9555AA06; 
    ECanaMboxes.MBOX7.MSGID.all = 0x9555AA07; 
    ECanaMboxes.MBOX8.MSGID.all = 0x9555AA08; 
    ECanaMboxes.MBOX9.MSGID.all = 0x9555AA09; 
    ECanaMboxes.MBOX10.MSGID.all = 0x9555AA10; 
    ECanaMboxes.MBOX11.MSGID.all = 0x9555AA11; 
    ECanaMboxes.MBOX12.MSGID.all = 0x9555AA12; 
    ECanaMboxes.MBOX13.MSGID.all = 0x9555AA13; 
    ECanaMboxes.MBOX14.MSGID.all = 0x9555AA14; 
    ECanaMboxes.MBOX15.MSGID.all = 0x9555AA15; 
    
    ECanaMboxes.MBOX16.MSGID.all = 0x9555AA16; 
    ECanaMboxes.MBOX17.MSGID.all = 0x9555AA17; 
    ECanaMboxes.MBOX18.MSGID.all = 0x9555AA18; 
    ECanaMboxes.MBOX19.MSGID.all = 0x9555AA19; 
    ECanaMboxes.MBOX20.MSGID.all = 0x9555AA20; 
    ECanaMboxes.MBOX21.MSGID.all = 0x9555AA21; 
    ECanaMboxes.MBOX22.MSGID.all = 0x9555AA22; 
    ECanaMboxes.MBOX23.MSGID.all = 0x9555AA23; 
    ECanaMboxes.MBOX24.MSGID.all = 0x9555AA24; 
    ECanaMboxes.MBOX25.MSGID.all = 0x9555AA25; 
    ECanaMboxes.MBOX26.MSGID.all = 0x9555AA26; 
    ECanaMboxes.MBOX27.MSGID.all = 0x9555AA27; 
    ECanaMboxes.MBOX28.MSGID.all = 0x9555AA28; 
    ECanaMboxes.MBOX29.MSGID.all = 0x9555AA29; 
    ECanaMboxes.MBOX30.MSGID.all = 0x9555AA30; 
    ECanaMboxes.MBOX31.MSGID.all = 0x9555AA31; 
 
 /* Configure Mailboxes 0-31 as Tx */

	ECanaRegs.CANMD.all = 0x00000000; 
	
/* Enable all Mailboxes */
	
	ECanaRegs.CANME.all = 0xFFFFFFFF;    

/* Write to Master Control field - DLC */
 
    ECanaMboxes.MBOX0.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX1.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX2.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX3.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX4.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX5.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX6.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX7.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX8.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX9.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX10.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX11.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX12.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX13.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX14.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX15.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX16.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX17.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX18.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX19.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX20.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX21.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX22.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX23.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX24.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX25.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX26.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX27.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX28.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX29.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX30.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX31.MCF.bit.DLC = 8;        
    
/* Set transmit priority level - Random priorities are assigned 
	Uncomment following block to check out the TPL mechanism */
    
    ECanaMboxes.MBOX20.MCF.bit.TPL = 31;
    ECanaMboxes.MBOX4.MCF.bit.TPL = 30;
    ECanaMboxes.MBOX9.MCF.bit.TPL = 29;
    ECanaMboxes.MBOX26.MCF.bit.TPL = 28;
    ECanaMboxes.MBOX15.MCF.bit.TPL = 27;
    ECanaMboxes.MBOX0.MCF.bit.TPL = 26;
    ECanaMboxes.MBOX7.MCF.bit.TPL = 25;
    ECanaMboxes.MBOX23.MCF.bit.TPL = 24;
    ECanaMboxes.MBOX11.MCF.bit.TPL = 23;
    ECanaMboxes.MBOX17.MCF.bit.TPL = 22;
    ECanaMboxes.MBOX27.MCF.bit.TPL = 21;
    ECanaMboxes.MBOX13.MCF.bit.TPL = 20;
    ECanaMboxes.MBOX18.MCF.bit.TPL = 19;
    ECanaMboxes.MBOX2.MCF.bit.TPL = 18;
    ECanaMboxes.MBOX24.MCF.bit.TPL = 17;
    ECanaMboxes.MBOX29.MCF.bit.TPL = 16;
    ECanaMboxes.MBOX12.MCF.bit.TPL = 15;
    ECanaMboxes.MBOX16.MCF.bit.TPL = 14;
    ECanaMboxes.MBOX31.MCF.bit.TPL = 13;
    ECanaMboxes.MBOX22.MCF.bit.TPL = 12;
    ECanaMboxes.MBOX19.MCF.bit.TPL = 11;
    ECanaMboxes.MBOX21.MCF.bit.TPL = 10;
    ECanaMboxes.MBOX1.MCF.bit.TPL = 9;
    ECanaMboxes.MBOX30.MCF.bit.TPL = 8;
    ECanaMboxes.MBOX28.MCF.bit.TPL = 7;
    ECanaMboxes.MBOX25.MCF.bit.TPL = 6;
    ECanaMboxes.MBOX10.MCF.bit.TPL = 5;
    ECanaMboxes.MBOX3.MCF.bit.TPL = 4;
    ECanaMboxes.MBOX8.MCF.bit.TPL = 3;
    ECanaMboxes.MBOX5.MCF.bit.TPL = 2;
    ECanaMboxes.MBOX14.MCF.bit.TPL = 1;
    ECanaMboxes.MBOX6.MCF.bit.TPL = 0;
    
/* If no tr.priority is assigned, tr.sequence will be starting
   with the mailbox with the highest priority, which will be the
   mailbox with the numerically highest ID. 31,30,29.........2,1,0 
   Uncomment the following block to try this out   */
   
    /*ECanaMboxes.MBOX20.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX4.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX9.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX26.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX15.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX0.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX7.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX23.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX11.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX17.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX27.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX13.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX18.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX2.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX24.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX29.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX12.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX16.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX31.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX22.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX19.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX21.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX1.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX30.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX28.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX25.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX10.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX3.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX8.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX5.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX14.MCF.bit.TPL = 0;
    ECanaMboxes.MBOX6.MCF.bit.TPL = 0; */
    
/* Write to the mailbox RAM field of MBOX0 - 31 */
    
     ECanaMboxes.MBOX0.MDRL.all = 0x00000000;
	 ECanaMboxes.MBOX0.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX1.MDRL.all = 0x00000001;
	 ECanaMboxes.MBOX1.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX2.MDRL.all = 0x00000002;
	 ECanaMboxes.MBOX2.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX3.MDRL.all = 0x00000003;
	 ECanaMboxes.MBOX3.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX4.MDRL.all = 0x00000004;
	 ECanaMboxes.MBOX4.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX5.MDRL.all = 0x00000005;
	 ECanaMboxes.MBOX5.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX6.MDRL.all = 0x00000006;
	 ECanaMboxes.MBOX6.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX7.MDRL.all = 0x00000007;
	 ECanaMboxes.MBOX7.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX8.MDRL.all = 0x00000008;
	 ECanaMboxes.MBOX8.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX9.MDRL.all = 0x00000009;
	 ECanaMboxes.MBOX9.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX10.MDRL.all = 0x00000010;
	 ECanaMboxes.MBOX10.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX11.MDRL.all = 0x00000011;
	 ECanaMboxes.MBOX11.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX12.MDRL.all = 0x00000012;
	 ECanaMboxes.MBOX12.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX13.MDRL.all = 0x00000013;
	 ECanaMboxes.MBOX13.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX14.MDRL.all = 0x00000014;
	 ECanaMboxes.MBOX14.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX15.MDRL.all = 0x00000015;
	 ECanaMboxes.MBOX15.MDRH.all = 0x00000000;	 
	 
	 ECanaMboxes.MBOX16.MDRL.all = 0x00000016;
	 ECanaMboxes.MBOX16.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX17.MDRL.all = 0x00000017;
	 ECanaMboxes.MBOX17.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX18.MDRL.all = 0x00000018;
	 ECanaMboxes.MBOX18.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX19.MDRL.all = 0x00000019;
	 ECanaMboxes.MBOX19.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX20.MDRL.all = 0x00000020;
	 ECanaMboxes.MBOX20.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX21.MDRL.all = 0x00000021;
	 ECanaMboxes.MBOX21.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX22.MDRL.all = 0x00000022;
	 ECanaMboxes.MBOX22.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX23.MDRL.all = 0x00000023;
	 ECanaMboxes.MBOX23.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX24.MDRL.all = 0x00000024;
	 ECanaMboxes.MBOX24.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX25.MDRL.all = 0x00000025;
	 ECanaMboxes.MBOX25.MDRH.all = 0x00000000;	 
	 
	 ECanaMboxes.MBOX26.MDRL.all = 0x00000026;
	 ECanaMboxes.MBOX26.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX27.MDRL.all = 0x00000027;
	 ECanaMboxes.MBOX27.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX28.MDRL.all = 0x00000028;
	 ECanaMboxes.MBOX28.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX29.MDRL.all = 0x00000029;
	 ECanaMboxes.MBOX29.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX30.MDRL.all = 0x00000030;
	 ECanaMboxes.MBOX30.MDRH.all = 0x00000000;
	 
	 ECanaMboxes.MBOX31.MDRL.all = 0x00000031;
	 ECanaMboxes.MBOX31.MDRH.all = 0x00000000;
		 
	 ECanaRegs.CANMIM.all = 0xFFFFFFFF;
          
/* Configure bit timing parameters */

	ECanaRegs.CANMC.bit.CCR = 1 ;            	// Set CCR = 1
    
    while(ECanaRegs.CANES.bit.CCE != 1 ) {}   	// Wait for CCE bit to be set..
    
    ECanaRegs.CANBTC.bit.BRP = 9;
    ECanaRegs.CANBTC.bit.TSEG2 = 5;
    ECanaRegs.CANBTC.bit.TSEG1 = 7; 
    
    ECanaRegs.CANMC.bit.CCR = 0 ;              	// Set CCR = 0
    while(ECanaRegs.CANES.bit.CCE == !0 ) {}   	// Wait for CCE bit to be cleared..
    
      
/* Begin transmitting */

     ECanaRegs.CANTRS.all = 0xFFFFFFFF;            // Set TRS for all transmit mailboxes
     while(ECanaRegs.CANTA.all != 0xFFFFFFFF ) {}  // Wait for all TAn bits to be set..
     ECanaRegs.CANTA.all = 0xFFFFFFFF;			   // Clear all TAn       

    asm("     ESTOP0");							   // Stop here after transmission

}

/* 

Note 1: If all 32-bits are written to in a register, the register
may be written to without using a shadow register, as illustrated
in this code example.


CANalyzer configuration file: 1M80SPRX.cfg
... */ 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -