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 interrupt handling

Other Parts Discussed in Thread: TM4C123GH6PM, EK-TM4C123GXL

i am using TM4C123GH6PM  microcontroller.     lauchpad (TM4C123GXL).

i am trying to transmit the data from CAN to CAN. in our project board1 TO  board 2 .

i am using CAN0 . using pins ...transmit (PE5 ), receive (PE4 ).

for transmit i am using the polling mechanism. and for receiving i am using the interrupt handling mechanism.

now i am facing one problem.

when i am trying to transmit the data from board1 (CAN) to board 2 (CAN) , at first time receiving flag is rised, and from the  CAN CONTROL REGISTER -(CAN_CTL_INIT ) bit is also rised.  the CAN CONTROL REGISTER get the value as E4.

for the second time transmit the data from board1 (CAN) to board 2(CAN) , then the error flag is gererated. the receive interrupt is not generated .

why its going to the error mode for the second time.

for reference i am attaching my CAN file.can_tx_rx.h

/****************************************************************************
 * FILE: Can_tx_rx.c
 ****************************************************************************
 * Copyright 2012 Testamatic Systems, Inc., All Rights Reserved.
 * Testamatic System Confidential
 ****************************************************************************
 * DESCRIPTION: This is Wifi_uart file for this project.
 *
 * ABBREVIATIONS: None
 *
 * TRACEABILITY INFO:
 *   Design Document(s):
 *   Requirements Document(s):
 *
 * DEVIATIONS FROM STANDARDS:None
*****************************************************************************/

/********************************************************************************
    Include files
*******************************************************************************/
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include "inc/tm4c1231h6pm.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "driverlib/sysctl.h"
#include "driverlib/can.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom_map.h"
#include "driverlib/uart.h"
#include "can_tx_rx.h"
#include "bluetooth_uart.h"
#include "Eeprom_Emulation.h"
#include "Wifi_uart.h"
	
/*****************************************************************************
 * Macros 
 ****************************************************************************/


	
/*****************************************************************************
 * Global Variables 
 ****************************************************************************/
uint8_t pui8BufferOut[8] = {0x61,0x72,0x75,0x6E,0x00,0x00,0x00,0x00};       
uint8_t pui8MsgData[8];
uint8_t eeprombuffer[14];            //  EEPROM data buffer
uint32_t g_ui32MsgCount_Tx = 0 ;     // transmitting message counter
uint32_t g_ui32MsgCount_Rx = 0;      // receving message counter

volatile bool g_bErrFlag ;
 volatile bool g_bRXFlag2 ;
struct eeprom_data data;

tCANMsgObject sMsgObjectTx,sMsgObjectRx,sMsgObjectTx1;
tCANBitClkParms GetBittime;

//*****************************************************************************
// This function is for making delay(in ms).
//*****************************************************************************
void Can_Re_Init(void)
{
		CANDisable(CAN0_BASE);
	// initialize the CAN0
	CANInit(CAN0_BASE);

	can_info();
	
	IntEnable(INT_CAN0);			

	// enable the interrupt on the CAN peripheral	
	CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS);
	// enable the 
	CANEnable(CAN0_BASE);
}
//*****************************************************************************
// This function is for making delay(in ms).
//*****************************************************************************
void can_info(void)
{
	// initialize the CAN0
	//CANInit(CAN0_BASE);

	
	// assigning the CAN bit timing structure values for CAN transmit and receive
	GetBittime.ui32SyncPropPhase1Seg=8;
	GetBittime.ui32Phase2Seg=7;
	GetBittime.ui32SJW=4;
	GetBittime.ui32QuantumPrescaler=10;	

	// set that assigning values to that CAN		
	CANBitTimingSet(CAN0_BASE, &GetBittime);

	//  initialize the CAN message object structure members fot transmitting the data
	sMsgObjectTx.ui32MsgID = 0x400;
	sMsgObjectTx.ui32Flags = 0;
	sMsgObjectTx.ui32Flags = MSG_OBJ_TX_INT_ENABLE;
	sMsgObjectTx.pui8MsgData = pui8BufferOut;
	sMsgObjectTx.ui32MsgLen = 8;


	// assign the CAN message object structure members for receving the data
	sMsgObjectRx.ui32MsgID =  0X101 ;
	sMsgObjectRx.ui32MsgIDMask = 0Xffff;
	sMsgObjectRx.ui32Flags = (MSG_OBJ_RX_INT_ENABLE | MSG_OBJ_USE_ID_FILTER | MSG_OBJ_EXTENDED_ID );
	sMsgObjectRx.ui32MsgLen = 8;

	//  set the messgae object 2 for receving the data 
	CANMessageSet(CAN0_BASE, 2, &sMsgObjectRx, MSG_OBJ_TYPE_RX);	
}

