cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with CAN in loopback mode

Erwan03
Associate III

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;

  }

}

1 ACCEPTED SOLUTION

Accepted Solutions

Configure CAN_Rx pin (PA11) in pullup mode:

SofLit_0-1711370925364.png

 

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

View solution in original post

7 REPLIES 7
SofLit
ST Employee

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 on "Accept as Solution" on the reply which solved your issue or answered your question.

Thank you for your quick answer!

Here is the GPIO config from the .ioc

Erwan03_0-1711363588909.png

 

I need your ioc file. please attach it.

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

here is the file. Sorry i clicked on the Accept as Solution but did not wanted to. Missclick.

Configure CAN_Rx pin (PA11) in pullup mode:

SofLit_0-1711370925364.png

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Erwan03
Associate III

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);

}

 

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 on "Accept as Solution" on the reply which solved your issue or answered your question.