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.

Using CAN with an internal oscillator

Other Parts Discussed in Thread: TM4C1231D5PM, TM4C123BE6PZ

We have several implementations of CAN using an external oscilator that are working admirably.  I am now trying to enable a CAN peripheral on a device that has not external oscillator. 

I am using simpletx.c as a baseline.  I have removed the UART code, as I have no UART, changed the CAN pins to the ones I use, disabled the NMI pin collision and moved to the baud rate I need: 250K.

I view the external CAN bus and there is definately many well organized bits on the bus.  But my bus immediately goes into passive error.

I am looking at the bus and I am not sure what a bit stream should look like, but a rough calculation indicates that I have the wrong baud rate.

Is there an example of using the CAN peripheral with the internal clock?

What do you look at on the CAN bus to verify baud rate?  The shortes'bit' looks like about 1msec, which is about 1Kbaud.

I looked at a CAN bus running 250kbaud and what I call a 'bit' is 4usec wide, as expected.  So I think by using the clock setup as I have it is running the CAN bus at 1kbaud.

I am using :

SysCtlClockSet(SYSCTL_OSC_INT | SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL);
CANBitRateSet(CAN0_BASE, SysCtlClockGet(), 250000);

SysCtlClockGet returns 37,500

  • The CAN controller uses the system clock so it should work fine even with the internal oscillator as the source, as long as the processor speed is high enough to support the request bit rate.

    The fact that SysCtlClockGet() is returning is not correct you shoeld get 20MHz with those settings.  That is probably why your bit rate is off.

    What Tiva device are you using?

  • I figured it out.  I am using a TM4C1231D5PM (probably does not matter) and TivaWare 1.0.

    I changed the calls to SysCtlClockSet and Get to the ROM_versions, and all is well.

    The TivaWare UG states that:


    Note:
    This cannot return accurate results if SysCtlClockSet() has not been called to configure the
    clocking of the device, or if the device is directly clocked from a crystal (or a clock source)
    that is not one of the supported crystal frequencies. In the latter case, this function should be
    modified to directly return the correct system clock rate.


    Not sure who or how "this function should be modified" happens. 

    Details:

        SysCtlClockSet(SYSCTL_OSC_INT | SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL);
        sysCtlClock = SysCtlClockGet();  // returns 37,500 .... WRONG
    
        ROM_SysCtlClockSet(SYSCTL_OSC_INT | SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL);
        sysCtlClock = ROM_SysCtlClockGet();  // Returns 20,000,000 .... CORRECT
    
        SysCtlClockSet(SYSCTL_OSC_INT | SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL);
        sysCtlClock = ROM_SysCtlClockGet();  // Returns 20,000,000 .... CORRECT
    
        ROM_SysCtlClockSet(SYSCTL_OSC_INT | SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL);
        sysCtlClock = SysCtlClockGet();  // returns 37,500 .... WRONG
    

    So in this case, you need to run ROM_SysCtlClockGet.  Which is puzzling, because on the TM4C123BE6PZ I could not use ROM_SysCtlClockSet to configure an 80Mhz clock as it did not support the SYSCT_SYSDIV_2_5 option.

     

  • There was a bug fix to the SysCtlClockGet() function that is probably the culprit here.  We are currently on version 2.0.1.11577 of TivaWare which includes the fix to this function. If you get the latest and see if it works for you or if you are fine using the ROM version you should be fine.  Here is a link to the release notes for the newer release to see if there is anything else that would help. 

    http://software-dl.ti.com/tiva-c/SW-TM4C/latest/exports/SW-TM4C-RLN-2.0.1.11577.pdf