cancel
Showing results for 
Search instead for 
Did you mean: 

The problem in CAN Receive using Interrupt. As code hangs in (HAL_CAN_RxFifo0MsgPendingCallback) function in STM32F103C8T6.

ALAN4
Associate II

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.

0693W000001rfS1QAI.png

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

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

15 REPLIES 15
SKacp.1
Senior II

Hi,

I propose to increase table rcvd_msg from 5 to 8 elements.

Perhaps 9, and insure the data is properly NUL terminated to use string functions against it, and content is ASCII​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Sure, I am going to try.

Sure, going to try.

Yeah, I tried but it is still hanging in Receive Callback Function.

Yeah, I tried but it is still hanging in Receive Callback Function.0693W000001rgJKQAY.png

ALAN4
Associate II

0693W000001rgKSQAY.png

0693W000001rgLBQAY.png

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.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
SKacp.1
Senior II

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.