cancel
Showing results for 
Search instead for 
Did you mean: 

CANBUS on F0 not able to receive.

JWieb
Associate III

I am working with the STM32F072CB device on a custom PCB. Working from this STM32 example.

I just want to implement a basic loopback test. However i don't seem to receive any data.

HAL_CAN_Init() is called succesful

HAL_CAN_Start() is called succesful

HAL_CAN_ActivateNotification(&hcan, CAN_IT_RX_FIFO0_MSG_PENDING) is called successful and should call HAL_CAN_RxFifo0MsgPendingCallback() when any message are recieved.

I then transmit a basic message from HAL_CAN_AddTxMessage() of which I can see is complete from the HAL_CAN_TxMailbox0CompleteCallback().

But still no receive interrupt is generated.

static void MX_CAN_Init(void)
{
  hcan.Instance = CAN;
  hcan.Init.Prescaler = 8;
  hcan.Init.Mode = CAN_MODE_SILENT_LOOPBACK;
  hcan.Init.SyncJumpWidth = CAN_SJW_1TQ;
  hcan.Init.TimeSeg1 = CAN_BS1_5TQ;
  hcan.Init.TimeSeg2 = CAN_BS2_6TQ;
  hcan.Init.TimeTriggeredMode = DISABLE;
  hcan.Init.AutoBusOff = DISABLE;
  hcan.Init.AutoWakeUp = DISABLE;
  hcan.Init.AutoRetransmission = ENABLE;
  hcan.Init.ReceiveFifoLocked = DISABLE;
  hcan.Init.TransmitFifoPriority = DISABLE;
  if (HAL_CAN_Init(&hcan) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN CAN_Init 2 */
  if (HAL_CAN_Start(&hcan) != HAL_OK)
  {
    /* Start Error */
    Error_Handler();
  }
 
  if (HAL_CAN_ActivateNotification(&hcan, CAN_IT_RX_FIFO0_MSG_PENDING) != HAL_OK)
  {
    /* Notification Error */
    Error_Handler();
  }
  /* USER CODE END CAN_Init 2 */
 
}
 
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan) {
	if (HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &RxHeader, RxData) == HAL_OK)
		CANprocess();
}
 
void CAN_TX_Echo_Test() {
	TxData[0] = 0xbe;
	TxData[1] = 0xef;
 
	/* Start the Transmission process */
	if (HAL_CAN_AddTxMessage(&hcan, &TxHeader, TxData, &TxMailbox) != HAL_OK) {
		/* Transmission request Error */
		Error_Handler();
	}
}

1 ACCEPTED SOLUTION

Accepted Solutions

You have to setup and enable some rx filter.

View solution in original post

2 REPLIES 2

You have to setup and enable some rx filter.

JWieb
Associate III

Yup. Now i feel like a fool.. I did not include a filter specifically to get all the messages.

Turns out you need to apply a pass all filter..