cancel
Showing results for 
Search instead for 
Did you mean: 

CAN doesn't go to the interrupt func.

Zek_De
Senior

Hello friends,I am trying CAN but I am sending something but codes dont go to the ibnterrupt function I will send codes.Any help? interrupt function is in interrupt section

void MX_CAN_Config()

{

hcan1.pTxMsg=&TxM;

hcan1.pRxMsg=&RxM;

sFilterConfig.FilterNumber=0;

sFilterConfig.FilterMode=CAN_FILTERMODE_IDMASK;

sFilterConfig.FilterScale=CAN_FILTERSCALE_32BIT;

sFilterConfig.FilterIdHigh=0x0000;

sFilterConfig.FilterIdLow=0x0000;

sFilterConfig.FilterMaskIdHigh=0x0000;

sFilterConfig.FilterMaskIdLow=0x0000;

sFilterConfig.FilterFIFOAssignment=0;

sFilterConfig.BankNumber=14;

sFilterConfig.FilterActivation=ENABLE;

HAL_CAN_ConfigFilter(&hcan1, &sFilterConfig );

hcan1.pTxMsg->StdId=0x245;

hcan1.pTxMsg->RTR=CAN_RTR_DATA;

hcan1.pTxMsg->IDE=CAN_ID_STD;

hcan1.pTxMsg->DLC=4;

hcan1.pRxMsg->StdId = 0x7F7; //to not make a mistake first cycle(random id)

}

int main(void)
{
 
 
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_CAN1_Init();
  MX_CAN2_Init();
  MX_TIM1_Init();
  MX_TIM2_Init();
  MX_NVIC_Init();
  MX_CAN_Config();
	
	HAL_Delay(3000);
	
	HAL_CAN_Receive_IT(&hcan1, CAN_FIFO0);
	
  while (1)
  {
 
		
		//led1-> yesil led2-> led3->turuncu
		for(j = 1;j<=numberOfDevice; j++)
		{
 
			hcan1.pTxMsg->StdId=j;
			hcan1.pTxMsg->RTR=CAN_RTR_REMOTE;
			while(!(HAL_CAN_Transmit(&hcan1,100) == HAL_OK));
			
			
			tick = HAL_GetTick();
			while((hcan1.pRxMsg->StdId != j) && (hcan1.pRxMsg->DLC != 4))
			{
				if(((HAL_GetTick() - tick) > timeOut))
				{
					isTimeOutErr = 1;
					brokenDevice = j; 
					HAL_GPIO_TogglePin(GPIOA,led2_Pin);
					break;
					
				}
				
			}
			
			sensor[i-1]	= Assemble_Data(hcan1.pRxMsg->Data);
			
		}
			
			HAL_GPIO_TogglePin(GPIOA,led1_Pin);
			
 
 
 
 
 
 
		
  }
 
 
 
 
OTHER DEVICE
 
 
int main(void)
{
 
  HAL_Init();
 
  SystemClock_Config();
 
  MX_GPIO_Init();
  MX_TIM2_Init();
  MX_TIM1_Init();
  MX_CAN_Init();
 
	ULTRASONIC.Start();
	MX_CAN_Config();
	
	HAL_CAN_Receive_IT(&hcan, CAN_FIFO0);
 
  while (1)
  {
		
		
		ULTRASONIC.Task();
		mesafe = ULTRASONIC.GetDistance();
		ULTRASONIC.CheckError();
	if(((hcan.pRxMsg->StdId == 2) && (hcan.pRxMsg->RTR == CAN_RTR_REMOTE)))
	{
		canInterrupt = 1;
		hcan.pRxMsg->StdId = 0x7FF;
	}
		
		if(canInterrupt)
		{
			Split_Data(splittedData,mesafe);
			
			hcan.pTxMsg->RTR=CAN_RTR_DATA;
			hcan.pTxMsg->DLC=4;
			hcan.pTxMsg->StdId=2;
			hcan.pTxMsg->IDE=CAN_ID_STD;
			
			hcan.pTxMsg->Data[0] = splittedData[0];
			hcan.pTxMsg->Data[1] = splittedData[1];
			hcan.pTxMsg->Data[2] = splittedData[2];
			hcan.pTxMsg->Data[3] = splittedData[3];
			
			HAL_CAN_Transmit(&hcan, 200);
			
			canInterrupt = 0;
			
		}
 
	
	
  }
}
 

2 REPLIES 2
T J
Lead

you have 2 fifos, did you check the other one ? just guessing here,

did you enable the CAN interrupt in the cube ?

where are the print statements ?

its make life so much easier when you can see the issues come up on the terminal.

hook up a serial port, and transmit messages.. ( but not from within interrupts)

Zek_De
Senior

Thank you TJ,I handled it with different algorithm.Probably one more devices tried to go on line I don't know.