//*****************************************************************************
// This function is for making delay(in ms).
//*****************************************************************************
void CAN_Config(void)
{
	// enable the PORT-E for CAN TX & RX 
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);    // enable the PORTE


	GPIOPinConfigure(GPIO_PE4_CAN0RX);     // configure the PE4 for CAN receiving function
	GPIOPinConfigure(GPIO_PE5_CAN0TX);     // configure the PE5 for CAN transmitting function
	
	
	GPIOPinTypeCAN(GPIO_PORTE_BASE, GPIO_PIN_4 | GPIO_PIN_5);   // enable the pin types for CAN
  SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0);
	
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
	GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0);
	GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, 0);               //  FOR CAN STB
	  
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);	
	GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_4);
	GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_4, 0);               // FOR CAN shutdown
	
	// The GPIO port and pins have been set up for CAN.  The CAN peripheral
	// must be enabled.	

	
	//	CANDisable(CAN0_BASE);
	// initialize the CAN0
	//CANInit(CAN0_BASE);

	can_info();
	
	IntEnable(INT_CAN0);			

	// enable the interrupt on the CAN peripheral	
	CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS);
	// enable the 
	CANEnable(CAN0_BASE);

}


//*****************************************************************************
// This function is for making delay(in ms).
//*****************************************************************************
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 the cause is a controller status interrupt, then get the status
    
	   if(ui32Status == CAN_INT_INTID_STATUS)
     {
        
				// Read the controller status
        ui32Status = CANStatusGet(CAN0_BASE, CAN_STS_CONTROL); 
			 
				CANIntClear(CAN0_BASE, CAN_INT_INTID_STATUS);
			  // set the error flag
        g_bErrFlag = 1;
			 
     } 

    // Check if the cause is message object 1, which what we are using for
    // sending messages.
			
     else if(ui32Status == 1)
     {
	      //-----------Transmit Interrupt-----------//
        // If this condition is true, then the TX interrupt occurred on
        // message object 1, and the message TX is complete.  Clear the
        // message object interrupt.
				
        CANIntClear(CAN0_BASE, 1);

        g_ui32MsgCount_Tx++;

			  // clear the error flag
        g_bErrFlag = 0;

		 }
			
	   else if(ui32Status == 2)
	   {
	  
			 //-------------Receive Interrupt-----------//
			   //  If this condition is true, then the RX interrupt occurred on
        // message object 2, and the message RX is complete.  Clear the
        // message object interrupt.
	  
        CANIntClear(CAN0_BASE, 2);
       
        // g_ui32MsgCount_Rx++;
       
			 // Set flag to indicate received message is pending.
        
			  g_bRXFlag2 = 1;
        
       // clear the error flag 
			  g_bErrFlag = 0;
	   }

    else
    {
       
    }
}

//*****************************************************************************
// This function is for making delay(in ms).
//*****************************************************************************
// what ever the data is received check that data is in proper formate, 
// if its in the proper frame formate means put the data  in the CAN buffer

void can_frame(void)
{

		if (BT_CAN_Tx_Req_Status())
		{
			can_transmit();
			BT_Clr_CAN_Tx_Req_Flg();
		}			
			
		else if (WIFI_CAN_Tx_Req_Status())
		{
			can_transmit();
			WIFI_Clr_CAN_Tx_Req_Flg();
		}
		else
		{
			/* DO transmits */	
		}
			
//		//	if((WIFI_Rx_Buff[9]==0xA5) && (	WIFI_Rx_Buff[10]==0x5A) && (	WIFI_Rx_Buff[11]==0xFE))
//		//	{
// 		
//       //  if the frame is proper format means enter into the condition	
//				
//				int j=0,k=10;
//				for(int i=0; i<	9 ;i++)
//					{
//								
//							// if((	WIFI_Rx_Buff[k]!=0x5A) && (	WIFI_Rx_Buff[k+1]!=0xA5))   // check for the stop bit
//							// {		 
//								 pui8BufferOut[j++] = 	WIFI_Rx_Buff[k++];
//							// } 
//				  }
//					
//					 can_transmit();
//		//	}
//			
			
			
	    //  if the data is not in the proper frame format means put that data with its details in EEPROM
			 
//			else if((BT_Rx_Buff[0]==0xA5) && (BT_Rx_Buff[1]==0x5A) && (BT_Rx_Buff[2]==0xFF))   // check the frame formate
//			{	
//   				
//		           // put zero in the  eeprom buffer		
//				
//				memset((uint8_t*)eeprombuffer,0,strlen((const char *)eeprombuffer));
//				
//				 int x=0,y=4;
//									
//				 for(int z=0; z<BT_Rx_Buff[3] ;z++)
//					{
//						 if((BT_Rx_Buff[y]!=0x5A) && (BT_Rx_Buff[y+1]!=0xA5))   // checking for the stop bit of the frame
//							{								
//								 eeprombuffer[x++] = BT_Rx_Buff[y++];                 // put the each and every data to the eeprom buffer
//							}
//					}
//								
//				  // BT_Msg_Send(eeprombuffer,strlen(eeprombuffer));					 // for checking purpose  (eeprombuffer)
//									 
//			  	memcpy(&data,eeprombuffer,sizeof(eeprombuffer));

//	       // initialize the EEPROM				
//					
//					EEPROM_Init();
//						 
//			 }
	
}
//*****************************************************************************
// This function is for making delay(in ms).
//*****************************************************************************
// Send message 1 using CAN controller message object 1.  This is
// the only message sent using this message object.  The
// CANMessageSet() function will cause the message to be sent right
// away.

