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.

TM4C123GH6PM: TM4C123GH6PM

Part Number: TM4C123GH6PM


Hi,

    I'm working on tm4c123 and implementing the CAN protocol. Here i'm able to configure the gpio pins for CAN0 device. But when it is coming to initialization of CANCTL register, init bit is not getting set in the register. So controller is not moving to the next instruction. I'm using CCS 6.1.2, here is my code.

void CAN0_Init(void)
{
/* Setup the pins PB4 and PB5 of GPIO Port B for CAN0 Module */
/* PB5 = Tx, PB4 = Rx */
*SYSCTL_RCGC0 |= 0x01000000;
*SYSCTL_RCGC2 |= 0x00000002;
*GPIO_CR |= 0x30;
*GPIOB_AMSEL &= 0x00;
*GPIOB_DEN |= 0x30;
*GPIOB_DIR |= 0x20;
*GPIOB_AFSEL_PB |= 0x30;
*GPIOB_PCTL_PB = (*GPIOB_PCTL_PB & 0xFF00FFFF) + 0x00880000;

/* Initializa the CAN0 Module */
*CANCTL |= 0x01;
while(*CANIF1CRQ & 0x00008000);

/* Eanbling the loop back test mode */
*CANCTL |= 0x81; /* CAN controller is in Test Mode */
*CANTST |= 0x10;

/* Bit rate setting */
*CANCTL |= 0x40; /* Write access to the CANBIT register */
*CANBIT |= 0x0201;

/* No interrupts are used */
*CANCTL &= ~0x41; /* CAN controller is in test mode */

}

In the above code where i'm trying to write the CANCTL register, it is not getting write and moreover it is getting stuck to that point, i pointed by putting break point. Is anything wrong in the configuration of gpio pins for CAN0 module ???

I'm trying this code for loop back mode. Kindly resolve my issue

Thanks,

Venkatesh.

  • Venkatesh,

    You probably won't get any support on this forum if you use direct register programming.

    Please use TivaWare to configure your GPIO's and your CAN communication - there's a big chance that your error will magically disappear, and if it does not, people here will be able to more quickly help.

    You program would have simple things like:

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
    GPIOPinTypeCAN(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0);
    CANInit(CAN0_BASE);
    CANMessageSet(CAN0_BASE, 1, &sMsgObjectRx, MSG_OBJ_TYPE_RX);
    CANEnable(CAN0_BASE);

    See? Much easier to work with, and to debug if needed.

    You will find a detailed manual on the /docs folder of your TivaWare installation. The user guide file is SW-TM4C-DRL-UG-xxxx.pdf.

    Bruno

  • Thanks Bruno Saraiva,

    So here how to set the mode for the CAN0 module. Actually i wanted to test the CAN for Loop back mode at first time as i don't have two boards, so which API i have to use to set it to the loop back mode.

    I had gone through the stellarise library user guide, but unfortunately i did not find corresponding API to set the CAN mode. 

  • Hello!

    I haven't used CAN so I can't assure this, but I don't think CAN has TivaWare enabled loopback mode. The device's datasheet informs the relevant bit:
    "The CAN Controller is put in Loopback Mode by setting the LBACK bit in the CANTST register. "

    You could also just connect wire jumpers on your launchpad to connect different CAN modules, or maybe directly connect Tx into Rx on the same module?

    When you say Stellaris, do you mean TivaWare? The old name no longer exists, and TivaWare is currently at 2.1.4.

    Bruno
  • Hi,

    Yes exactly, i'm using TivaWare 2.1.4.178 and 2.1.0.12573. So as i know i can test the Loop back mode by setting LBACK bit in CANTST, But i'm not finding the corresponding API to set that LBACK bit. If any help could appreciate.

    Thanks,
    Venkatesh