Skip to main content
Associate III
March 25, 2024
Solved

Issue with CAN in loopback mode

Hello, i am using f446re nucleo board and have been facing a problem for a while now. I need to establish a loopback CAN transmission and the debug mode allows me to find a bug in the CAN Start function: HAL_ERROR 0x1 returned everytime i attempt.

here is the while loop i am talking about:

while((hcan->Instance->MSR & CAN_MSR_INAK) != 0)

{

  if((HAL_GetTick() -tickstart) > CAN_TIMEOUT_VALUE)

  {

    hcan->ErrorCode |= HAL_CAN_ERROR_TIMEOUT;

    hcan->State = HAL_CAN_STATE_ERROR;

    return HAL_ERROR;

  }

}

This topic has been closed for replies.
mƎALLEm
mƎALLEmBest answer
ST Technical Moderator
March 25, 2024

Configure CAN_Rx pin (PA11) in pullup mode:

SofLit_0-1711370925364.png

 

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

7 replies

mƎALLEm
ST Technical Moderator
March 25, 2024

Hello,

Could you please share your code or your ioc file if you're using CubeMx?

Share the GPIO pin configurations.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
Erwan03Author
Associate III
March 25, 2024

Thank you for your quick answer!

Here is the GPIO config from the .ioc

Erwan03_0-1711363588909.png

 

mƎALLEm
ST Technical Moderator
March 25, 2024

I need your ioc file. please attach it.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
Erwan03Author
Associate III
March 25, 2024

Thank you for your help. I don,t know how come this worked but it did.

Another problem i am facing is i am trying to display the frame using the picoscope. I Wrote a function that initialise the Header Struct, and send the data, but nothing on the screen, can you help me one more time? he re is the function i wrote: 

 

void CAN_send(void)

{

char msg[50];

CAN_TxHeaderTypeDef TxHeader;

uint8_t TxData[4] = {'T','E','S','T'};

 

TxHeader.DLC = 4; // 4 data byte

TxHeader.ExtId = 0; // Not used so far

TxHeader.IDE = CAN_ID_STD; // Standard ID

TxHeader.RTR = CAN_RTR_DATA; // Data and not remote frame

TxHeader.StdId = 0x103; // Data ID

TxHeader.TransmitGlobalTime = DISABLE;

 

if(HAL_CAN_AddTxMessage(&hcan1, &TxHeader, TxData, &TxMailbox)!=HAL_OK)

{

Error_Handler();

}

while( HAL_CAN_IsTxMessagePending(&hcan1, TxMailbox));

 

sprintf(msg, "Message transmitted\r\n");

HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY);

}

 

mƎALLEm
ST Technical Moderator
March 25, 2024

Hello,

Since the original question was answered, I invite you to open a new thread and tag me there, I will gladly help you on this new question ;).

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