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.

Configure Tiva C CAN

Other Parts Discussed in Thread: TM4C1230C3PM

Hello, Dear. Support.

I programmed CAN interface with TivaWare 1.1 on TM4C1230C3PM.

I initialize and configured CAN to 500Kbps and communication test was successful.

however, It was not worked at 1Mbps.

The processor has running without errors, but CAN signal is not generated properly.

I can't find my fault, and I don't know what was wrong.

Here's my C code..

// PIOSC, 80MHz
ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_INT |
SYSCTL_MAIN_OSC_DIS);

...

// CAN Init

ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE)
ROM_GPIOPinConfigure(GPIO_PE4_CAN0RX);
ROM_GPIOPinConfigure(GPIO_PE5_CAN0TX);
ROM_GPIOPinTypeCAN(GPIO_PORTE_BASE, GPIO_PIN_4 | GPIO_PIN_5);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0);
ROM_CANInit(CAN0_BASE);
ROM_CANBitRateSet(CAN0_BASE, SysCtlClockGet(), 1000000); // It worked 500kbps with no problem
CANIntRegister(CAN0_BASE, CANIntHandler); 
ROM_CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS); 
ROM_IntEnable(INT_CAN0); 
CANEnable(CAN0_BASE); 

...

There are something to do before call CANBitRateSet() ??

I tested same code to LM3S9B96 custom board with StellarisWare v9453, it also worked at 500kbps, not 1Mbps.

and I tied call CANBitTimingSet() instead of ROM_CANBitRateSet().

tCANBitClkParms tCANClkParams;

// bitrate = CAN Clock / ((ui32SyncPropPhase1Seg + ui32Phase2Seg + 1) * (ui32QuantumPrescaler))
// @80MHz, 500kbps = 4 / 3 / 0 / 20
tCANClkParams.ui32SyncPropPhase1Seg = 4;
tCANClkParams.ui32Phase2Seg = 3;
tCANClkParams.ui32SJW = 1;
tCANClkParams.ui32QuantumPrescaler = 20;
ROM_CANBitTimingSet(CAN0_BASE, &tCANClkParams);

however, did not work following code.

// @80MHz, 1000kbps = 4 / 3 / 0 / 10
tCANClkParams.ui32SyncPropPhase1Seg = 4;
tCANClkParams.ui32Phase2Seg = 3; 
tCANClkParams.ui32SJW = 1;
tCANClkParams.ui32QuantumPrescaler = 10;
ROM_CANBitTimingSet(CAN0_BASE, &tCANClkParams);

I changed clock to 6Mhz XTAL, or PLL, however It has same symptoms.

My targetboard communicated with the LAWICEL CANUSB device,

CANUSB  has been operated well 1Mbps with another microprocessor (Nuvoton NuMicro series)

I need your help.

Thanks.

Regards. Hyunkyo Oh.

  • HyeonKyo,

    On one of our kits, these settings work for 1Mbps when used with a system clock of 16MHz:

    tCANClkParams.ui32SyncPropPhase1Seg = 5;
    tCANClkParams.ui32Phase2Seg = 5;
    tCANClkParams.ui32SJW = 2;
    tCANClkParams.ui32QuantumPrescaler = 2;

    Try these and see if they work for you.

  • Dear, John.

    Thanks for your reply and concern.

    I found a way to solve that is add a terminate resistance to my circuit.

    By put a 220ohm beetween CAN_H and CAN_L the matter was fixed cleanly.

    there is no problem in source code.

    Thank you once again for your support.

  • Glad to hear of your success. 

    Is not 120 ohm the more, "normal/customary" termination value for a CAN "end" device?

    At that speed one should pay attention to CAN transceiver's spec & the length of CAN bus signal traces (CAN+ & CAN-) should be closely matched... 

    In our experience 500K is more, "forgiving" (thus more robust) - and enables greater transmission distance as well...