cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to receive data using CAN

Mukesh_Patil
Associate II

Hello, 

I am using NUCLEO F767 microcontroller. i want to receive data using CAN. I am using CAN2. pins PB12 Rx and PB13 TX. I have tried bunch of things but i am unable to receive data. So, please help me regarding this 

Code : 

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_CAN2_Init();

/* USER CODE BEGIN 2 */



if (HAL_CAN_Start(&hcan2) != HAL_OK)

{

Error_Handler();

}



sFilterConfig.FilterActivation = CAN_FILTER_ENABLE;///CAN_FILTER_

sFilterConfig.FilterBank = 0; // which filter bank to use from the assigned ones

sFilterConfig.FilterFIFOAssignment = CAN_FILTER_FIFO1;

sFilterConfig.FilterIdHigh = 0x114<<5;//<<5;

sFilterConfig.FilterIdLow = 0x0000;

sFilterConfig.FilterMaskIdHigh = 0x114<<5;//0x1<<13;

sFilterConfig.FilterMaskIdLow = 0x0000;

sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;

sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;

sFilterConfig.SlaveStartFilterBank = 27;



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

{

Error_Handler();

}



if (HAL_CAN_ActivateNotification(&hcan2, CAN_IT_RX_FIFO1_MSG_PENDING) != HAL_OK) //CAN_IT_RX_FIFO0_MSG_PENDING

{

Error_Handler();

}



/* USER CODE END 2 */



/* Infinite loop */

/* USER CODE BEGIN WHILE */

while (1)

{

/* USER CODE END WHILE */



/* USER CODE BEGIN 3 */

}

/* USER CODE END 3 */

}



/* USER CODE BEGIN 4 */

void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)

{

HAL_CAN_GetRxMessage(&hcan2, CAN_RX_FIFO1, &RxHeader, RxData);

}
1 ACCEPTED SOLUTION

Accepted Solutions

Hello @Mukesh_Patil ,

Getting back to your request. 

I have made two projects for NUCLEO-F767:

- CAN in Loopback mode

- CAN in Normal mode: using two NUCLEO-F767 boards. Both using the CAN transceiver: MCP2562FD.

I'm attaching the two projects.

What I changed versus what you shared:

Changed timing parameters for CAN to get a simple point at ~85%.

According the Nucleo board schematics PB13 is connected to RMII_TXD1 over JP7 (if you didn't remove it it could cause an issue)

Hope that solves your issue/answers your question.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

View solution in original post

9 REPLIES 9
SofLit
ST Employee

Hello @Mukesh_Patil and welcome to the community.

Please review our recommendations in this link on thread posting in this community especially how to share your code and on which forum you post your question (this is not CubeIDE subject but it's related to the MCU usage itself). I'm editing it in order to follow these recommendations and moving the post to the correct forum.

 

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
SofLit
ST Employee

You have an issue with CAN filter configuration especially with this parameter:

 

sFilterConfig.SlaveStartFilterBank = 27

 

if you are not using CAN1 you can set it to 0:

 

sFilterConfig.SlaveStartFilterBank = 0

 

See this thread (you are in case 2):

https://community.st.com/t5/stm32-mcus-products/how-to-configure-can-filters-to-use-can1-and-can2-parallelly/td-p/56553

Hope it does answer your question.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Thank you for your assistance.

I have tried sFilterConfig.SlaveStartFilterBank = 0. But I still haven't gotten any result. and i am only using one CAN that is CAN2

 

You have also another issue. The usage FIFO is wrong:

Here you assigned the filter to FIFO1 and you activated the interrupt on FIFO1.

 

sFilterConfig.FilterFIFOAssignment = CAN_FILTER_FIFO1
if (HAL_CAN_ActivateNotification(&hcan2, CAN_IT_RX_FIFO1_MSG_PENDING) != HAL_OK)

 

But here you are using FIFO0 callback and in the callback you are receiving data from FIFO1 which doeasn't make sense:

 

void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)

{

HAL_CAN_GetRxMessage(&hcan2, CAN_RX_FIFO1, &RxHeader, RxData);

}

 

Here you are using the incorrect callback. So, replace HAL_CAN_RxFifo0MsgPendingCallback by HAL_CAN_RxFifo1MsgPendingCallback

I suggest you also to start with a filter passing all IDs:

 

sFilterConfig.FilterIdHigh = 0x0000;
sFilterConfig.FilterIdLow = 0x0000;
sFilterConfig.FilterMaskIdHigh = 0x0000;
sFilterConfig.FilterMaskIdLow = 0x0000;
sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;

 

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

I have made changes as you said but i am still unable to get the data. please let me know if there is anything i should try.

 

Mukesh_Patil
Associate II

I am sharing Main.c file

 

Mukesh_Patil
Associate II

Here are some pictures of IOC file configuration for CAN:

Screenshot (28).pngScreenshot (29).pngScreenshot (30).pngScreenshot (31).png

Hello,

Please attach your project including your ioc file.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Hello @Mukesh_Patil ,

Getting back to your request. 

I have made two projects for NUCLEO-F767:

- CAN in Loopback mode

- CAN in Normal mode: using two NUCLEO-F767 boards. Both using the CAN transceiver: MCP2562FD.

I'm attaching the two projects.

What I changed versus what you shared:

Changed timing parameters for CAN to get a simple point at ~85%.

According the Nucleo board schematics PB13 is connected to RMII_TXD1 over JP7 (if you didn't remove it it could cause an issue)

Hope that solves your issue/answers your question.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.