This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/TMS320F28335: CAN communication

Part Number: TMS320F28335

Tool/software: Code Composer Studio

hi all, this is code. i want to check wheather it is receving datat or not.. how should i check in ccs . which register should i check??

,plz ,help me.

#include "DSP2833x_Device.h"

// external function prototypes
extern void InitSysCtrl(void);
extern void InitPieCtrl(void);
extern void InitPieVectTable(void);
extern void InitCpuTimers(void);
extern void ConfigCpuTimer(struct CPUTIMER_VARS *, float, float);
extern void InitECan(void);


// Prototype statements for functions found within this file.
void Gpio_select(void);
interrupt void cpu_timer0_isr(void);

//###########################################################################
// main code
//###########################################################################
void main(void)
{
struct ECAN_REGS ECanaShadow; // local copy of CAN registers
Uint16 temp;

InitSysCtrl(); // Basic Core Init from DSP2833x_SysCtrl.c

EALLOW;
SysCtrlRegs.WDCR= 0x00AF; // Re-enable the watchdog
EDIS; // 0x00AF to NOT disable the Watchdog, Prescaler = 64

Gpio_select(); // GPIO9, GPIO11, GPIO34 and GPIO49 as output
// to 4 LEDs at Peripheral Explorer

/* Initialize the CAN module */
// NOTE: first modify TI-file: InitECan() to 100kbps by setting BTR = 49
InitECan();

/* Write to Mailbox 1 message ID field */
ECanaMboxes.MBOX1.MSGID.all = 0x10000000; // extended identifier
ECanaMboxes.MBOX1.MSGID.bit.IDE = 1;

/* Configure Mailbox 1 as Receiver mailbox */
ECanaShadow.CANMD.all = ECanaRegs.CANMD.all;
ECanaShadow.CANMD.bit.MD1 = 1;
ECanaRegs.CANMD.all = ECanaShadow.CANMD.all;

/* Enable Mailbox 1 */
ECanaShadow.CANME.all = ECanaRegs.CANME.all;
ECanaShadow.CANME.bit.ME1 = 1;
ECanaRegs.CANME.all = ECanaShadow.CANME.all;

InitPieCtrl(); // basic setup of PIE table; from DSP2833x_PieCtrl.c

InitPieVectTable(); // default ISR's in PIE

EALLOW;
PieVectTable.TINT0 = &cpu_timer0_isr;
EDIS;

InitCpuTimers(); // basic setup CPU Timer0, 1 and 2

ConfigCpuTimer(&CpuTimer0,150,100000);

PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

IER |=1;

EINT;
ERTM;

CpuTimer0Regs.TCR.bit.TSS = 0; // start timer0

while(1)
{
while(CpuTimer0.InterruptCount == 0);
CpuTimer0.InterruptCount = 0;

EALLOW;
SysCtrlRegs.WDKEY = 0x55; // service WD #1
EDIS;

if(ECanaRegs.CANRMP.bit.RMP1 == 1 ) // valid new data in MBX1?
{
temp = ECanaMboxes.MBOX1.MDL.byte.BYTE0; // read message
ECanaRegs.CANRMP.bit.RMP1 = 1; // clear the status flag RMP1
// and prepare MBX1 for next receive
if(temp & 1) // update LED LD1
GpioDataRegs.GPASET.bit.GPIO9 = 1;
else
GpioDataRegs.GPACLEAR.bit.GPIO9 = 1;
if(temp & 2) // update LED LD2
GpioDataRegs.GPASET.bit.GPIO11 = 1;
else
GpioDataRegs.GPACLEAR.bit.GPIO11 = 1;
if(temp & 4) // update LED LD3
GpioDataRegs.GPBSET.bit.GPIO34 = 1;
else
GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;
if(temp & 8) // update LED LD4
GpioDataRegs.GPBSET.bit.GPIO49 = 1;
else
GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1;
}
}
}

void Gpio_select(void)
{
EALLOW;
GpioCtrlRegs.GPAMUX1.all = 0; // GPIO15 ... GPIO0 = General Puropse I/O
GpioCtrlRegs.GPAMUX2.all = 0; // GPIO31 ... GPIO16 = General Purpose I/O
GpioCtrlRegs.GPAMUX2.bit.GPIO30 = 1; // CANA_RX
GpioCtrlRegs.GPAMUX2.bit.GPIO31 = 1; // CANA_TX

GpioCtrlRegs.GPBMUX1.all = 0; // GPIO47 ... GPIO32 = General Purpose I/O
GpioCtrlRegs.GPBMUX2.all = 0; // GPIO63 ... GPIO48 = General Purpose I/O
GpioCtrlRegs.GPCMUX1.all = 0; // GPIO79 ... GPIO64 = General Purpose I/O
GpioCtrlRegs.GPCMUX2.all = 0; // GPIO87 ... GPIO80 = General Purpose I/O

GpioCtrlRegs.GPADIR.all = 0;
GpioCtrlRegs.GPADIR.bit.GPIO9 = 1; // peripheral explorer: LED LD1 at GPIO9
GpioCtrlRegs.GPADIR.bit.GPIO11 = 1; // peripheral explorer: LED LD2 at GPIO11

GpioCtrlRegs.GPBDIR.all = 0; // GPIO63-32 as inputs

GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1; // peripheral explorer: LED LD3 at GPIO34
GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1; // peripheral explorer: LED LD4 at GPIO49

GpioCtrlRegs.GPCDIR.all = 0; // GPIO87-64 as inputs
EDIS;
}

interrupt void cpu_timer0_isr(void)
{
CpuTimer0.InterruptCount++;
EALLOW;
SysCtrlRegs.WDKEY = 0xAA; // service WD #2
EDIS;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
//===========================================================================
// End of SourceCode.
//===========================================================================

  • Have you looked at my Application Report “Programming Examples for the TMS320x28xx eCAN (http://www.ti.com/lit/an/spra876b/spra876b.pdf )”? If not, please download it and take a look at the examples. All examples have been tested on the device and you should be able to run it “as is” if you are running it on a F28335 device, with a 30 MHz clock input. For your specific question, there are two example testcases: 

    • CAN_RXLOOP

    This is an example of how data may be received using polling.

    • CAN_RXINT

    This is a simple example of how data may be received using interrupts.

     

    To be able to receive a frame, a receive MBX must be properly configured to receive it. Either it should have the same MSGID as the transmitted frame or it should satisfy the acceptance filtering criterion. You need to check CANRMP register. All this is clearly shown in the examples.