|
我在一块dsp板中如果发送完了点亮一个led灯
在另一板中受到数据也点亮一个led灯
问题是自测模式能行,分开就不行;请大侠帮忙看看
程序:
// TI File $Revision: /main/4 $
// Checkin $Date: July 2, 2007 11:33:00 $
//###########################################################################
//
// FILE: Example_281xECanBack2Back.c
//
// TITLE: DSP281x eCAN Back-to-back transmission and reception in
// SELF-TEST mode
//
// ASSUMPTIONS:
//
// This program requires the DSP281x V1.00 header files.
// As supplied, this project is configured for "boot to H0" operation.
//
// Other then boot mode configuration, no other hardware configuration
// is required.
//
// DESCRIPTION:
//
// This test transmits data back-to-back at high speed without
// stopping.
// The received data is verified. Any error is flagged.
// MBX0 transmits to MBX16, MBX1 transmits to MBX17 and so on....
// This program illustrates the use of self-test mode
//
//###########################################################################
// $TI Release: DSP281x C/C++ Header Files V1.20 $
// $Release Date: July 27, 2009 $
//###########################################################################
#include "DSP281x_Device.h" // DSP281x Headerfile Include File
#include "DSP281x_Examples.h" // DSP281x Examples Include File
// Prototype statements for functions found within this file.
void mailbox_check(int32 T1, int32 T2, int32 T3);
void mailbox_read(int16 i);
void Gpio_select(void);
// Global variable for this example
Uint32 ErrorCount;
Uint32 MessageReceivedCount;
Uint32 TestMbox1 = 0;
Uint32 TestMbox2 = 0;
Uint32 TestMbox3 = 0;
void main(void)
{
Uint16 j;
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP281x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initalize GPIO:
// This example function is found in the DSP281x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio(); // Skipped for this example
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP281x_PieCtrl.c file.
// InitPieCtrl(); // Skipped for this example
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in DSP281x_DefaultIsr.c.
// This function is found in DSP281x_PieVect.c.
// InitPieVectTable(); // Skipped for this example
// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP281x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
///Gpio_select();
// Step 5. User specific code
Gpio_select();
MessageReceivedCount = 0;
ErrorCount = 0;
InitECan(); // Initialize the eCAN module
ConfigureECan();//Osea Add:configrue eCan mailbox ID、data etc..
// Begin transmitting
GpioDataRegs.GPADAT.bit.GPIOA0=1;
while(1)
{
ECanaRegs.CANTRS.all = 0x0000FFFF; // Set TRS for all transmit mailboxes发送请求置位寄存器
while(ECanaRegs.CANTA.all != 0x0000FFFF ) {} // Wait for all TAn bits to be set..当对应mailbox发送了相应位置位
ECanaRegs.CANTA.all = 0x0000FFFF; // Clear all TAn
GpioDataRegs.GPADAT.bit.GPIOA0=0;
MessageReceivedCount++;
DSP28x_usDelay(50000000);
GpioDataRegs.GPADAT.bit.GPIOA0=1;
DSP28x_usDelay(50000000);
//Read from Receive mailboxes and begin checking for data */
/* while(ECanaRegs.CANRMP.all != 0xFFFF0000){} //接收消息待决寄存器
for(j=0; j<16; j++) // Read & check 16 mailboxes
{
mailbox_read(j); // This func reads the indicated mailbox data
mailbox_check(TestMbox1,TestMbox2,TestMbox3); // Checks the received data
} */
}
}
// This function reads out the contents of the indicated
// by the Mailbox number (MBXnbr).
void mailbox_read(int16 MBXnbr)
{
volatile struct MBOX *Mailbox;
Mailbox = &ECanaMboxes.MBOX0 + MBXnbr;
TestMbox1 = Mailbox->MDL.all; // = 0x9555AAAn (n is the MBX number)
TestMbox2 = Mailbox->MDH.all; // = 0x89ABCDEF (a constant)
TestMbox3 = Mailbox->MSGID.all;// = 0x9555AAAn (n is the MBX number)
} // MSGID of a rcv MBX is transmitted as the MDL data.
void mailbox_check(int32 T1, int32 T2, int32 T3)
{
if((T1 != T3) || ( T2 != 0x89ABCDEF))
{
ErrorCount++;
}
}
void Gpio_select(void)
{
EALLOW;
GpioMuxRegs.GPAMUX.bit.PWM1_GPIOA0=0;
GpioMuxRegs.GPAMUX.bit.PWM2_GPIOA1=0;
GpioMuxRegs.GPAMUX.bit.PWM3_GPIOA2=0;
GpioMuxRegs.GPAMUX.bit.PWM4_GPIOA3=0;
GpioMuxRegs.GPAMUX.bit.PWM5_GPIOA4=0;
GpioMuxRegs.GPAMUX.bit.PWM6_GPIOA5=0;
GpioMuxRegs.GPADIR.bit.GPIOA0=1;
GpioMuxRegs.GPADIR.bit.GPIOA1=1;
GpioMuxRegs.GPADIR.bit.GPIOA2=1;
GpioMuxRegs.GPADIR.bit.GPIOA3=0;
GpioMuxRegs.GPADIR.bit.GPIOA4=0;
GpioMuxRegs.GPADIR.bit.GPIOA5=0;
EDIS;
}
//===========================================================================
// No more.
//===========================================================================
/* Note:
As indicated in the 281x device errata (SPRZ193), double-reads/double writes should be
employed for accesses to the mailbox RAM & LAM/MOTO/MOTS areas. Note, however, that the
errata is applicable only if the mailbox RAM & LAM/MOTO/MOTS areas are accessed at the
same time. The header file example operates in self-test mode, with no possibility of
a contention. Hence, the workaround is not implemented. When eCAN is communicating with
another node in non self-test mode), the workaround must be incorporated.
*/
点击此处下载 ourdev_626452UIMJJ5.rar(文件大小:236K) (原文件名:ecan_back2back.rar) |
阿莫论坛20周年了!感谢大家的支持与爱护!!
该献的血还是要献的。你不献他不献。难道让我去献? --- 出自坛友:lovejp1981
|