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 Communication

Other Parts Discussed in Thread: CONTROLSUITE, TMS320F28335

I have a battery whose output is CAN H and CAN L. I am connecting the output of battery to tranceiver IC and TX and RX of the IC to DSP processorTMS320f28335.

Now i want to read the output of the battery, can u suggest me of the code that can be used to monitor the data and use it for further task. I could communicate via CAN transceiver between two DSP boards(i.e. in Self Test Mode)  but i am not aware where does the data gets store, i.e. in which mailbox, when operating in NORMAL MODE and what is the code for it and any more hardware changes. Also the data that is coming consists of 15 parameters which i want to access.  I am unaware of how to view each one of them in different mail boxes and use it for further analysis.

Thank You.

  • Hi Smitesh,

    First of all you'll have to go through the device CAN userguide to understand its structure. Secondly you can find the eCAN example codes in controlsuite here:
    C:\ti\controlSUITE\device_support\f2833x\v141\DSP2833x_examples_ccsv5

    Here you'll be able to observe setting up of mailboxes, message ids etc... Do let us know if you've more doubts.

    Regards,
    Gautam
  • Gautan Thank You for replying , i went through the structure and even the code, but i am not able to code such that each parameter enters the specific mail box for example parameter 1 in mailbox 0, parameter 2 in mailbox 1,... so on .

    Thank You.

  • Smitesh Modak said:
    but i am not able to code such that each parameter enters the specific mail box for example parameter 1 in mailbox 0, parameter 2 in mailbox 1,... so on .

    Can be more specific? Generally Message ID is used for parameter filtering.

  • Gautam, the CAN H and CAN L output of the battery has 15 parameters and i need to access them individually and i m not aware of the message id of the data that is coming out. So i m not able to understand how to impelement this. And is it possible to read CAN data without message id ?
  • Smitesh Modak said:
    i m not aware of the message id of the data that is coming out

    That's a must! How will you know which parameter is linked to what ID? Do you have the battery datasheet?

    Smitesh Modak said:
    And is it possible to read CAN data without message id ?

    That's like trying to fetch data from EEPROM without Address bit.

    Regards,

    Gautam

  • Gautam Thank You so much. I apologize for asking such an innocent question. Thank You Again. 

    I ll get back to you further if i have any doubts. 

    Thank You Again.

  • No problem. Do get back :)

    Regards,
    Gautam
  • Hi Gautam, I read this post where a guy wants to access 15 strings of data coming from battery and he also doesn't know the message ids of that data. And you have provided him with this answer . Can you explain it , I coudn't understand the difference between his and my problem although it seems similar. 

    Your reply:

    You can mask all the MsgID bits to receive to a particular Mailbox. Simply Set AME bit and configure ECanaLAMRegs.LAM2.all = 0xFFFFFFFF;

    for mailbox 2.

    By this can i see all the 15 parameters in a single mailbox and use the specific parameter?

  • Yes, you should be able to observe but all 15 would get dumped into one mailbox (Result being you'll be able to observe only one value). Hence you need to know which part of message ID gives you the type of the parameter. The best way would be to check the incoming data on a CAN analyzer and get the type details -> filter them accordingly.

    Regards,
    Gautam
  • Thank You so much Gautam.
  • You're Welcome!

    Goodluck & Regards,
    Gautam
  • Hello Gautam,
    this is the code i am using to read the data.

    //
    // Lab11_2: TMS320F28335
    // (c) Frank Bormann
    //
    //###########################################################################
    //
    // FILE: Lab11_2.c
    //
    // TITLE: CAN - Receive via F28335controlCARD
    // and SH65HVD230 at Peripheral Explorer Board
    //
    // Extended CAN-Frame is received with 100 kbit/s
    //
    // Objective:
    // Receive a 1 Byte data frame with Identifier 0x10000000
    // and display 4 least significant bits of byte0 at 4 LEDs
    //
    // Mailbox 1 is receiver
    // Identifier : 0x1000 0000
    // Data Length Code (DLC) = 1
    // eCANA is at GPIO31 (CANTXA) and GPIO30 (CANRXA)
    //
    // Frequency Osscillator @F28335controlCARD: 30MHz
    // PLLCR = 10 : multiply by 5
    // SYSCLKOUT = 150MHz , 28335-CAN-CLKIN = 75MHz
    // CAN - Bit timing set in file "DSP2833x_ECan.c" for 100 kbit/s:
    // TQ = (49 +1) / 75 MHz = 0.667 us: BRPREG = 49
    // tseg1 = 1us (10+1) = 7.333 us; TSEG1REG = 10
    // tseg2 = 1us (2+1) = 2 us; TSEG2REG = 2
    //###########################################################################
    // Ver | dd mmm yyyy | Who | Description of changes
    // =====|=============|======|===============================================
    // 3.0 | 14 Jul 2009 | F.B. | solution file Lab11_2 for F28335;
    // 3.1 | 15 Nov 2009 | F.B | Lab11_2 for F28335 @30MHz and PE revision 5
    //###########################################################################
    #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 = 0;

    /* 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;
    temp = ECanaMboxes.MBOX1.MDL.byte.BYTE0;

    if(ECanaRegs.CANRMP.bit.RMP1 == 1 ) // valid new data in MBX1?
    {
    // 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.
    //===========================================================================

    We have message identifier as 0x356, 0x355 and the source has provided the same message id for different parameter which each parameter assigned different byte position; so how do we know whether its extended identifier or standard identifier.
    And this is the connection i have made CAN TX from transceiver to GPIO31 (CANTXA) and CAN RX from transceiver to GPIO30 (CANRXA).
  • Smitesh Modak said:
    so how do we know whether its extended identifier or standard identifier.

    Simply check the IDE field in MSGID

    When AMI = 1:

    IDE = 1: The RECEIVED message had an extended identifier

    IDE = 0: The RECEIVED message had a standard identifier

    Regards,

    Gautam

  • Hi Gautam,

    I have a problem with my F28379D. When I programmed it with Simulink to transmit data over CAN I get this waveform on oscilloscope which is weird.

    It is supposed to be differential but CAN high and low are identical. that's why I can't read it through CANalyzer or other devices. Do you have any idea?

    Thanks,

    Kash

  • Hi Kash,

    Please don't post your queries in old threads. Create a new one for better support.
    Replied here: e2e.ti.com/.../2119142

    Regards,
    Gautam