cancel
Showing results for 
Search instead for 
Did you mean: 

I am using STM32H743 MCU for CAN communication (classic mode).external loop back mode is working fine. but facing issues in NORMAL MODE of the can.in FDCAN_ECR register REC,TEC as well as CEL bits are setting after transmitting from the MCU.

srikanth
Associate III

i am trying out the example code which is given in Repository from STM

3 REPLIES 3
Ozone
Lead

Do you know the CAN bus spec. ?

REC and TEC are error counter, that effect a silencing and shut-off of non-working nodes.

If there is no recipient (second node) to answer (set the ACK bit during transmission), the error counters go up.

If you have a second node, check the transmission via scope or CANbus analyzer.

srikanth
Associate III

Recipient is epos4 module which work on standard can (bitrate is 1mbps) .

the following is the configuration i have made in my code to set the can in classic mode with 1mbps.please check and verify if any wrong

void MX_FDCAN2_Init(void)

{

 FDCAN_FilterTypeDef sFilterConfig;

 hfdcan2.Instance = FDCAN2;

 hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC;

 hfdcan2.Init.Mode = FDCAN_MODE_NORMAL;

 hfdcan2.Init.AutoRetransmission = ENABLE;

 hfdcan2.Init.TransmitPause = DISABLE;

 hfdcan2.Init.ProtocolException = ENABLE;

 hfdcan2.Init.NominalPrescaler = 0x2; /* tq = NominalPrescaler x (1/fdcan_ker_ck) */

 hfdcan2.Init.NominalSyncJumpWidth = 0x8;

 hfdcan2.Init.NominalTimeSeg1 = 0x1F; /* NominalTimeSeg1 = Propagation_segment + Phase_segment_1 */

 hfdcan2.Init.NominalTimeSeg2 = 0x8;

 hfdcan2.Init.DataPrescaler = 0x1;

 hfdcan2.Init.DataSyncJumpWidth = 0x4;

 hfdcan2.Init.DataTimeSeg1 = 0x5; /* DataTimeSeg1 = Propagation_segment + Phase_segment_1 */

 hfdcan2.Init.DataTimeSeg2 = 0x4;

 hfdcan2.Init.MessageRAMOffset = 0;

 hfdcan2.Init.StdFiltersNbr = 1;

 hfdcan2.Init.ExtFiltersNbr = 1;

 hfdcan2.Init.RxFifo0ElmtsNbr = 1;

 hfdcan2.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_8;

 hfdcan2.Init.RxFifo1ElmtsNbr = 2;

 hfdcan2.Init.RxFifo1ElmtSize = FDCAN_DATA_BYTES_8;

 hfdcan2.Init.RxBuffersNbr = 1;

 hfdcan2.Init.RxBufferSize = FDCAN_DATA_BYTES_8;

 hfdcan2.Init.TxEventsNbr = 2;

 hfdcan2.Init.TxBuffersNbr = 1;

 hfdcan2.Init.TxFifoQueueElmtsNbr = 2;

 hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;

 hfdcan2.Init.TxElmtSize = FDCAN_DATA_BYTES_8;

 if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK)

 {

  Error_Handler();

HAL_Delay(100);

 }

///* Configure Rx filter */

 sFilterConfig.IdType = FDCAN_STANDARD_ID;

 sFilterConfig.FilterIndex = 0;

 sFilterConfig.FilterType = FDCAN_FILTER_MASK;

 sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;

 sFilterConfig.FilterID1 = 0x00;

 sFilterConfig.FilterID2 = 0x00;

 if (HAL_FDCAN_ConfigFilter(&hfdcan2, &sFilterConfig) != HAL_OK)

 {

  /* Filter configuration Error */

HAL_Delay(100);

  Error_Handler();

 }

HAL_FDCAN_ConfigFifoWatermark(&hfdcan2,FDCAN_FILTER_TO_RXFIFO0,2);

if (HAL_FDCAN_ActivateNotification(&hfdcan2, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK)

 {

  /* Notification Error */

  Error_Handler();

HAL_Delay(100);

 }

  /* Start the FDCAN module */

 if (HAL_FDCAN_Start(&hfdcan2) != HAL_OK)

 {

  /* Start Error */

  Error_Handler();

HAL_Delay(100);

 }

// /* Configure Tx buffer message */

 TxHeader.Identifier = 0x601;

 TxHeader.IdType = FDCAN_STANDARD_ID;

 TxHeader.TxFrameType = FDCAN_DATA_FRAME;

 TxHeader.DataLength = FDCAN_DLC_BYTES_8;

 TxHeader.ErrorStateIndicator = FDCAN_ESI_ACTIVE;

 TxHeader.BitRateSwitch = FDCAN_BRS_OFF;

 TxHeader.FDFormat = FDCAN_CLASSIC_CAN;

 TxHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS;

 TxHeader.MessageMarker =0x00;     //0x52;

}

srikanth
Associate III

can kernal clock is 80MHZ