The problem in CAN Receive using Interrupt. As code hangs in (HAL_CAN_RxFifo0MsgPendingCallback) function in STM32F103C8T6.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-28 7:59 PM
Hi,
I am working on CAN on STM32F103C8T6.
I am using a Callback Function of (HAL_CAN_RxFifo0MsgPendingCallback) but soon after receiving message code hangs in Callback Function even though no data sent afterwards it.
I am not getting the reason. Because this function works fine on CORTEX-M4 pocessor.
However, Transmit_Interrupt is working fine. But receive interrupt is hanging.
Here, is the code Snippet.
Code is getting stuck in the receiver callback function (HAL_CAN_RxFifo0MsgPendingCallback).
/* INTERRUPT HANG IN RECEIVER ISR FUNCTION */
void HAL_CAN_RxFifo0MsgPendingCallback (CAN_HandleTypeDef *hcan) {
CAN_RxHeaderTypeDef RxHeader;
uint8_t rcvd_msg[5];
char msg[50];
if(HAL_CAN_GetRxMessage((CAN_HandleTypeDef*)&hcan,CAN_RX_FIFO0,&RxHeader,rcvd_msg) != HAL_OK)
{
Error_Handler();
}
sprintf(msg,"Message Received : %s\n",rcvd_msg);
HAL_UART_Transmit(&huart1,(uint8_t*)msg,strlen(msg),10);
}
Guys, please help.
Thanks,
Alankrit
Solved! Go to Solution.
- Labels:
-
CAN
-
STM32F1 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-29 10:09 AM
Hi,
Please, see my example. I tested on the STM32F103VBT6. My example work in NORMAL and LOOPBACK mode. I have also connected LCD for diagnostic. HCLK = 72 MHZ, APB1 PCLK1 = 36 MHz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-28 11:08 PM
Hi,
I propose to increase table rcvd_msg from 5 to 8 elements.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-29 12:08 AM
Perhaps 9, and insure the data is properly NUL terminated to use string functions against it, and content is ASCII​
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-29 12:47 AM
Sure, I am going to try.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-29 12:48 AM
Sure, going to try.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-29 12:49 AM
Yeah, I tried but it is still hanging in Receive Callback Function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-29 12:52 AM
Yeah, I tried but it is still hanging in Receive Callback Function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-29 12:53 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-29 1:12 AM
Callbacks done under interrupt context, would avoid calling things which can block, or have delays/timeouts dependent on other interrupts. Would avoid printing to uart.
Queue or buffer data to be handled off critical path.
​
Don't see you dealing with NUL termination. Post code in formatted code block, not screen grabs.​
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-29 2:07 AM
Hi,
Please show me Your CAN settings.
I propose change in Your function void HAL_CAN_RxFifo0MsgPendingCallback (CAN_HandleTypeDef *hcan). Use sprintf and HAL_UART_transmit in the external functions and call it from the main. Maybe You have problem with the stack.
