cancel
Showing results for 
Search instead for 
Did you mean: 

NUCLEO-STM32F446RE: TX working, RX not

TMass.1
Associate

Hi!

I am using a NUCLEO-STM32F446RE and HAL which was created with CubeMX. I can send messages via CAN to my test PC. Messages which are sent to the NUCLEO board are correctly acknowledged from the NUCLEO board. So I assume that HW wiring, CAN transceiver etc. is working fine and the STM is somehow receiving the CAN message.

As soon as I register the TX interrupt via:

HAL_CAN_ActivateNotification(&hcan1, CAN_IT_TX_MAILBOX_EMPTY);

It gets called properly every time after a CAN message is sent.

Now my problem:

If I send CAN-messages to the NUCLEO board the messages get acknowledged by the NUCLEO, but cannot be received via software. Neither of the two interrupt routines (RX1 and RX0) is called even though both are registered with:

HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING);

HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO1_MSG_PENDING);

The return value of HAL_CAN_GetRxFifoFillLevel is always 0 and the function HAL_CAN_GetRxMessage does not return the CAN message which was sent and acknowledged on the bus.

I have not performed any filter configuration so it should be set to receive all CAN-IDs.

I only configured the clock, CAN and one GPIO-Pin connected to a LED in CubeMX. Here is my complete main:

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */
 
  /* USER CODE END 1 */
 
  /* MCU Configuration--------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* USER CODE BEGIN Init */
 
  /* USER CODE END Init */
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* USER CODE BEGIN SysInit */
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_CAN1_Init();
  /* USER CODE BEGIN 2 */
  HAL_CAN_ActivateNotification(&hcan1, CAN_IT_TX_MAILBOX_EMPTY);
  HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING);
  HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO1_MSG_PENDING);
 
  HAL_CAN_Start(&hcan1);
	
  CAN_TxHeaderTypeDef myTxHeader;
  uint8_t data[8];
  CAN_TxMailBox_TypeDef myMailbox;
  myTxHeader.DLC = 8;
  myTxHeader.StdId = 0x180;
  myTxHeader.IDE = CAN_ID_STD;
  myTxHeader.RTR = CAN_RTR_DATA;
 
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
    
  while (1)
  {
	  HAL_CAN_AddTxMessage(&hcan1, &myTxHeader, data, &myMailbox);
 
	  HAL_Delay(1000);
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

And here is the relevant part of the stm32f4xx_it.c:

/**
  * @brief This function handles CAN1 TX interrupt.
  */
void CAN1_TX_IRQHandler(void)
{
  /* USER CODE BEGIN CAN1_TX_IRQn 0 */
	HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
  /* USER CODE END CAN1_TX_IRQn 0 */
  HAL_CAN_IRQHandler(&hcan1);
  /* USER CODE BEGIN CAN1_TX_IRQn 1 */
 
  /* USER CODE END CAN1_TX_IRQn 1 */
}
 
/**
  * @brief This function handles CAN1 RX0 interrupt.
  */
void CAN1_RX0_IRQHandler(void)
{
  /* USER CODE BEGIN CAN1_RX0_IRQn 0 */
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
  /* USER CODE END CAN1_RX0_IRQn 0 */
  HAL_CAN_IRQHandler(&hcan1);
  /* USER CODE BEGIN CAN1_RX0_IRQn 1 */
 
  /* USER CODE END CAN1_RX0_IRQn 1 */
}
 
/**
  * @brief This function handles CAN1 RX1 interrupt.
  */
void CAN1_RX1_IRQHandler(void)
{
  /* USER CODE BEGIN CAN1_RX1_IRQn 0 */
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
  /* USER CODE END CAN1_RX1_IRQn 0 */
  HAL_CAN_IRQHandler(&hcan1);
  /* USER CODE BEGIN CAN1_RX1_IRQn 1 */
 
  /* USER CODE END CAN1_RX1_IRQn 1 */
}
 
/**
  * @brief This function handles CAN1 SCE interrupt.
  */
void CAN1_SCE_IRQHandler(void)
{
  /* USER CODE BEGIN CAN1_SCE_IRQn 0 */
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
  /* USER CODE END CAN1_SCE_IRQn 0 */
  HAL_CAN_IRQHandler(&hcan1);
  /* USER CODE BEGIN CAN1_SCE_IRQn 1 */
 
  /* USER CODE END CAN1_SCE_IRQn 1 */
}

Does anyone know what I am doing wrong here? The LED is toggling every 1000ms so the TX interrupt is called. I would have expected the interrupt routine RX0 to be called after every message on the CAN-bus and that the LED connected to PA5 is light up but this is not the case. If any more code is needed -> no problem. But it is only CubeMX generated code. I have posted all of my user code here.

Thanks in advance for your support!

0 REPLIES 0