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.

CCS/TM4C123GH6PM: CCS/TM4C123GH6PM

Part Number: TM4C123GH6PM

Tool/software: Code Composer Studio

Hello!

I try to send can message from my TM4C microcontroler to NI can, but I can't receive can messages on NI can. Here is my program:

#include <stdbool.h>

#include <stdint.h>

#include "inc/hw_ints.h"

#include "inc/hw_memmap.h"

#include "inc/hw_types.h"

#include "driverlib/sysctl.h"

#include "driverlib/can.h"

#include "driverlib/gpio.h"

#include "driverlib/pin_map.h"

int main(void)

{

tCANMsgObject sMsgObjectTx;

uint8_t pui8BufferOut[8];

uint32_t ui32SysClock=SysCtlClockGet();

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

//pin f3 config

    GPIOPinConfigure(GPIO_PF3_CAN0TX);

    GPIOPinTypeCAN(GPIO_PORTF_BASE, GPIO_PIN_3);

//pin f0 config

    GPIOPinConfigure(GPIO_PF0_CAN0RX);

    GPIOPinTypeCAN(GPIO_PORTF_BASE, GPIO_PIN_0);

//

// Enable the CAN0 module.

//

SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0);

//

// Wait for the CAN0 module to be ready.

//

while(!SysCtlPeripheralReady(SYSCTL_PERIPH_CAN0))

{

}

//

// Enable the CAN1 module.

//

SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN1);

//

// Wait for the CAN1 module to be ready.

//

while(!SysCtlPeripheralReady(SYSCTL_PERIPH_CAN1))

{

}

//

// Reset the state of all the message objects and the state of the CAN

// module to a known state.

//

CANInit(CAN0_BASE);

CANInit(CAN1_BASE);

//

// Configure the controller for 1 Mbit operation.

//

CANBitRateSet(CAN0_BASE, ui32SysClock, 1000000);

CANBitRateSet(CAN1_BASE, ui32SysClock, 1000000);

//

// Take the CAN0 and CAN1 device out of INIT state.

//

CANEnable(CAN0_BASE);

CANEnable(CAN1_BASE);

//

// Configure a receive object.

//

while(1)

{

sMsgObjectTx.ui32MsgID = 0x400;

sMsgObjectTx.ui32Flags = 0;

sMsgObjectTx.ui32MsgLen = 1;

sMsgObjectTx.pui8MsgData = pui8BufferOut;

CANMessageSet(CAN0_BASE, 2u, &sMsgObjectTx, MSG_OBJ_TYPE_TX);

}

}

And my settings in NI can:

What can be the problem?

Best Regards,

Gondos Andor

#include <stdbool.h>#include <stdint.h>#include "inc/hw_ints.h"#include "inc/hw_memmap.h"#include "inc/hw_types.h"#include "driverlib/sysctl.h"#include "driverlib/can.h"#include "driverlib/gpio.h"#include "driverlib/pin_map.h"


