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.

Receive from PCan USB

Other Parts Discussed in Thread: TMS320F28335

Hey

I m working with TMS320F28335 connected to a PCAN usb. what im trying to do is create a program that sends messages from CAN A to PCAN and also receives Messages from PCAN to CAN A. The transmitting of the messagues works fine wheareas when i try to send a message from PCAN to CAN A it never reaches the mailbox. are there any ideas as to why this might happen. I have configured Mailbox 8 as the receive mailbox and mailbox 4 as the transmit one, here s my code:

/*--------------------------------------------------------------------------------------------------------------------*/
//                                   Can A Reception and Tranmition to/From PCAN                                                        //
/*--------------------------------------------------------------------------------------------------------------------*/
// Description:
/* The program configures Mailbox 8 In CAN A to Receive Messages from P_CAN and Mailbox 4 to Transmit to PCAN*/


#include "DSP2833x_Device.h"
#include "DSP2833x_Examples.h"


struct ECAN_REGS ECanaShadow;

Uint16 MessageCount=0;

void main()
{
// Initialize the System

        InitSysCtrl();

//Initialize GPIO for eCan
 
        InitECanGpio();

//Pie Control Registers are initialized to their default state

        InitPieCtrl();

// Enable CPU interrupts and clear all CPU interrupt flags:
 
//        EnableInterrupts();

// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
 
        InitPieVectTable();

// Initialize CAN A and CAN B

          InitECan(); 


/*---------------------------------Start Receive and Transmit Configurations Configuration------------------------------*/

// For the Transmit Mailbox Clear The CANTRS register

        ECanaShadow.CANTRR.all=ECanaRegs.CANTRR.all;
        ECanaShadow.CANTRR.bit.TRR4=1;
        ECanaRegs.CANTRR.all=ECanaShadow.CANTRR.all;

// Wait until TRS bit clears

        do
        { ECanaShadow.CANTRS.all=ECanaRegs.CANTRS.all;

            } while(ECanaShadow.CANTRS.bit.TRS4!=0);

//Dissable Mailbox

        ECanaShadow.CANME.all=ECanaRegs.CANME.all;
        ECanaShadow.CANME.bit.ME4=0;
        ECanaShadow.CANME.bit.ME8=0;
        ECanaRegs.CANME.all=ECanaShadow.CANME.all;

//Write Identifier in the Identifier Field
//Mailbox 4
       
        ECanaMboxes.MBOX4.MSGID.all=0x0000BBCC;
        ECanaMboxes.MBOX4.MSGID.bit.IDE=1;
        ECanaMboxes.MBOX4.MSGID.bit.AAM=0;
        ECanaMboxes.MBOX4.MSGID.bit.AME=0;


//Mailbox 8

        ECanaMboxes.MBOX8.MSGID.all=0x0000AACC;
        ECanaMboxes.MBOX8.MSGID.bit.IDE=1;
        ECanaMboxes.MBOX8.MSGID.bit.AME=0;


//Writting the Data Lenght

        ECanaMboxes.MBOX4.MSGCTRL.bit.DLC=8;

//Configure the Mailbox In Receive Direction


        ECanaShadow.CANMD.all=ECanaRegs.CANMD.all;
        ECanaShadow.CANMD.bit.MD4=0;
        ECanaShadow.CANMD.bit.MD8=1;
        ECanaRegs.CANMD.all=ECanaShadow.CANMD.all;

//Enable Mailbox

        ECanaShadow.CANME.all=ECanaRegs.CANME.all;
        ECanaShadow.CANME.bit.ME4=1;
        ECanaShadow.CANME.bit.ME8=1;
        ECanaRegs.CANME.all=ECanaShadow.CANME.all;

//----------------------------------------Start Transmission---------------------------------------------------------//

//Write The message data into the Mailbox Data Field

        ECanaMboxes.MBOX4.MDL.all= 0xAAAAAAAA;
        ECanaMboxes.MBOX4.MDH.all= 0x00000000;

for(;;)
{
        ECanaShadow.CANTRS.all=ECanaRegs.CANTRS.all;
        ECanaShadow.CANTRS.bit.TRS4=1;
        ECanaRegs.CANTRS.all=ECanaShadow.CANTRS.all;

    do{

        ECanaShadow.CANTA.all=ECanaRegs.CANTA.all;

        } while(ECanaShadow.CANTA.bit.TA4==0);


        ECanaShadow.CANTA.all= ECanaRegs.CANTA.all;
         ECanaShadow.CANTA.bit.TA4= 1;
         ECanaRegs.CANTA.all=ECanaShadow.CANTA.all;


    do{

        ECanaShadow.CANTA.all=ECanaRegs.CANTA.all;

        } while(ECanaShadow.CANTA.bit.TA4!=0);
   
    MessageCount++;
 
}

}

  • 1.)

    Thi initialization of your code looks ok. However I cannot see any lines in the for-loop of your example, which interact with the receiving mailbox 8. To receive CAN messages you either can use a polling ( register: Receive Message Pending - RMP ) or you can use an receiver interrupt from mailbox 8.

    2.)

    Your for-loop will send message after message from mailbox 4. Right after you have received the TA4  from the CAN you clear this bit, jump back to the beginning of the loop  and start sending the next message. This will cause a busload of 100%, which is not very clever.

    3.)

    I would recommend to use a timed transmission, lets say a new message every x milliseconds ( Cpu Timer 0 can be used as time base) and to poll the RMP bits in the meantime. Or, use a mailbox8 interrupt to read the data.

     

  • Thank you Frank for the advice, the code works properly now after a couple of changes made. I will make sure to Transmit in such a way that the busload is not that high. Best Regards