void can_transmit(void)
 {
				
	 // transmite the data through the CAN msg object
	 
	 CANMessageSet(CAN0_BASE, 1, &sMsgObjectTx, MSG_OBJ_TYPE_TX);
	 
 }
			

		    // If the flag for message object 1 is set, that means that the RX
        // interrupt occurred and there is a message ready to be read from
        // this CAN message object.	

//void can_recevie(void)
//{
//        //	put the data from the TX message object buffer to the RX message object buffer
//	
//				 sMsgObjectRx.pui8MsgData = pui8MsgData;   
//					 
//				 WIFISend(sMsgObjectRx.pui8MsgData,strlen((const char *)sMsgObjectRx.pui8MsgData));
//				
//	       //  read the message object from the CAN      
//	
//	  	  	CANMessageGet(CAN0_BASE, 2, &sMsgObjectRx, 0);
//	
//	       //  after receiving the data clear the receive interrupt flag
//	
// 					g_bRXFlag2 = 0;
//				
//}

/*****************************************************************************
 * 
 *
 *  Rev.   SCR        	  Date        By            Description
 * ---- ---------  	--------      ----          -----------------------------------
 * 1.0             	13 Aug 2016   Arun          Created Initial Version for OBD
 
 ******************************************************************************/
 

  • Hello Arun,

    arun kumar86 said:
    when i am trying to transmit the data from board1 (CAN) to board 2 (CAN) , at first time receiving flag is rised,

    Which flag is raised? Is this flag raised after the data is transmitted?

    arun kumar86 said:
    and from the  CAN CONTROL REGISTER -(CAN_CTL_INIT ) bit is also rised.  the CAN CONTROL REGISTER get the value as E4.

    If the CAN Control Register has a value of E4, then CAN_CTL_INIT bit should be '0'. What do you mean by "-(CAN_CTL_INIT ) bit is also rised"?

    arun kumar86 said:
    for the second time transmit the data from board1 (CAN) to board 2(CAN) , then the error flag is gererated. the receive interrupt is not generated .

    Which error flag is generated?

    Thanks,

    Sai

  • hi sir,

    when first time my receive interrupt flag is raised in board 2, but the data is not transmitted to my board 1.
    i check that in my debug window , that code is entered in the canmessageset() function. but the data is not transmitted.

    next time the error flag is generated. here also its entered into the canmessageset() function, but the message is not transmitted,
    i dont know why its not transmitted.

    is there any other changes i want to do in my programe sir ???
  • hi sir,

    i am checking in the debug window . now when the receive flag is raised means ((CAN_CTL_INIT) bit is not raised.
    my CAN CONTROL REGISER value is (0x0E). now ( IE , SIE, EIE), these registers are raised.
    and the STATUS CONTROL REGISTER value is zero.

    when the function is going to canmessageset() , for transmitting the data, then the STATUS CONTROLL REGISTER'S are raised.
    now the STATUS CONTROLL REGISTER value is ( 0x00000073). the following registers are raised in the status register.( CAN_STS_RXOK , CAN_STS_EPASS , CAN_STS_EWARN),

    when finally come out from the canmessageset () function (transmit function ), the STATUS CONTROLL REGISTER value is ( 0x00000063).
    because now the ( CAN_STS_RXOK ) bit is clear.

    how can i clear these (CAN_STS_EPASS , CAN_STS_EWARN) two bits from the CAN STATUS REGISTER.

    because of these two bits , the acknowledgement error is created to me. thats why the data is not transmitted.

    can u please tell me the sollutions for this prob sir ..

    thanks

    arun
  • hi sir,

    did you find how to clear that flag means , can you please let it know to me sir,
    because i dont know how to clear that flags.

    thanks
    arun