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.

LM4F230 CAN Setting

Other Parts Discussed in Thread: EK-LM3S2965, LM3S2965

I am attempting to configure a CAN . I want to making a code like the following: Into the loop, continue to send a CAN Message.

When my code run ,it reaches the CAN interrupt handler.

But,  go to default: only, because I checked resister value.  As a result 0x40040004 000000E5.

This  represents the bit 0 error. I do not know why this result.

Please help me.Thank you

Code1

void CANHandler(void)
{
    unsigned long ulStatus;

    ulStatus = CANIntStatus(CAN0_BASE, CAN_INT_STS_CAUSE);

    CANStatusGet(CAN0_BASE, CAN_STS_CONTROL);
    switch(ulStatus)
    {
    case 10:
    {
         g_ulFlags &= (~FLAG_BUTTON_PEND );

        break;
    }

    default:
    {
        CANStatusGet(CAN0_BASE, CAN_STS_CONTROL);
        return;
    }
}
CANIntClear(CAN0_BASE, ulStatus);
}

Code2

void main(void)
{
    unsigned char EVENT_BUTTON_PRESS,TARGET_BUTTON_UP;

    SysCtlClockSet(SYSCTL_USE_OSC | SYSCTL_OSC_INT);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    GPIOPinConfigure(GPIO_PE4_CAN0RX);
    GPIOPinConfigure(GPIO_PE5_CAN0TX);

    GPIOPinTypeCAN(GPIO_PORTE_BASE, GPIO_PIN_4 | GPIO_PIN_5);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0);           

        CANInit(CAN0_BASE);                                       
        CANBitRateSet(CAN0_BASE, SysCtlClockGet(), 1000000);  
        CANEnable(CAN0_BASE);                                      

        CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR);   


        /* ================================================================== */
        /* =    config message object                                               = */
        /* ================================================================== */

        g_MsgObjectButton.ulMsgID = 0x0;
        g_MsgObjectButton.ulMsgIDMask = 0;
        g_MsgObjectButton.ulFlags = MSG_OBJ_TX_INT_ENABLE;
        g_MsgObjectButton.ulMsgLen = 2;
        g_MsgObjectButton.pucMsgData = g_pucButtonMsg;

        IntEnable(INT_CAN0);

    while(1)                                           
    {
        SendButtonMsg(EVENT_BUTTON_PRESS, TARGET_BUTTON_UP);
    }
}

Code3

void SendButtonMsg(unsigned char ucEvent, unsigned char ucButton)
{
    //
    // Set the flag to indicate that a button status is being sent.
    //
    g_ulFlags |= FLAG_BUTTON_PEND;

    //
    // Send the button status.
    //
    g_MsgObjectButton.pucMsgData[0] = 0x1;
    g_MsgObjectButton.pucMsgData[1] = 0x2;

    CANMessageSet(CAN0_BASE, 10, &g_MsgObjectButton,
                  MSG_OBJ_TYPE_TX);
}

  •  

    Yuichi,

    I believe your issue is that you are falling into a hard fault. 

    Change your API, SysCtlClockSet(SYSCTL_USE_OSC | SYSCTL_OSC_INT); to SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_INT);

    What button/GPIO are you using for SendButtonMsg(EVENT_BUTTON_PRESS, TARGET_BUTTON_UP);?  Where is the SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIO?); for the GPIO?

    Lela

  • Hi, Lela

    I tried changing ,SysCtlClockSet(SYSCTL_USE_OSC | SYSCTL_OSC_INT); to SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_INT);.

    But,  go to default: only, and 0x40040004 000000E5.

    By any chance, do I need external clock for input to LM4F230? For a CAN.

    For your informatio.

    Pin connect.


    declaration

    #define FLAG_BUTTON_PEND         0x00000200

    tCANMsgObject g_MsgObjectButton;
    unsigned char g_pucButtonMsg[2];
    volatile unsigned long g_ulFlags;  
    void SendButtonMsg(unsigned char , unsigned char);


    > What button/GPIO are you using for SendButtonMsg(EVENT_BUTTON_PRESS, TARGET_BUTTON_UP);? 

    I copyed SendButtonMsg(EVENT_BUTTON_PRESS, TARGET_BUTTON_UP); from the sample code.(ek-lm3s2965\can_device_qs)

  • Yuichi Sone said:
    do I need external clock for input

    I went to the operating & electrical specs of 4F datasheet - clock spec for USB, ADC several others listed - could find none for CAN.  (but cannot hurt for you to try using external osc/xtal)

    Note that you've used sample code for the older, less sophisticated LM3S2965 MCU.  The new M4 parts frequently require more "set-up" and configuration/pin-typing than older devices.  Have you done this?  In our M4F (64 pin version) the CAN bus is shared with UART - we must both pinconfigure and pintype - along with other necessary GPIO configurations.  Datasheet is quite good @ detailing - if you have not done this - then such set-up/config is very fertile ground for your review...

  •   Hi,

        SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_INT);

        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
        GPIOPinConfigure(GPIO_PE4_CAN0RX);
        GPIOPinConfigure(GPIO_PE5_CAN0TX);
        GPIOPinTypeCAN(GPIO_PORTE_BASE, GPIO_PIN_4 | GPIO_PIN_5);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0);  

        CANInit(CAN0_BASE);                                       
        CANBitRateSet(CAN0_BASE, SysCtlClockGet(), 1000000);  
        CANEnable(CAN0_BASE);