Part Number: TMS320F28069M
Other Parts Discussed in Thread: TMS320F28335, C2000WARE
Hi Sir,
I have TMS320F28069M Eval. board. I want to receive CAN data with the ID of 0xC0000037.
But i am unable to receive the data.
I have attached my code, please have a look what mistake i have done.
//###########################################################################
//
// FILE: Example_2806xECanBack2Back.c
//
// TITLE: eCAN back to back Example
//
//! \addtogroup f2806x_example_list
//! <h1>eCAN back to back (ecan_back2back)</h1>
//!
//! This example tests eCAN by transmitting 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 example uses the self-test mode of the CAN module. i.e. the
//! transmission/reception happens within the module itself (even the required
//! ACKnowldege is generated internally in the module). Therefore, there is no
//! need for a CAN transceiver to run this particular test case and no activity
//! will be seen in the CAN pins/bus. Because everything is internal, there is
//! no need for a 120-ohm termination resistor. Note that a real-world CAN
//! application needs a CAN transceiver and termination resistors on both ends
//! of the bus.
//!
//! \b Watch \b Variables \n
//! - PassCount
//! - ErrorCount
//! - MessageReceivedCount
//
//
//###########################################################################
// $TI Release: $
// $Release Date: $
// $Copyright:
// Copyright (C) 2009-2021 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
//
// Included Files
//
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
/*
* Header file of SCU
*/
#include "SCU.h"
int * Electron_Health_STS;
int arr[100] = {0};
int Electron_HLTH = 0;
int EV_Detect=0;
int CHRG_STRT=0;
//
// Function Prototypes
//
void mailbox_check(int32 T1, int32 T2, int32 T3);
void mailbox_read(int16 i);
Uint16 i=0;
//
// Globals
//
Uint32 ErrorCount;
Uint32 PassCount;
Uint32 MessageReceivedCount;
Uint32 TestMbox1 = 0;
Uint32 TestMbox2 = 0;
Uint32 TestMbox3 = 0;
//
// Main
//
void main(void)
{
Uint16 j;
//
// eCAN control registers require read/write access using 32-bits. Thus we
// will create a set of shadow registers for this example. These shadow
// registers will be used to make sure the access is 32-bits and not 16.
//
struct ECAN_REGS ECanaShadow;
//
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the F2806x_SysCtrl.c file.
//
InitSysCtrl();
//
// Step 2. Initialize GPIO:
// This example function is found in the F2806x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
//
// InitGpio(); // Skipped for this example
//
// For this example, configure CAN pins using GPIO regs here
// This function is found in F2806x_ECan.c
//
InitECanGpio();
//
// 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 F2806x_PieCtrl.c file.
//
InitPieCtrl();
//
// 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 F2806x_DefaultIsr.c.
// This function is found in F2806x_PieVect.c.
//
InitPieVectTable();
//
// Step 4. Initialize all the Device Peripherals:
// This function is found in F2806x_InitPeripherals.c
//
// InitPeripherals(); // Not required for this example
//
// Step 5. User specific code, enable interrupts:
//
MessageReceivedCount = 0;
ErrorCount = 0;
PassCount = 0;
InitECana(); // Initialize eCAN-A module
/*
* Added by Divyesh
*/
// ECanaRegs.CANME.all = 0x00; // Added by Divyesh
//
// Mailboxs can be written to 16-bits or 32-bits at a time
// Write to the MSGID field of TRANSMIT mailboxes MBOX0 - 15
//
/*
* Extended Frame Configuration
*/
// ECanaMboxes.MBOX0.MSGID.all = Electron_EMG_SHTDN; // Message ID 0x2000
// ECanaMboxes.MBOX1.MSGID.all = EV_Ready;
// ECanaMboxes.MBOX2.MSGID.all = EV_Max_PWR;
// ECanaMboxes.MBOX3.MSGID.all = EV_Trgt_VLT;
// ECanaMboxes.MBOX4.MSGID.all = EV_Trgt_CRNT;
// ECanaMboxes.MBOX5.MSGID.all = EV_CHRG_CMPLT;
// ECanaMboxes.MBOX6.MSGID.all = EV_STDBY;
// ECanaMboxes.MBOX7.MSGID.all = EV_CHRG_STRT_STP;
// ECanaMboxes.MBOX8.MSGID.all = 0x9555AAA8;
// ECanaMboxes.MBOX9.MSGID.all = 0x9555AAA9;
// ECanaMboxes.MBOX10.MSGID.all = 0x9555AAAA;
// ECanaMboxes.MBOX11.MSGID.all = 0x9555AAAB;
// ECanaMboxes.MBOX12.MSGID.all = BMS_STS;
// ECanaMboxes.MBOX13.MSGID.all = DCDC_STS;
// ECanaMboxes.MBOX14.MSGID.all = OBC_STS;
// ECanaMboxes.MBOX15.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX0.MSGID.all = IMD_Info; // Message ID 0x2000
// ECanaMboxes.MBOX1.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX2.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX3.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX4.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX5.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX6.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX7.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX8.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX9.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX10.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX11.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX12.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX13.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX14.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX15.MSGID.all = IMD_Info;
//
// Write to the MSGID field of RECEIVE mailboxes MBOX16 - 31
//
// ECanaMboxes.MBOX16.MSGID.all = IMD_Info; // Message ID 0x2000
// ECanaMboxes.MBOX17.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX18.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX19.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX20.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX21.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX22.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX23.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX24.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX25.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX26.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX27.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX28.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX29.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX30.MSGID.all = IMD_Info;
// ECanaMboxes.MBOX31.MSGID.all = IMD_Info;
// EDIS;
/* Configure mask for Mailboxes*/
// ECanaLAMRegs.LAM31.all = 0xBF000000; // MSGID Mask for MBOX1 (RX Quick Coupler): b10111111000000000000000000000000
//
// Configure Mailboxes 0-15 as Tx, 16-31 as Rx
// Since this write is to the entire register (instead of a bit
// field) a shadow register is not required.
//
// ECanaRegs.CANMD.all = 0xFFFF0000;
/*
* Added by Divyesh
*/
ECanaMboxes.MBOX31.MSGCTRL.bit.DLC = 8;
//Set RTR bit
ECanaMboxes.MBOX31.MSGCTRL.bit.RTR = 1;
ECanaMboxes.MBOX31.MSGID.all = IMD_Info;
EDIS;
ECanaRegs.CANMD.bit.MD31 = 0x01; // MD31 receive
// ECanaRegs.CANOPC.all = 0xFFFFFFFF; // added by Divyesh
/* Configure Mailbox 1 under test as a Receive mailbox */
ECanaMboxes.MBOX31.MSGID.bit.IDE = 1; // Set Mailbox 31 with a 29-bit extended MSGID
ECanaShadow.CANMD.all = ECanaRegs.CANMD.all; // Save the (CANMD) Message Data Register
ECanaShadow.CANMD.bit.MD31 = 1; // Set Mailbox 1 as receive
ECanaRegs.CANMD.all = ECanaShadow.CANMD.all; // Set the (CANMD) Message Data Register
/* Enable Mailbox 1 under test */
ECanaShadow.CANME.all = ECanaRegs.CANME.all; // Save the (CANME) Mailbox Enable Register
ECanaShadow.CANME.bit.ME31 = 1; // Enable Mailbox 1
ECanaRegs.CANME.all = ECanaShadow.CANME.all; // Set the (CANME) Mailbox Enable Register
/*
* Added by Divyesh
*/
ECanaRegs.CANTRS.bit.TRS31 = 0x1;
//
// Enable all Mailboxes
// Since this write is to the entire register (instead of a bit
// field) a shadow register is not required.
//
// ECanaRegs.CANME.all = 0xFFFFFFFF; // Disabled by Divyesh
// ECanaRegs.CANME.bit.ME31 = 0x00; // Added by Divyesh
//
// Specify the bits to be sent/received
//
// ECanaMboxes.MBOX0.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX1.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX2.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX3.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX4.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX5.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX6.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX7.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX8.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX9.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX10.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX11.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX12.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX13.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX14.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX15.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX16.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX17.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX18.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX19.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX20.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX21.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX22.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX23.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX24.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX25.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX26.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX27.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX28.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX29.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX30.MSGCTRL.bit.DLC = 8;
// ECanaMboxes.MBOX31.MSGCTRL.bit.DLC = 8;
//
// //Set RTR bit
// ECanaMboxes.MBOX31.MSGCTRL.bit.RTR = 1;
//
// Write to the mailbox RAM field of MBOX0 - 15
//
// ECanaMboxes.MBOX0.MDL.all = 0x00;
// ECanaMboxes.MBOX0.MDH.all = 0x00;
//
// ECanaMboxes.MBOX1.MDL.all = 0x00;
// ECanaMboxes.MBOX1.MDH.all = 0x00;
//
// ECanaMboxes.MBOX2.MDL.all = 0xA2; // 674W watt Power
// ECanaMboxes.MBOX2.MDH.all = 0x02;
//
// ECanaMboxes.MBOX3.MDL.all = 0x90; // 400V Voltage in V
// ECanaMboxes.MBOX3.MDH.all = 0x01;
//
// ECanaMboxes.MBOX4.MDL.all = 0x7D; // 125A Current in A
// ECanaMboxes.MBOX4.MDH.all = 0x00;
//
// ECanaMboxes.MBOX5.MDL.all = 0x06;
// ECanaMboxes.MBOX5.MDH.all = 0x00;
//
// ECanaMboxes.MBOX6.MDL.all = 0x07;
// ECanaMboxes.MBOX6.MDH.all = 0x00;
//
// ECanaMboxes.MBOX7.MDL.all = 0x08;
// ECanaMboxes.MBOX7.MDH.all = 0x00;
//
// ECanaMboxes.MBOX8.MDL.all = 0x09;
// ECanaMboxes.MBOX8.MDH.all = 0x00;
//
// ECanaMboxes.MBOX9.MDL.all = 0x0A;
// ECanaMboxes.MBOX9.MDH.all = 0x00;
//
// ECanaMboxes.MBOX10.MDL.all = 0x0B;
// ECanaMboxes.MBOX10.MDH.all = 0x00;
//
// ECanaMboxes.MBOX11.MDL.all = 0x0C;
// ECanaMboxes.MBOX11.MDH.all = 0x00;
//
// ECanaMboxes.MBOX12.MDL.all = 0x00;
// ECanaMboxes.MBOX12.MDH.all = 0x00;
//
// ECanaMboxes.MBOX13.MDL.all = 0x00;
// ECanaMboxes.MBOX13.MDH.all = 0x00;
//
// ECanaMboxes.MBOX14.MDL.all = 0x00;
// ECanaMboxes.MBOX14.MDH.all = 0x00;
// ECanaMboxes.MBOX15.MDL.all = 0x01;
// ECanaMboxes.MBOX15.MDH.all = 0x00;
//
// Since this write is to the entire register (instead of a bit
// field) a shadow register is not required.
//
// EALLOW;
// ECanaRegs.CANMIM.all = 0xFFFFFFFF;
/*
* Declared by Divyesh
*/
// ECanaRegs.CANTRS.bit.TRS31 = 1;
//
// Configure the eCAN for self test mode
// Enable the enhanced features of the eCAN.
//
// ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
//// ECanaShadow.CANMC.bit.STM = 1; // Configure CAN for self-test mode
// ECanaShadow.CANMC.bit.STM = 0; // Configure CAN for self-test mode
// ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
// EDIS;
/*
* Electron Safety Check
*/
// Electron_Health_STS = electron_check();
//
// Begin transmitting
//
// for(;;)
while(1)
{
/*
* Send Data to Telematics
*/
// Telematics();
//
// Set TRS for all transmit mailboxes
//
// ECanaRegs.CANTRS.all = 0x0000FFFF;
//
// Wait for all TAn bits to be set
//
// while(ECanaRegs.CANTA.all != 0x0000FFFF )
// {
//
// }
//
// ECanaRegs.CANTA.all = 0x0000FFFF; // Clear all TAn
MessageReceivedCount++;
//
// Read from Receive mailboxes and begin checking for data
// Read & check 16 mailboxes
//
for(j=16; j<32; j++)
{
//
// This func reads the indicated mailbox data
//
// while(ECanaShadow.CANRMP.bit.RMP31 != 1 ); // if Mailbox 1 has not received any messages
// ECanaShadow.CANRMP.bit.RMP31 = 1; // Set Mailbox 1 as having recieved a message
// ECanaRegs.CANRMP.all = ECanaShadow.CANRMP.all;
mailbox_read(31);
//
// Checks the received data
//
mailbox_check(TestMbox1,TestMbox2,TestMbox3);
/*
* Electron Safety Check
*/
// Electron_Health_STS = electron_check();
}
j = 0;
// return;
/*
* Main Execution of System
*/
// if(Electron_HLTH == 0) // IF system is Healthy
// {
//
// /*
// * Read Command from HMI
// */
//
// /*
// * Read CAN signal from CMC if EV Detected
// */
// if(EV_Detect == 1)
// {
//
// EV_INFO(); // Read EV Information
// HMI_RCV(); // Authorization of customer and start charge signal
// /*
// * Electron Safety Check
// */
// Electron_Health_STS = electron_check();
//
// HMI_Send(); // Send Confirmation for charging on Display
//
// if(CHRG_STRT == 1) // If start Charging Command received from User through HMI
// {
// electron_start(); // Send EV Ready Command to HMI
// }
// }
// else
// {
//
// }
// }//IF loop of Electron health
// else
// {
// /*
// * Emergency Shutdown the System
// */
// Emergency_Shtdn();
// }
}//Continues for loop
}
//
// mailbox_read - This function reads out the contents of the indicated
// by the Mailbox number (MBXnbr). MSGID of a rcv MBX is transmitted as the
// MDL data.
//
void
mailbox_read(int16 MBXnbr)
{
volatile struct MBOX *Mailbox;
Mailbox = &ECanaMboxes.MBOX0 + MBXnbr;
// ECanaRegs.CANRMP.all = 0xFFFFFFFF;
// switch (MBXnbr )
// {
// case 16:
// ECanaRegs.CANRMP.bit.RMP16 = 0;
// break;
//
// case 17:
// ECanaRegs.CANRMP.bit.RMP17 = 0;
// break;
//
// case 18:
// ECanaRegs.CANRMP.bit.RMP18 = 0;
// break;
//
// case 19:
// ECanaRegs.CANRMP.bit.RMP19 = 0;
// break;
//
// case 20:
// ECanaRegs.CANRMP.bit.RMP20 = 0;
// break;
//
// case 21:
// ECanaRegs.CANRMP.bit.RMP21 = 0;
// break;
//
// case 22:
// ECanaRegs.CANRMP.bit.RMP22 = 0;
// break;
//
// case 23:
// ECanaRegs.CANRMP.bit.RMP23 = 0;
// break;
//
// case 24:
// ECanaRegs.CANRMP.bit.RMP24 = 0;
// break;
//
// case 25:
// ECanaRegs.CANRMP.bit.RMP25 = 0;
// break;
//
// case 26:
// ECanaRegs.CANRMP.bit.RMP26 = 0;
// break;
//
// case 27:
// ECanaRegs.CANRMP.bit.RMP27 = 0;
// break;
//
// case 28:
// ECanaRegs.CANRMP.bit.RMP28 = 0;
// break;
//
// case 29:
// ECanaRegs.CANRMP.bit.RMP29 = 0;
// break;
//
// case 30:
// ECanaRegs.CANRMP.bit.RMP30 = 0;
// break;
//
// case 31:
// ECanaRegs.CANRMP.bit.RMP31 = 0;
// break;
//
// default:
// break;
// }
TestMbox1 = ECanaMboxes.MBOX31.MDH.all + (ECanaMboxes.MBOX31.MDL.all * 4294967296L); // Receive the messages from Mailbox 1
//
// 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)
}
//
// mailbox_check -
//
void
mailbox_check(int32 T1, int32 T2, int32 T3)
{
// if((T1 != T3) || ( T2 != 0x89ABCDEF))
// {
// ErrorCount++;
// }
// else
// if((T1 == 0x37) || (T2 == 0x37) || (T3 == 0x37))
{
PassCount++;
}
}
//
// End of File
//
