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/TM4C1294NCPDT: TM4C

Part Number: TM4C1294NCPDT

Tool/software: Code Composer Studio

Hi All,

I am using TM4C1294NCPDT micro controller for my new development, In this I am using timer, I2C, UART and other peripheral's well.

Now I want to CAN module  establishment communication with my salve board, for this I try to use CAN0 module with PA0, PA1.

I am new to CAN module one.

I wrote code with example studied in online. I think the data transmission not working properly.

Screen shots attached below and I pasted my code below. Interrupt handler working fine I think

unsigned char can_tx_buff[100];

int main(void)

{

SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

GPIOPinConfigure(GPIO_PA0_CAN0RX);

GPIOPinConfigure(GPIO_PA1_CAN0TX);

GPIOPinTypeCAN(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0);

CANInit(CAN0_BASE);

CANBitRateSet(CAN0_BASE, SysCtlClockGet(), 500000);

CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS);

IntEnable(INT_CAN0);

CANEnable(CAN0_BASE);

tCANMsgObject sCANMessage;

uint8_t *pui8MsgData;

can_tx_buff[0] = 11;

can_tx_buff[1] = 0x0f;

can_tx_buff[2] = 0;

can_tx_buff[3] = 0;

can_tx_buff[4] = 0;

can_tx_buff[5] = 0;

can_tx_buff[6] = 0;

can_tx_buff[7] = 1;

pui8MsgData = (uint8_t *)&can_tx_buff;

while(1)

{

sCANMessage.ui32MsgID = 1;

sCANMessage.ui32MsgIDMask = 0;

sCANMessage.ui32Flags = MSG_OBJ_TX_INT_ENABLE;

sCANMessage.ui32MsgLen = 8;

sCANMessage.pui8MsgData = pui8MsgData;

set.Spindle_Operating_Mode = 1;

/*machine Sequence*/

if(set.Spindle_Operating_Mode == 0)

{

//check_all_moto_stat();

//process_manual_oper();

CANMessageSet(CAN0_BASE, 1, &sCANMessage, MSG_OBJ_TYPE_TX);

}

// Now wait 1 second before continuing

SimpleDelay();

}

}

 

//*****************************************************************************

void CANIntHandler(void)

{

uint32_t ui32Status;

// Read the CAN interrupt status to find the cause of the interrupt

ui32Status = CANIntStatus(CAN0_BASE, CAN_INT_STS_CAUSE);

if(ui32Status == CAN_INT_INTID_STATUS)

{

ui32Status = CANStatusGet(CAN0_BASE, CAN_STS_CONTROL);

}

else if(ui32Status == 1)

{

CANIntClear(CAN0_BASE, 1);

}

else

{

// Spurious interrupt handling can go here.

}

}

Regards

Yuvaraj

  • Yuva raj said:
    I wrote code with example studied in online. I think the data transmission not working properly.

    Not sure which online example you refer to. There is CAN example in TivaWare. Please go to <TivaWare_Installation>\examples\peripherals\can where several examples are provided. 

    When you said the transmission is not working, can you be specific? How did you setup the CAN bus? Do you have transceiver on the bus for each node. Do you have proper termination resistors on the bus. 

    Another question is if you are using the LaunchPad or this is your custom board? If you are using the LaunchPad then you need to change the jumper settings on JP4 and JP5 in order to bring the CAN signals to the boosterpack X6 connector. 

  • Hi Charles,

    Check my attached screen shot, In that CAN error status shows Bus off status, Warning status, Error passive bits are set while I am view register window in CCS7.2. Why these error bits are set...??

    Regards
    Yuvaraj
  • Hi Yuva,

    If you get a bus off it means the transmitter error counter value is higher than 255. Please refer to the CAN protocol. Normally the recovery mechanism from bus-off is to reset the CAN node. I asked you how you set up the CAN bus and if you have transceiver and proper termination resistors on the bus but you didn't reply me. How many nodes do you have on bus? Are you getting acknowledged from any receivers on the bus? These are the questions to answer that will help debug the problem. Please also use the scope to monitor the CAN bus and TX/RX pin from your transmitter.

    Since you said you are new to CAN, I will suggest you start with the TivaWare CAN examples. Please refer to the examples in <TivaWare_Installation>\examples\peripherals\can