AnsweredAssumed Answered

STM32F7  HAL CAN Receive interrupt only once

Question asked by Rob Ashworth on Jan 25, 2017
Latest reply on Aug 24, 2017 by JongOk Baek

I seem to have an issue with receiving CAN messages.  It is set up on an interrupt, but the interrupt only seems to fire once, and when I receive the 2nd message, nothing happens.  There seems to be very little on setting up the NVIC using the HAL library with CAN.  Can anyone see anything obvious wrong with the configuration etc.  Can transmits OK.

 

Hardware Is the STM32F7 DISCO board.

HAL Libraries are the latest V1.5

 

CAN Config:

//Initialize the CAN bus settings

void CAN_Init(void)

{

HAL_CAN_MspInit(&CanHandle);

}

 

void CAN_Config(void)

{

char MyString[20];

CAN_FilterConfTypeDef sFilterConfig;

 

//HAL_CAN_DeInit(&CanHandle);

 

/*##-1- Configure the CAN peripheral #######################################*/

CanHandle.Instance = CANx;

 

//Calculation is CANCLK/(BRP*(BS1+BS2+1)) = 50/5*(7+2+1) = 1

CanHandle.Init.TTCM = DISABLE;

CanHandle.Init.ABOM = ENABLE;

CanHandle.Init.AWUM = DISABLE;

CanHandle.Init.NART = DISABLE;

CanHandle.Init.RFLM = DISABLE;

CanHandle.Init.TXFP = DISABLE;

CanHandle.Init.Mode = CAN_MODE_NORMAL;

CanHandle.Init.SJW = CAN_SJW_1TQ;//1MBit

CanHandle.Init.BS1 = CAN_BS1_7TQ;//Aim for between 70% & 85% Bit sampling point

CanHandle.Init.BS2 = CAN_BS2_2TQ;//

CanHandle.Init.Prescaler = 5;//2;//?

 

/*##-3- Configure Transmission process #####################################*/

CanHandle.pTxMsg->StdId = 0x64;

CanHandle.pTxMsg->ExtId = 0x01;

CanHandle.pTxMsg->RTR = CAN_RTR_DATA;

CanHandle.pTxMsg->IDE = CAN_ID_STD;

CanHandle.pTxMsg->DLC = 8;

 

if (HAL_CAN_Init(&CanHandle) != HAL_OK)

{

/* Initialization Error */

// Error_Handler();

}

 

/*##-2- Configure the CAN Filter ###########################################*/

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 = CAN_FIFO0;

sFilterConfig.FilterActivation = ENABLE;

sFilterConfig.BankNumber = 14;

 

//Set up the CAN Receive buffer and enable it

HAL_CAN_Receive_IT(&CanHandle, CAN_FIFO0);

 

if (HAL_CAN_ConfigFilter(&CanHandle, &sFilterConfig) != HAL_OK)

{

/* Filter configuration Error */

// Error_Handler();

}

 

HAL_NVIC_SetPriority(CANx_RX0_IRQn, 2, 0);

HAL_NVIC_EnableIRQ(CANx_RX0_IRQn);

HAL_NVIC_SetPriority(CANx_RX1_IRQn, 2, 0);

HAL_NVIC_EnableIRQ(CANx_RX1_IRQn);

 

}

 

Then in the Interupt handler:

void CAN1_RX0_IRQHandler(void)

{

HAL_CAN_IRQHandler(&CanHandle);

// __HAL_CAN_CLEAR_FLAG(&CanHandle,CAN_IT_FMP0);

}

 

void CAN1_RX1_IRQHandler(void)

{

HAL_CAN_IRQHandler(&CanHandle);

//__HAL_CAN_CLEAR_FLAG(&CanHandle,CAN_IT_FMP0);

}

 

 

Then the code which handles what happens when the interrupt is triggered - This only get triggered on the reception of the first message.  Subsequent message are ignored....!!

 

void HAL_CAN_RxCpltCallback(CAN_HandleTypeDef *RxCANHandle)

{

uint8_t CANData[8];

char DebugStr[20];

 

//send debug message

CAN_TAG320_TxDataMerge.CAN_TAG_TxMsg.StdId=0x65;

HAL_CAN_Transmit_IT(&CanHandle);

 

BSP_LCD_SetTextColor(LCD_COLOR_GREEN);

BSP_LCD_SetFont(&Font12);

sprintf(DebugStr,"CAN Message Received %d", nCANMessage);

BSP_LCD_DisplayStringAt(200, 195, (uint8_t*)DebugStr, LEFT_MODE);

CANData[0] = RxCANHandle->pRxMsg->Data[0];

nCANMessage++;//increment the message count

}

Outcomes