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/TM4C1294KCPDT: CAN_Tx_Configuration

Part Number: TM4C1294KCPDT


Tool/software: Code Composer Studio

I have add the sample (simple_tx code for CAN data tx) code in my source code and run the code. This has executed and run successfully but only error interrupt has been generating. I have made some changes in the configuration, but not get result. Can you explain how to configure CAN communication module.  

I have attached my code below,

void CANIntHandler()
{
uint32_t ui32Status;

ui32Status = CANIntStatus(CAN0_BASE, CAN_INT_STS_CAUSE);

if(ui32Status == CAN_INT_INTID_STATUS)
{
ui32Status = CANStatusGet(CAN0_BASE, CAN_STS_CONTROL);
Send_String("Error Interrupt\n");
g_bErrFlag = 1;
// g_ui32MsgCount++;
}

else if(ui32Status == 1)
{
Send_String("TX Interrupt\n");
CANIntClear(CAN0_BASE, 1);

g_ui32MsgCount++;

g_bErrFlag = 0;
}

else
{
Send_String("Unexpected Interrupt\n");
}
}

void UART_Init(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART5);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE,GPIO_PIN_5);
GPIOPinWrite(GPIO_PORTC_BASE,GPIO_PIN_5, 0);//RX enable

GPIOPinConfigure(GPIO_PC6_U5RX);
GPIOPinConfigure(GPIO_PC7_U5TX);
GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_6 | GPIO_PIN_7);

UARTConfigSetExpClk(UART5_BASE, g_ui32SysClock, 19200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));

IntEnable(INT_UART5);
// UARTIntEnable(UART5_BASE,UART_INT_RX | UART_INT_RT);
IntMasterEnable();
}


int main(void)
{
g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_20MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 120000000);
tCANMsgObject sCANMessage;
UART_Init();

uint32_t ui32MsgData;
uint8_t *pui8MsgData;

pui8MsgData = (uint8_t *)&ui32MsgData;

SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

GPIOPinConfigure(GPIO_PA0_CAN0RX);
GPIOPinConfigure(GPIO_PA1_CAN0TX);

GPIOPinTypeCAN(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

CANInit(CAN0_BASE);

CANBitRateSet(CAN0_BASE, g_ui32SysClock, 500000);

CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS);

IntEnable(INT_CAN0);

CANEnable(CAN0_BASE);

ui32MsgData = 0;
sCANMessage.ui32MsgID = 1;
sCANMessage.ui32MsgIDMask = 0;
sCANMessage.ui32Flags = MSG_OBJ_TX_INT_ENABLE;
sCANMessage.ui32MsgLen = sizeof(pui8MsgData);
sCANMessage.pui8MsgData = pui8MsgData;

TX
while(1)
{
Send_String("SANKAR");
// SysCtlDelay(g_ui32SysClock/2);

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

SysCtlDelay(g_ui32SysClock/2);

if(g_bErrFlag)
{
// g_bErrFlag = 0;
Send_String(" error - cable connected?\n");
}
else
{
String_To_Int(g_ui32MsgCount);
Send_String(" total count = ");
Send_String(Data_Buffer);
Send_String(" \n");
}

ui32MsgData++;

if(CANStatusGet(CAN0_BASE, CAN_STS_CONTROL) & CAN_STATUS_BUS_OFF)
{
Send_String(" entered into this condition\n");
CANEnable(CAN0_BASE);
// SysCtlDelay(g_ui32SysClock/2);

while(CANStatusGet(CAN0_BASE, CAN_STS_CONTROL) & CAN_STATUS_BUS_OFF);
}

}
}