cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F446's CAN transmission completed interrupt not firing :(

PPopo
Senior

Hello,

I'm working with the CAN Module from the STM32F446RE board which has the MCU mentioned in the title. I'm trying to transmit some data on the UART via Tera Term terminal and take this data and send it via Loopback mode and read it back. For starters I have generated the configuration from CubeMx and written some code to transmit a numerical value which the user enters to the can 'network' and when that happens I want to go into an can completed transmission ISR and print some message on the UART from there to indicate that the transfer was completed.

In the CubeMx I have configured the CAN interrupts like this:

CAN1 TX interrupt enabled

CAN1 RX interrupt enabled(because I will also want to trigger the receive interrupt after I fix this issue)

This is the part of the code(I cannot copy paste all as this is the post will become too long just ask me if I need to provide more of my code):

while (1)
  {
	  /*keep getting what the user enters on the UART untill enter is pressed*/
	  while(received_data != '\r')
	  {
		  HAL_UART_Receive(&huart2,&received_data,1,HAL_MAX_DELAY);
		  recvd_buffer[buf_indx] = received_data;
		  buf_indx++;
		  if(buf_indx > 1)
		  {
			  buf_indx = 0;
		  }
	  }
 
	  if( recvd_buffer[0] == '1' || recvd_buffer[0] == '0')
	  {
		  received_data = 0;
		  buf_indx = 0;
 
		  user_data = "\n\rOK. Starting CAN transmission in interrupt mode\n\r";
		  len_of_data = strlen(user_data);
		  HAL_UART_Transmit( &huart2, (uint8_t*)user_data, len_of_data, HAL_MAX_DELAY );
		  //CAN will start sending data in non-blocking mode
		  CAN_Tx(recvd_buffer[0]);
		  recvd_buffer[0] = 0;
		  recvd_buffer[1] = 1;
	  }
	  else
	  {
		  recvd_buffer[0] = 0;
		  recvd_buffer[1] = 1;
		  received_data = 0;
		  user_data = "\n\rInvalid value. Please enter either 1 or 2\n\r";
		  len_of_data = strlen(user_data);
		  HAL_UART_Transmit( &huart2, (uint8_t*)user_data, len_of_data, HAL_MAX_DELAY );
	  }
  }
}

Below I have also implemented the 3 Tx mailbox transmit complete callback functions:

void HAL_CAN_TxMailbox0CompleteCallback(CAN_HandleTypeDef *hcan)
{
	uint16_t user_data = "\n\rTransmission completed mailbox_0\n\r";
	uint16_t len_of_data = strlen(user_data);
	HAL_UART_Transmit( &huart2, (uint8_t*)user_data, len_of_data, HAL_MAX_DELAY );
}
 
void HAL_CAN_TxMailbox1CompleteCallback(CAN_HandleTypeDef *hcan)
{
	user_data = "\n\rTransmission completed mailbox_1\n\r";
	uint16_t len_of_data = strlen(user_data);
	HAL_UART_Transmit( &huart2, (uint8_t*)user_data, len_of_data, HAL_MAX_DELAY );
}
 
void HAL_CAN_TxMailbox2CompleteCallback(CAN_HandleTypeDef *hcan)
{
	user_data = "\n\rTransmission completed mailbox_2\n\r";
	uint16_t len_of_data = strlen(user_data);
	HAL_UART_Transmit( &huart2, (uint8_t*)user_data, len_of_data, HAL_MAX_DELAY );
}

This is the CAN_Tx function that makes use of the CAN hal driver to send the data:

void CAN_Tx(uint8_t value)
{
  uint8_t mailbox_no;
  CAN_TxHeaderTypeDef can_header;
  can_header.StdId = 0;
  can_header.ExtId = 0;
  can_header.IDE = CAN_ID_STD;
  can_header.RTR = CAN_RTR_DATA;
  can_header.DLC = 1;
  can_header.TransmitGlobalTime = DISABLE;
  HAL_CAN_AddTxMessage(&hcan1, &can_header, value, &mailbox_no);
}

I have debugged the code in main and it seems to work fine. I got no error in the Can_Tx function it returns with success. From my understanding from the datasheet of the microcontroller(secttion 30.8 - bxCAN interrupts) if the timer1 transmit interrupt is enabled than depending on which mailbox was used for transmission one of those callbacks should get executed. However that does not happen the code inside them won't get executed. Please help me understand what I'm doing wrong. Thank you!

0 REPLIES 0