cancel
Showing results for 
Search instead for 
Did you mean: 

CAN doesn't receive in loopback

Tomas Zahradnik
Associate II
Posted on September 19, 2017 at 10:34

Hi all,

I have connected CAN driver TAJ1050 to my STM32F469I-Discovery kit on extension port CN12 (pin 9 and 10). I can transmit message which is correctly received in another device (I can see this message in my PcanView).

Unfortunately I cannot receive any message even in loopback mode.

I have used source code from example in STM32Cube_FW_F4_V1.0 repository (CAN_Loopback example).

Here is relevant code:

 CAN_FilterConfTypeDef sFilterConfig;
 static CanTxMsgTypeDef TxMessage;
 static CanRxMsgTypeDef RxMessage;
 hcan2.Instance = CAN2;
 hcan2.pTxMsg = &TxMessage;
 hcan2.pRxMsg = &RxMessage;
 hcan2.Init.Prescaler = 18;
 hcan2.Init.Mode = CAN_MODE_NORMAL;
 hcan2.Init.SJW = CAN_SJW_1TQ;
 hcan2.Init.BS1 = CAN_BS1_8TQ;
 hcan2.Init.BS2 = CAN_BS2_1TQ;
 hcan2.Init.TTCM = DISABLE;
 hcan2.Init.ABOM = DISABLE;
 hcan2.Init.AWUM = DISABLE;
 hcan2.Init.NART = DISABLE;
 hcan2.Init.RFLM = DISABLE;
 hcan2.Init.TXFP = DISABLE;
 if(HAL_CAN_Init(&hcan2) != HAL_OK)
 {
 /* Initialization Error */
 Error_Handler();
 }
 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.FilterActivation = ENABLE;
 sFilterConfig.BankNumber = 14;
 if(HAL_CAN_ConfigFilter(&hcan2, &sFilterConfig) != HAL_OK)
 {
 /* Filter configuration Error */
 Error_Handler();
 }
 if(HAL_CAN_Receive(&hcan2, CAN_FIFO0,100) == HAL_ERROR)
 {
 /* Reception Error */
 Error_Handler();
 }
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

I'm afraid that there is some misunderstanding about filter registers because there couldn't be any HW issue while I'm in loopback mode, could be?

Could someone give me some hint?

Thanks for any comments.

Tomas

#can #loopback #stm32f469i-disco
3 REPLIES 3
Tomas Zahradnik
Associate II
Posted on October 29, 2017 at 22:10

Thanks to my colleague I found the solutionfor my issue.

I have used CAN2 (slave CAN controller) and in that case, must be used filter numbersstarting from 14. So if I use FilterNumber14 in my example, it starts working.

So the fixed example is:

CAN_FilterConfTypeDef sFilterConfig;
 static CanTxMsgTypeDef TxMessage;
 static CanRxMsgTypeDef RxMessage;
 hcan2.Instance = CAN2;
 hcan2.pTxMsg = &TxMessage;
 hcan2.pRxMsg = &RxMessage;
 hcan2.Init.Prescaler = 18;
 hcan2.Init.Mode = CAN_MODE_NORMAL;
 hcan2.Init.SJW = CAN_SJW_1TQ;
 hcan2.Init.BS1 = CAN_BS1_8TQ;
 hcan2.Init.BS2 = CAN_BS2_1TQ;
 hcan2.Init.TTCM = DISABLE;
 hcan2.Init.ABOM = DISABLE;
 hcan2.Init.AWUM = DISABLE;
 hcan2.Init.NART = DISABLE;
 hcan2.Init.RFLM = DISABLE;
 hcan2.Init.TXFP = DISABLE;
 if(HAL_CAN_Init(&hcan2) != HAL_OK)
 {
 /* Initialization Error */
 Error_Handler();
 }
 sFilterConfig.FilterNumber = 14;
 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.FilterActivation = ENABLE;
 sFilterConfig.BankNumber = 14;
 if(HAL_CAN_ConfigFilter(&hcan2, &sFilterConfig) != HAL_OK)
 {
 /* Filter configuration Error */
 Error_Handler();
 }
 if(HAL_CAN_Receive(&hcan2, CAN_FIFO0,100) == HAL_ERROR)
 {
 /* Reception Error */
 Error_Handler();
 }

Unfortunately, I didn't find the right and clear explanation of this solution.

Do you have some comments?

Tomas

Posted on October 29, 2017 at 23:00

Hi Tomas,

STM32F469NI embeds two CAN interfaces: CAN1 and CAN2. For both these CANs there is a CAN filtering solution, which provides 28 filter banks. These filter banks are equally divided in terms of assignemnt to CAN interfaces. This means that CAN1 uses filter banks number 0..13 and CAN2 uses filter banks number 14..27. In your application you work with CAN2, so filter bank 14 is the first one, which can be used with CAN2.

Regards

Szymon 

Posted on October 30, 2017 at 06:29

Hi Szymon,

Thanks for the explanation. It is evidence of my conclusion with good describing. Unfortunately, I couldn't see this clear explanation in the datasheet. But now I can remember it and for other is this thread of discussion.

Thank you for your comment Szymon.

Regards

Tomas