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

📄 rxloop.c

📁 2812的CAN通讯源代码,需要的朋友请下载试用
💻 C
字号:
/*********************************************************************
* Filename: RXLOOP.c                                                 *
*                                                                    *
* Description: This test is a simple example of how data may be received  	
* in 28x CAN.
*
* This program runs on Node B. CANalyzer is used as node A in this example.
* All mailboxes are configured as receive mailboxes. Each mailbox
* has a different ID. All mailboxes in node A are allowed to transmit
* in a sequence to mailboxes in node B. Once the cycle is complete,
* the cycle is started all over again. 

* This program loops forever. The # of times the receive loop is executed
* is stored in the RXCOUNT value.
*      
* Last update: 12/24/2002
*********************************************************************/

#include "DSP28_Device.h"

long      RXCOUNT = 0;
long	  i;

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 - MBX number is written as its MSGID */
    
    ECanaMboxes.MBOX1.MSGID.all  = 0x00040000;  // Std identifier 
    ECanaMboxes.MBOX2.MSGID.all  = 0x00080000;  // Std identifier 
    ECanaMboxes.MBOX3.MSGID.all  = 0x000C0000;  // Std identifier 
    ECanaMboxes.MBOX4.MSGID.all  = 0x00100000;  // Std identifier 
    ECanaMboxes.MBOX5.MSGID.all  = 0x00140000;  // Std identifier 
    ECanaMboxes.MBOX6.MSGID.all  = 0x00180000;  // Std identifier 
    ECanaMboxes.MBOX7.MSGID.all  = 0x001C0000;  // Std identifier 
    ECanaMboxes.MBOX8.MSGID.all  = 0x00200000;  // Std identifier 
    ECanaMboxes.MBOX9.MSGID.all  = 0x00240000;  // Std identifier 
    ECanaMboxes.MBOX10.MSGID.all = 0x00400000;  // Std identifier 
    ECanaMboxes.MBOX11.MSGID.all = 0x00440000;  // Std identifier 
    ECanaMboxes.MBOX12.MSGID.all = 0x00480000;  // Std identifier 
    ECanaMboxes.MBOX13.MSGID.all = 0x004C0000;  // Std identifier 
    ECanaMboxes.MBOX14.MSGID.all = 0x00500000;  // Std identifier 
    ECanaMboxes.MBOX15.MSGID.all = 0x00540000;  // Std identifier 
    ECanaMboxes.MBOX16.MSGID.all = 0x00580000;  // Std identifier 
    ECanaMboxes.MBOX17.MSGID.all = 0x005C0000;  // Std identifier 
    ECanaMboxes.MBOX18.MSGID.all = 0x00600000;  // Std identifier 
    ECanaMboxes.MBOX19.MSGID.all = 0x00640000;  // Std identifier 
    ECanaMboxes.MBOX20.MSGID.all = 0x00800000;  // Std identifier 
    ECanaMboxes.MBOX21.MSGID.all = 0x00840000;  // Std identifier 
    ECanaMboxes.MBOX22.MSGID.all = 0x00880000;  // Std identifier 
    ECanaMboxes.MBOX23.MSGID.all = 0x008C0000;  // Std identifier 
    ECanaMboxes.MBOX24.MSGID.all = 0x00900000;  // Std identifier 
    ECanaMboxes.MBOX25.MSGID.all = 0x00940000;  // Std identifier 
    ECanaMboxes.MBOX26.MSGID.all = 0x00980000;  // Std identifier 
    ECanaMboxes.MBOX27.MSGID.all = 0x009C0000;  // Std identifier 
    ECanaMboxes.MBOX28.MSGID.all = 0x00A00000;  // Std identifier 
    ECanaMboxes.MBOX29.MSGID.all = 0x00A40000;  // Std identifier 
    ECanaMboxes.MBOX30.MSGID.all = 0x00C00000;  // Std identifier 
    ECanaMboxes.MBOX31.MSGID.all = 0x00C40000;  // Std identifier 
    ECanaMboxes.MBOX0.MSGID.all =  0x00C80000;  // Std identifier 
             
	/* Note: If writing to only the 11-bit identifier as by
	"ECanaMboxes.MBOX0.MSGID.bit.MSGID_H = 0x00C8", IDE, AME & AAM
	bit fields also need to be initialized. Otherwise, they 
	may assume random values */
	
/* Configure Mailboxes as Receive mailboxes */

	ECanaShadow.CANMD.all = ECanaRegs.CANMD.all;	
	ECanaShadow.CANMD.all = 0xFFFFFFFF;
	ECanaRegs.CANMD.all = ECanaShadow.CANMD.all; 
	
/* Enable Mailboxes */
	
	ECanaShadow.CANME.all = ECanaRegs.CANME.all;	
	ECanaShadow.CANME.all = 0xFFFFFFFF;
	ECanaRegs.CANME.all = ECanaShadow.CANME.all; 
	
/* Begin receiving */

    while(1) 							
    {
     while(ECanaRegs.CANRMP.all != 0xFFFFFFFF ) {}  // Wait for all RMPn to be set..
                
     ECanaRegs.CANRMP.all = 0xFFFFFFFF;			   // Clear all RMPn bits and start 
     RXCOUNT++ ;		                           // all over again...
    }   										   

}

/* CANalyzer configuration file: RXLOOP.CFG... */ 

⌨️ 快捷键说明

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