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.

CAN interface with TMS320F2808 Experimental kit

Other Parts Discussed in Thread: CONTROLSUITE, TMS320F2808

Hello,

I'm working with TMS320F280 Experimental kit and also Peripheral kit. I'm new to these kits.

so First of all i would like to know if i need a CAN Transreceiver for connecting kit or  it is already available on the board.

2. I would like to know if it is possible to change baud rate of the board, for default the clock on this board is 150MHZ and baud rate it is 1MBps, so can i change with some interface like simulink. if it is "yes" did you know where can i found information about that?

Please i need your support because i need to work on this


Thank you  for your help 


Karol



  • 1. What board exactly do you use?

    2. It is simple to change the CAN data rate: just edit the baud rate registers in intializing function "InitCan()" (in controlSuite support files). You haven't explained which code you use to inti CAN, so I assumed that the controlSuite support files are used.

     

  • Hi Frank

    Thank you for your response.

    1. I'm using TMS320F2808

    2. i'm using the sample code Example_28xEcan_A_to_B_Xmit.c

    3. i would like to know if i need a CAN Transceiver for connecting kit or it is already available on the board.

    Thank you for your response

    Karol

  • Assuming you use this kit: http://www.ti.com/tool/tmdsdock2808  : it does not have any CAN - Transceivers on board, as you can find out with the schematics in controlSUITE.

  • Hi frank

    I have a question to verify if the data that i'm sending through the USB CAN adapter is saving in a part of memory of F2808. I need to verify where is the data that i send and if it is possible to convert the data (hexa or binary) in decimal format. Could you help me with these.

    Thank you

  • (1) The received data are in the message - part (MDH, MDL) of the mailbox, which was initialized with a matching Identifier.

    (2) Hex to decimal is a general question and not related to this forum. Use any of the standard C-forums to find a solution, which is best to your needs. Or, program it by yourself. An example:

    unsigned long hex2int(char *a, unsigned int len)
    {
       
    int i;
       
    unsigned long val = 0;

       
    for(i=0;i<len;i++)
          
    if(a[i] <= 57)
        val
    += (a[i]-48)*(1<<(4*(len-1-i)));
          
    else
        val
    += (a[i]-55)*(1<<(4*(len-1-i)));
       
    return val;
    }

    Note: This code assumes uppercase A-F. It does not work if len is beyond your longest integer 32 or 64bits, and there is no error trapping for illegal hex characters.

     

  • Hi Frank

    Thank you so much, for your response.

    I would like to tell you what is the application that i'm working with F2808 to make some questions more puntuals about my doubts.

    So, First of all I built code on code composer, this code allow me transmit and receive messages. Look at the code:

    #include "DSP280x_Device.h"     // DSP280x Headerfile Include File
    #include "DSP280x_Examples.h"   // DSP280x Examples Include File

    // Prototipos de funciones externas
    extern void InitSysCtrl(void);
    extern void InitPieCtrl(void);
    extern void InitPieVectTable(void);
    extern void InitCpuTimers(void);
    extern void InitECan(void); 
    extern void ConfigCpuTimer(struct CPUTIMER_VARS *, float, float);


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

    //###########################################################################
    //      main code         
    //###########################################################################
    void main(void)
    {
     int counter=0; //Contador binario para la salida
     Uint16 temp;
     struct ECAN_REGS ECanaShadow;  // Copia local de los registros de CANA

     InitSysCtrl(); // Inicialización
         // SYSCLK=150MHz, HISPCLK=75MHz, LSPCLK=37.5MHz

     EALLOW;
        SysCtrlRegs.WDCR= 0x00AF; // activar watchdog
        EDIS;   // 0x00AF  para no activar Watchdog, Prescaler = 64

     DINT;    // Desactivar todos los interrupts  
     
     Gpio_select(); // GPIO9, GPIO11, GPIO34 and GPIO49 salidas
         // 4 LED 

     /* Initialize the CAN module */
     // NOTE: first modify TI-file: InitECan() to 100kbps by setting BTR = 49
     InitECan(); 
     
     /* Escribir en el Mailbox 1 el mensaje con el ID  */
     ECanaMboxes.MBOX1.MSGID.all  = 0x11111111;  // identificador extendido
        ECanaMboxes.MBOX1.MSGID.bit.IDE = 1;  
       
     /* Configurar Mailbox 1 como mailbox receptor */
     ECanaShadow.CANMD.all = ECanaRegs.CANMD.all; 
     ECanaShadow.CANMD.bit.MD1 = 1;
     ECanaRegs.CANMD.all = ECanaShadow.CANMD.all;

     /* Activar Mailbox 1         */
     ECanaShadow.CANME.all = ECanaRegs.CANME.all; 
     ECanaShadow.CANME.bit.ME1 = 1;
     ECanaRegs.CANME.all = ECanaShadow.CANME.all;
     
     /* Escribir en el Mailbox 5 el mensaje ID field    */
        ECanaMboxes.MBOX5.MSGID.all     = 0x11111111; // identificador del mensaje
        ECanaMboxes.MBOX5.MSGID.bit.IDE = 1;  //Identificador extendido
          
     /* Configure Mailbox 5 as transmit mailbox  */
     ECanaShadow.CANMD.all = ECanaRegs.CANMD.all; 
     ECanaShadow.CANMD.bit.MD5 = 0;
     ECanaRegs.CANMD.all = ECanaShadow.CANMD.all;
     
     /* Activar Mailbox 5   */
     ECanaShadow.CANME.all = ECanaRegs.CANME.all; 
     ECanaShadow.CANME.bit.ME5 = 1;
     ECanaRegs.CANME.all = ECanaShadow.CANME.all;

     /* Escribir el campo DLC en  registro de control maestro  */
     ECanaMboxes.MBOX5.MSGCTRL.all = 0;
     ECanaMboxes.MBOX5.MSGCTRL.bit.DLC = 8;

     InitPieCtrl();  // Configuración básica de PIE table; from DSP2833x_PieCtrl.c
     
     InitPieVectTable(); // Por defecto  ISR's in PIE

     EALLOW;
     PieVectTable.TINT0 = &cpu_timer0_isr;
     EDIS;

     InitCpuTimers(); // Configuración básica CPU Timer0, 1 and 2

     ConfigCpuTimer(&CpuTimer0,150,100000);

     PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

     IER |=1;

     EINT;
     ERTM;

     CpuTimer0Regs.TCR.bit.TSS = 0; // inicializar timer en 0

     while(1)
     {   
         while(CpuTimer0.InterruptCount < 10) // wait for 10*100 milliseconds
       {
        EALLOW;
        SysCtrlRegs.WDKEY = 0xAA; // service WD #2
        EDIS;
       }
       CpuTimer0.InterruptCount = 0;

       ECanaMboxes.MBOX5.MDL.byte.BYTE0 = counter & 0x00FF ;
           ECanaShadow.CANTRS.all = 0;  
           ECanaShadow.CANTRS.bit.TRS5 = 1;     // Colocar TRS para mailbox antes de la prueba            
           ECanaRegs.CANTRS.all = ECanaShadow.CANTRS.all;

       while(ECanaRegs.CANTA.bit.TA5 == 0 ) // Espera el bit TA5 se habilite    
           {
        EALLOW;
        SysCtrlRegs.WDKEY = 0xAA;    // Service watchdog #2
        EDIS;
           }
         
           ECanaShadow.CANTA.all = 0;  
           ECanaShadow.CANTA.bit.TA5 = 1;       // Borra Transmit Acknowledge #5            
           ECanaRegs.CANTA.all = ECanaShadow.CANTA.all;
       
       counter++;
       GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1;  // toggle red LED LD3 @ 28335CC
       
       while(CpuTimer0.InterruptCount == 0);
       CpuTimer0.InterruptCount = 0;
       
       EALLOW;
       SysCtrlRegs.WDKEY = 0x55; // service WD #1
       EDIS;

          if(ECanaRegs.CANRMP.bit.RMP1 == 1 )  // validar Nuevo dato en MBX1?
       {
         temp = ECanaMboxes.MBOX1.MDL.byte.BYTE0; // leer mensaje  
        ECanaRegs.CANRMP.bit.RMP1 = 1;   // borrar el estado del flag RMP1
                  //y prepara MBX1 para la siguiente recepción
        if(temp & 1)         // actualizar LED LD1
         GpioDataRegs.GPASET.bit.GPIO9 = 1;
        else
         GpioDataRegs.GPACLEAR.bit.GPIO9 = 1;
        if(temp & 2)        // actualizar LED LD2
         GpioDataRegs.GPASET.bit.GPIO11 = 1;
        else
         GpioDataRegs.GPACLEAR.bit.GPIO11 = 1;
        if(temp & 4)         // actualizar LED LD3
         GpioDataRegs.GPBSET.bit.GPIO34 = 1;
        else
         GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;
        //if(temp & 8)        // actualizar 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; // Enable pull-up for GPIO30  (CANRXA)
     GpioCtrlRegs.GPAMUX2.bit.GPIO31 = 1; // Enable pull-up for GPIO31  (CANTXA)

     GpioCtrlRegs.GPBMUX1.all = 0;  // GPIO34 ... GPIO32 = General Purpose I/O
      
      
     EDIS;
    }


    interrupt void cpu_timer0_isr(void)
    {
     CpuTimer0.InterruptCount++;
     EALLOW;
     SysCtrlRegs.WDKEY = 0x55; // service WD #1
     EDIS;
     PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
    }
    //===========================================================================
    // Fin del Codigo fuente.
    //===========================================================================

    2. Next i used a modem named USB CAN Adaptater to receive and transmit messages on the network, you can see on the image the messages receive and transmit.

    Look at:

    So, my question is where is located on the memory the messages that i transmit on the software?

    I opened on menu bar of code composer studio the option Gel the EcanRegisters and then open memory map, the software show me this:

    So, i don't know if i'm seeing on the right place the memory upload because when i observe the data on the mailbox these didn't mach with the data that i'm transmiting on USB CAN adapter.

    Could you tell me if i'm checking on the right place or if i have a mistake.

    Thank you so much for your reponse.

    Karol

     

  • Hi Frank 

    Now i can solve my problem of send messages throught CAN analyser and see on watch-window. But i would like to ask you if it is possible to store the data of mailboxes in new variables for then organize in a table  throught code composer or show i a new watch window.

    Thank you for your response

    Karol