int main(void){//tCANMsgObject sMsgObjectRx;tCANMsgObject sMsgObjectTx;//uint8_t pui8BufferIn[8];uint8_t pui8BufferOut[8];uint32_t ui32SysClock=SysCtlClockGet();
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
//pin f3 config    GPIOPinConfigure(GPIO_PF3_CAN0TX);    GPIOPinTypeCAN(GPIO_PORTF_BASE, GPIO_PIN_3);//pin f0 config    GPIOPinConfigure(GPIO_PF0_CAN0RX);    GPIOPinTypeCAN(GPIO_PORTF_BASE, GPIO_PIN_0);
//// Enable the CAN0 module.//SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0);//// Wait for the CAN0 module to be ready.//while(!SysCtlPeripheralReady(SYSCTL_PERIPH_CAN0)){}//// Enable the CAN1 module.//SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN1);//// Wait for the CAN1 module to be ready.//while(!SysCtlPeripheralReady(SYSCTL_PERIPH_CAN1)){}//// Reset the state of all the message objects and the state of the CAN// module to a known state.//CANInit(CAN0_BASE);CANInit(CAN1_BASE);//// Configure the controller for 1 Mbit operation.//CANBitRateSet(CAN0_BASE, ui32SysClock, 1000000);CANBitRateSet(CAN1_BASE, ui32SysClock, 1000000);//// Take the CAN0 and CAN1 device out of INIT state.//CANEnable(CAN0_BASE);CANEnable(CAN1_BASE);//// Configure a receive object.///*sMsgObjectRx.ui32MsgID = 0x400;sMsgObjectRx.ui32MsgIDMask = 0x7f8u;sMsgObjectRx.ui32Flags = MSG_OBJ_USE_ID_FILTER;sMsgObjectRx.pui8MsgData = pui8BufferIn;CANMessageSet(CAN1_BASE, 4u, &sMsgObjectRx, MSG_OBJ_TYPE_RX);*///// Configure and start transmit of message object.//while(1){sMsgObjectTx.ui32MsgID = 0x400;sMsgObjectTx.ui32Flags = 0;sMsgObjectTx.ui32MsgLen = 1;sMsgObjectTx.pui8MsgData = pui8BufferOut;CANMessageSet(CAN0_BASE, 2u, &sMsgObjectTx, MSG_OBJ_TYPE_TX);}//// Wait for new data to become available by checking bit 4 (0x08u).///*while((CANStatusGet(CAN1_BASE, CAN_STS_NEWDAT) & 0x08u) == 0u){}//// Read the message out of the message object 4.//CANMessageGet(CAN1_BASE, 4u, &sMsgObjectRx, true);//// Process new data in sMsgObjectRx.pucMsgData.// * */
}

  • Hi,

      The code you paste at the bottom of the post is totally unreadable. To paste code, you should click the below icon.

      Attached you will find two ready to run CAN example, one for TX and another for RX. I will suggest you reference these two examples to develop your application.

    tm4c123 can examples.zip

  • Than you!

    When I try simple TX program, then i get this:

    Regards,

    Andor

  • Did you import the project in the CCS from "File" -> "Import"? Can you compile the project?

  • No I imported from "Project"->"Import CCS projects". 

    Yes I can. 


    Regards,

    Andor

  • What do you mean you import from "Project"? There is no "Import" under the "Project". 

    Below is what I meant to "File"->"Import" the project.

    In any case, you seem to import the project and compile it fine. 

    This project uses the UARTprintf to output the status of the operations. You need to open a virtual COM port to view the status. You should see something like below in your terminal window. 

    If you look at the code I think you are in the SimpleDelay as shown on your disassembly window. The code for the can_simple_tx is supposed to keep sending data on the CAN bus every second. If it is not sending continuously then it means that the receiver is not acknowledging the data. You need to check if you receiver is setup on the network. If the transmitter is not successful sending the data (see theCANStatusGet), then it just got stuck. 

        while(1)
        {
            //
            // Print a message to the console showing the message count and the
            // contents of the message being sent.
            //
            // Check to see if previous message was already sent
            if((CANStatusGet(CAN0_BASE, CAN_STS_TXREQUEST) & 1) == 0)
            {
                UARTprintf("Sending msg: 0x%02X %02X %02X %02X",
                           pui8MsgData[0], pui8MsgData[1], pui8MsgData[2],
                           pui8MsgData[3]);
    
                //
                // Send the CAN message using object number 1 (not the same thing as
                // CAN ID, which is also 1 in this example).  This function will cause
                // the message to be transmitted right away.
                //
                CANMessageSet(CAN0_BASE, 1, &sCANMessage, MSG_OBJ_TYPE_TX);
                //
                // Check the error flag to see if errors occurred
                //
                if(g_bErrFlag)
                {
                    UARTprintf(" error - cable connected?\n");
                }
                else
                {
                    //
                    // If no errors then print the count of message sent
                    //
                    UARTprintf(" total count = %u\n", g_ui32MsgCount);
                }
    
                //
                // Increment the value in the message data.
                //
                ui32MsgData++;
            }
    
            //
            // Now wait 1 second before continuing
            //
            SimpleDelay();

  • Whwn I take out the SimpleDelay() function, then it works fine, but I can't  see the UARTprintf. My virtual COM port settings:

    Best Regards,

    Andor

  • You need to go to your Windows device manager to find out which COM port is mapped to the UART. You can't just use COM6. The COM6 is the one that is enumerated on my PC, not yours. Make sure you have the correct baud rate, parity and stop bits on your terminal that is matching which the UART which is 115200-N-1.