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

📄 txloop.c

📁 2812的CAN通讯源代码,需要的朋友请下载试用
💻 C
字号:
/*********************************************************************
* Filename: TXLOOP.c                                                 *
*                                                                    *
* Description: TXLOOP - Transmit loop using any mailbox 	
* 
* Mailbox 5 is shown as an example...
* This program TRANSMITS data to another CAN module using MAILBOX5
* This program could either loop forever or transmit "n" # of times,	
* where "n" is the TXCOUNT value.
*          
* Last update: 12/23/2002
*********************************************************************/

#include "DSP28_Device.h"
#define TXCOUNT  10000  // Transmission will take place (TXCOUNT) times..

long      i;
long 	  loopcount = 0;

void InitECan(void);

main()
{

/* Create a shadow register structure for the CAN control registers. This is
 needed, since, only 32-bit access is allowed to these registers. 16-bit access
 to these registers could potentially corrupt the register contents. This is
 especially true while writing to a bit (or group of bits) among bits 16 - 31 */

struct ECAN_REGS ECanaShadow;

/* Initialize the CAN module */

	InitECan();

/* Write to the MSGID field  */
    
    ECanaMboxes.MBOX5.MSGID.all = 0x9FFFFFFF; // Extended Identifier
       
/* Configure Mailbox under test as a Transmit mailbox */

	ECanaShadow.CANMD.all = ECanaRegs.CANMD.all;	
	ECanaShadow.CANMD.bit.MD5 = 0;
	ECanaRegs.CANMD.all = ECanaShadow.CANMD.all; 
	
/* Enable Mailbox under test */
	
	ECanaShadow.CANME.all = ECanaRegs.CANME.all;	
	ECanaShadow.CANME.bit.ME5 = 1;
	ECanaRegs.CANME.all = ECanaShadow.CANME.all; 
	
/* Write to DLC field in Master Control reg */

	ECanaMboxes.MBOX5.MCF.bit.DLC = 8;
	
/* Write to the mailbox RAM field */
    
     ECanaMboxes.MBOX5.MDRL.all = 0x01234567;
	 ECanaMboxes.MBOX5.MDRH.all = 0x89ABCDEF;	 
	 
/* Begin transmitting */

    // while(1) 							// Uncomment this line for infinite transmissions
    for(i=0; i < TXCOUNT; i++)				// Uncomment this line for finite transmissions			  	
    {
     
     ECanaShadow.CANTRS.all = 0; 	
     ECanaShadow.CANTRS.bit.TRS5 = 1;     // Set TRS for mailbox under test       
     ECanaRegs.CANTRS.all = ECanaShadow.CANTRS.all; 
         
     while(ECanaRegs.CANTA.bit.TA5 == 0 ) {}  // Wait for TA5 bit to be set..
     
     ECanaShadow.CANTA.all = 0; 	
     ECanaShadow.CANTA.bit.TA5 = 1;     	 // Clear TA5       
     ECanaRegs.CANTA.all = ECanaShadow.CANTA.all;
     
     loopcount ++; 			    
    }   

}

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

⌨️ 快捷键说明

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