cancel
Showing results for 
Search instead for 
Did you mean: 

how to convert CAN loopback example code to CAN normal mode?

utamb
Associate II

I am using CAN loopback example code for my STM23l476RG evaluation board (with new API's) and it is working fine, but how port same example to normal mode I am not getting please help.

6 REPLIES 6

Look for Network examples. You need two nodes for Normal mode to be functional, as a receiving node needs to acknowledge the packets.

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

I am using network example with two evaluation board along with MCP2551 CAN tranceiver. One board I configured as tx and another as rx, but I am not able to receive the data in Rxdata buffer

suggest me something.

//this is my TX part code

 CanHandle.Init.TimeTriggeredMode = DISABLE;

 CanHandle.Init.AutoBusOff = DISABLE;

 CanHandle.Init.AutoWakeUp = DISABLE;

 CanHandle.Init.AutoRetransmission = ENABLE;

 CanHandle.Init.ReceiveFifoLocked = DISABLE;

 CanHandle.Init.TransmitFifoPriority = DISABLE;

 CanHandle.Init.Mode = CAN_MODE_NORMAL;

 CanHandle.Init.SyncJumpWidth = CAN_SJW_1TQ;

 CanHandle.Init.TimeSeg1 = CAN_BS1_6TQ;

 CanHandle.Init.TimeSeg2 = CAN_BS2_2TQ;

 CanHandle.Init.Prescaler = 5;

  

 if(HAL_CAN_Init(&CanHandle) != HAL_OK)

 {

  /* Initialization Error */

  Error_Handler();

 }

 /*##-3- Start the CAN peripheral ###########################################*/

 if (HAL_CAN_Start(&CanHandle) != HAL_OK)

 {

  /* Start Error */

  Error_Handler();

 }

 /*##-4- Start the Transmission process #####################################*/

 TxHeader.StdId = 0x11;

 TxHeader.RTR = CAN_RTR_DATA;

 TxHeader.IDE = CAN_ID_STD;

 TxHeader.DLC = 2;

 TxHeader.TransmitGlobalTime = DISABLE;

 TxData[0] = '$';

 TxData[1] = '#';

  

 /* Request transmission */

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

 {

  /* Transmission request Error */

  Error_Handler();

 }

//this is RX side code

configuring filter and receiving msg

sFilterConfig.FilterBank = 0;

 sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;

 sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;

 sFilterConfig.FilterIdHigh = 0x11 << 5;

 sFilterConfig.FilterIdLow = 0x0000;

 sFilterConfig.FilterMaskIdHigh = 0xFFFF;

 sFilterConfig.FilterMaskIdLow = 0xFFFF;

 sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;

 sFilterConfig.FilterActivation = ENABLE;

 sFilterConfig.SlaveStartFilterBank = 14;

  

 if(HAL_CAN_ConfigFilter(&CanHandle, &sFilterConfig) != HAL_OK)

 {

  /* Filter configuration Error */

  Error_Handler();

 }

 /* Get RX message */

 if (HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &RxHeader, RxData) != HAL_OK)

 {

  /* Reception Error */

  Error_Handler();

 }

 /* Display LEDx */

 if ((RxHeader.StdId == 0x11) && (RxHeader.IDE == CAN_ID_STD) && (RxHeader.DLC == 2))

 {

// code for LED

 }

Don't the EVAL series boards​ have CAN ports and transceivers already?

What board specifically do you have? A DISCO or NUCLEO? ​

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

No CAN transceiver. It is NUCLEO. MCP2551 CAN tranceiver I am using.0690X000006CGzUQAW.jpg

Do you get the answer? I am facing same problem.

turboscrew
Senior III

If it works with loopback, it should work with two boards with the same SW and CAN lines connected, without loopback.