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.

RTOS/tda3: how to set mcan bit rate

Part Number: tda3

Tool/software: TI-RTOS

hi all:

We are using  Mcan in TDA3.  Please  show us how to set the mcan's bit rate.

Thanks !

  • Hi Song,

    which SDK you use?

    Regards,
    Yordan
  • Hi,

    I'm not familiar with TI-RTOS, but I want to flag that MCAN hardware is described in TDA3 TRM, particularly see the MCAN_DBTP register for CAN timing.

    Regards,

    Stan

  • Hi Yordan:

    Thanks for your answer . We are using "VISION_SDK_02_12_00_00". And another question, is there any demo for mcan such as "utils_dcan" in the SDK.  We have problem in how to initialize the clock and the interrupt of mcan.

    Thanks and Regards

  • Hi Song,

    MCAN sample application is available in Starterware at "<starterware_install_dir>\starterware_\examples\mcan_app\mcanEvmLoopback".
    In this sample application, mcan_clk is initialized to 80MHz. Please refer to function 'App_mcanConfig()' for baud rate configuration and 'App_mcanXBarConfig()' for interrupt configuration.

    Regards,
    Vivek Dhande.
    Texas Instruments (India) Pvt Ltd
  • hi Vivek :

    Thanks for your answer.
    In our application , we need set mcan to classic mode, and the bitrate is 500KBps.
    The initialization code is as follows:

    /* Initialize MCAN Init params */
    initParams.fdMode = 0x0U;
    initParams.brsEnable = 0x0U;
    initParams.txpEnable = 0x0U;
    initParams.efbi = 0x0U;
    initParams.pxhddisable = 0x0U;
    initParams.darEnable = 0x1U;
    initParams.wkupReqEnable = 0x1U;
    initParams.autoWkupEnable = 0x1U;
    initParams.emulationEnable = 0x0U;
    initParams.emulationFAck = 0x0U;
    initParams.wdcPreload = 0xFFU;
    initParams.clkStopFAck = 0x0U;
    initParams.tdcEnable = 0x0U;
    initParams.tdcConfig.tdcf = 0xAU;
    initParams.tdcConfig.tdco = 0x6U;
    /* Initialize MCAN Config params */
    configParams.monEnable = 0x0U;
    configParams.asmEnable = 0x0U;
    configParams.tsPrescalar = 0xFU;
    configParams.tsSelect = 0x0U;
    configParams.timeoutSelect = MCAN_TIMEOUT_SELECT_CONT;
    configParams.timeoutPreload = 0xFFFFU;
    configParams.timeoutCntEnable = 0x0U;
    configParams.filterConfig.rrfs = 0x1U;
    configParams.filterConfig.rrfe = 0x1U;
    configParams.filterConfig.anfe = 0x1U;
    configParams.filterConfig.anfs = 0x1U;

    /* Initialize Message RAM Sections Configuration Parameters */
    msgRAMConfigParams.flssa = 0;
    msgRAMConfigParams.lss = 8;
    msgRAMConfigParams.flesa = 100;
    msgRAMConfigParams.lse = 8;
    msgRAMConfigParams.txStartAddr = 400;
    msgRAMConfigParams.txBufNum = 8;
    msgRAMConfigParams.txFIFOSize = 0U;
    msgRAMConfigParams.txBufMode = 0U;
    msgRAMConfigParams.txBufElemSize = MCAN_ELEM_SIZE_8BYTES;
    msgRAMConfigParams.txEventFIFOStartAddr = 280;
    msgRAMConfigParams.txEventFIFOSize = 8;
    msgRAMConfigParams.txEventFIFOWaterMark = 3U;
    msgRAMConfigParams.rxFIFO0startAddr = 720;
    msgRAMConfigParams.rxFIFO0size = 8;
    msgRAMConfigParams.rxFIFO0waterMark = 3U;
    msgRAMConfigParams.rxFIFO0OpMode = 0U;
    msgRAMConfigParams.rxFIFO1startAddr = 1000;
    msgRAMConfigParams.rxFIFO1size = 8;
    msgRAMConfigParams.rxFIFO1waterMark = 3U;
    msgRAMConfigParams.rxFIFO1OpMode = 0U;
    msgRAMConfigParams.rxBufStartAddr = 1280;
    msgRAMConfigParams.rxBufElemSize = MCAN_ELEM_SIZE_8BYTES;
    msgRAMConfigParams.rxFIFO0ElemSize = MCAN_ELEM_SIZE_8BYTES;
    msgRAMConfigParams.rxFIFO1ElemSize = MCAN_ELEM_SIZE_8BYTES;

    bitTimes.nomRatePrescalar = 0x0U;
    bitTimes.nomTimeSeg1 = 0xAU;
    bitTimes.nomTimeSeg2 = 0x3U;
    bitTimes.nomSynchJumpWidth = 0x3U;
    bitTimes.dataRatePrescalar = 0x0U;
    bitTimes.dataTimeSeg1 = 0x3U;
    bitTimes.dataTimeSeg2 = 0x3U;
    bitTimes.dataSynchJumpWidth = 0xAU;

    clock configure:
    /* Clock Configuration. */
    dpllId = PMHAL_PRCM_DPLL_DSP_GMAC;
    dpllPostDivider.postDivId = PMHAL_PRCM_DPLL_POST_DIV_H14;
    dpllPostDivider.configValue = 25U;
    UTILS_assert (PM_SUCCESS == PMHALCMDpllSetPostDiv(dpllId,
    &dpllPostDivider, 1U));

    The interrupt line is chosen "MCAN_IRQ_INT0".

    Using the above configure, the APP can't send and receive data. (The register "MCAN_TXBRP" will not be cleared).

    Please help us to parse this problem.

    Thanks and regards!
  • Hi Song,

    From your configurations, you are configuring mcan_clk as 80MHz. Also, you are configuring Nominal bit rate as 5 Mbps as you are programming 'bitTimes.nomRatePrescalar' as '0', which is wrong for 500 kbps bit rate. Instead you should program it as '9'. Refer following for more details.
    Bit rate calculation:
    bit rate = ((mcan_clk / prescalar) / (Sum of timing parameters))
    So here, mcan_clk = 80 MHz, prescalar = = (nomRatePrescalar + 1) = 10, Sum of timing parameters = (nomTimeSeg1 + nomTimeSeg2 + 3) = (0xA + 0x3 + 3) = 16
    bit rate = (80MHz / 10) / 16 = 500 kbps
    Does this application use internal loopback? If not then make sure that bit rate on both sides i.e. Transmitter and Receiver side is same.


    Regards,
    Vivek Dhande.
    Texas Instruments (India) Pvt Ltd
  • hi Vivek :

    Thanks very much for your help.

    I have changed the bit rate configure as follows.

    bitTimes.nomRatePrescalar = 0x9U;
    bitTimes.nomTimeSeg1 = 0xAU;
    bitTimes.nomTimeSeg2 = 0x3U;
    bitTimes.nomSynchJumpWidth = 0x3U;
    bitTimes.dataRatePrescalar = 0x13U;
    bitTimes.dataTimeSeg1 = 0x3U;
    bitTimes.dataTimeSeg2 = 0x2U;
    bitTimes.dataSynchJumpWidth = 0x0U;

    Both nominal and data bit-rate are set to 500Kbps.

    The  internal loopback can work , but when transmit to other equipment. I have another question about the rules to how to set parameters "RatePrescalar", "TimeSeg1", "TimeSeg2". Is there any equation?

    Thanks and Regards

  • Hi Song,

    Yes, internal loopback will work with any feasible bit rate since transmitter and receiver is same. Since MCAN is working in classic CAN mode data bit rate does not matter.
    What hardware are you using? Is is TI EVM? If not then IO PADs (Tx and Rx) has to be configured accordingly. Also, you need to enable transceiver, if not enabled by default.

    Regards,
    Vivek Dhande.
    Texas Instruments (India) Pvt Ltd
  • Hi Vivek

    We are using our DEMO board. There is something wrong when set PADs, now this issue is fixed. Thanks very much!
    Another question:
    What is the rules to how to set parameters "RatePrescalar", "TimeSeg1", "TimeSeg2". Is there any equation like Dcan?

    Thanks and Regards
  • Hi Song,

    'TimeSeg1' and 'TimeSeg2' can be used to manipulate Sample Point for CAN Bit Timings. Typically Sample Point used in CAN communication is around 75% to 90%. At same time, 'TimeSeg1' should be big enough in order to compensate for the physical delay times within the
    network.
    Prescalar can be used to adjust Time Quantum. Time Quantum is the unit in which above timing parameters(TimeSeg1 and TimeSeg2) are expressed.

    Regards,
    Vivek Dhande.
    Texas Instruments (India) Pvt Ltd
  • Hi Vivek

    Thank you very much for your help.