remreq2.c

来自「闻亭2812开发板光盘」· C语言 代码 · 共 100 行

C
100
字号
/*********************************************************************
* Filename: REMREQ2.c                                                

 Description: This test checks the ability of the CAN module to SEND
 remote frames from (and receive dataframes in) the SAME Mailbox.

Mailboxes 2,3,4,5 in 28x are configured as Receive mailboxes and their
TRS bits and RTR bits are set. This enables the same mailbox to transmit
a remote frame and receive the corresponding data frame. Mailboxes in 
node B (a LF2407A EVM) would transmit DATA frames to the four Rx
mailboxes in 28x, matching the ID of mailboxes.  (ECN Ref #15)

* Last update: 12/25/2002
*********************************************************************/

#include "DSP28_Device.h"

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();
	
/* Initialize mailbox data to zero */

	ECanaMboxes.MBOX2.MDRH.all = 0x00000000;
	ECanaMboxes.MBOX2.MDRL.all = 0x00000000;
	ECanaMboxes.MBOX3.MDRH.all = 0x00000000;
	ECanaMboxes.MBOX3.MDRL.all = 0x00000000;
	ECanaMboxes.MBOX4.MDRH.all = 0x00000000;
	ECanaMboxes.MBOX4.MDRL.all = 0x00000000;
	ECanaMboxes.MBOX5.MDRH.all = 0x00000000;
	ECanaMboxes.MBOX5.MDRL.all = 0x00000000;	
	
/* Write to the MSGID field  */	
     
    ECanaMboxes.MBOX2.MSGID.all  = 0x8AAAAA02;  // Ext identifier 
    ECanaMboxes.MBOX3.MSGID.all  = 0x8AAAAA03;  // Ext identifier 
    ECanaMboxes.MBOX4.MSGID.all  = 0x8AAAAA04;  // Ext identifier 
    ECanaMboxes.MBOX5.MSGID.all  = 0x8AAAAA05;  // Ext identifier 
    
/* Enable all Mailboxes */
	
	ECanaRegs.CANME.all = 0x0000003C;
	
/* Write to Master Control field - RTR */
 
    ECanaMboxes.MBOX2.MCF.bit.RTR = 1;  
    ECanaMboxes.MBOX3.MCF.bit.RTR = 1;
    ECanaMboxes.MBOX4.MCF.bit.RTR = 1;
    ECanaMboxes.MBOX5.MCF.bit.RTR = 1;
       
    ECanaMboxes.MBOX2.MCF.bit.DLC = 8;  
    ECanaMboxes.MBOX3.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX4.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX5.MCF.bit.DLC = 7;     
    
/* Configure all Mailboxes as Rx */

	ECanaRegs.CANMD.all = 0x0000003C;     
          
/* Transmit the remote frames and Wait for data frames.. */

	ECanaShadow.CANTRS.all = 0; 	
    ECanaShadow.CANTRS.all = 0x0000003C;     // Set TRS for Rx mailboxes       
    ECanaRegs.CANTRS.all = ECanaShadow.CANTRS.all; 
	
    while(1) {}							
   
}


/* 

Observations:

28x sent remote frames from mailboxes 2,3,4,5 to mailboxes 2,3,4,5 in
a 2407 EVM. The corresponding data frames were received in 
mailboxes 2,3,4,5 of 28x.

It is important to correctly configure the DLC value in the remote frame
since only that many bytes will be transmitted in the data frame.

Use 1M80spRX.CFG in CANalyzer.

Use REM28ANS.asm in the 2407 EVM
*/

⌨️ 快捷键说明

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