2024-07-05 04:37 AM - last edited on 2024-07-05 04:48 AM by SofLit
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);
}
Solved! Go to Solution.
2024-10-08 07:19 AM
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.
2024-07-05 04:48 AM
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.
2024-07-05 04:54 AM - edited 2024-07-05 04:56 AM
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):
Hope it does answer your question.
2024-07-05 05:11 AM
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
2024-07-05 06:57 AM - edited 2024-07-05 07:03 AM
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;
2024-07-05 09:01 PM
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.
2024-07-05 09:38 PM
2024-07-05 10:05 PM
Here are some pictures of IOC file configuration for CAN:
2024-07-08 07:05 AM
Hello,
Please attach your project including your ioc file.
2024-10-08 07:19 AM
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.