cancel
Showing results for 
Search instead for 
Did you mean: 

How to send data via CANFD from stm32H753AI to PC?

PHumm.1
Associate

Hello,

i am pretty new to this topic. I want to send simple data via CANFD from the stm32H/53AI to a PC. For that i have the CANFD-USB adapter from PEAK and to display the data i am using PCAN-View. I discovered the function and i put in the addresses to the fdcan and header initialization and the data i want to send: HAL_FDCAN_AddMessageT oTxFifoQ(&hfdcan1, &TxHeader, TxData)

  hfdcan1.Instance = FDCAN1;
  hfdcan1.Init.FrameFormat = FDCAN_FRAME_FD_BRS;
  hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
  hfdcan1.Init.AutoRetransmission = ENABLE;
  hfdcan1.Init.TransmitPause = DISABLE;
  hfdcan1.Init.ProtocolException = DISABLE;
  hfdcan1.Init.NominalPrescaler = 0x1;
  hfdcan1.Init.NominalSyncJumpWidth = 0x10;
  hfdcan1.Init.NominalTimeSeg1 = 0x3F;
  hfdcan1.Init.NominalTimeSeg2 = 0x10;
  hfdcan1.Init.DataPrescaler = 0x1;
  hfdcan1.Init.DataSyncJumpWidth = 0x04;
  hfdcan1.Init.DataTimeSeg1 = 0xF;
  hfdcan1.Init.DataTimeSeg2 = 0x4;
  hfdcan1.Init.MessageRAMOffset = 0;
  hfdcan1.Init.StdFiltersNbr = 1;
  hfdcan1.Init.ExtFiltersNbr = 0;
  hfdcan1.Init.RxFifo0ElmtsNbr = 0;
  hfdcan1.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_12;
  hfdcan1.Init.RxFifo1ElmtsNbr = 0;
  hfdcan1.Init.RxFifo1ElmtSize = FDCAN_DATA_BYTES_12;
  hfdcan1.Init.RxBuffersNbr = 0;
  hfdcan1.Init.RxBufferSize = FDCAN_DATA_BYTES_12;
  hfdcan1.Init.TxEventsNbr = 32;
  hfdcan1.Init.TxBuffersNbr = 32;
  hfdcan1.Init.TxFifoQueueElmtsNbr = 32;
  hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
  hfdcan1.Init.TxElmtSize = FDCAN_DATA_BYTES_64;
static void HEADER_Init(void){
  TxHeader.Identifier = 0x111;
  TxHeader.IdType = FDCAN_STANDARD_ID;
  TxHeader.TxFrameType = FDCAN_DATA_FRAME;
  TxHeader.DataLength = FDCAN_DLC_BYTES_12;
  TxHeader.ErrorStateIndicator = FDCAN_ESI_ACTIVE;
  TxHeader.BitRateSwitch = FDCAN_BRS_ON;
  TxHeader.FDFormat = FDCAN_FD_CAN;
  TxHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
  TxHeader.MessageMarker = 0;
}

That's the config in the PCAN-View:

0693W00000BZdZiQAL.png 

But when i start the program PCAN-View doesn't receive the message/data . Does anyone has a clue what i am doing wrong?

There is less information about this on the internet therefore i am asking this here...

Thanks!

2 REPLIES 2
SofLit
ST Employee

Hello,

First, you have to check your bitrate config: Nominal & data:

0693W00000BbXniQAF.png 

STM32

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.
TOlli
Senior

Hi @Community member​ 

Try changing these two lines:

hfdcan1.Init.TxEventsNbr = 32;

hfdcan1.Init.TxBuffersNbr = 32;

to

hfdcan1.Init.TxEventsNbr = 0;

hfdcan1.Init.TxBuffersNbr = 0;

You might be crashing your tx because you allocate too many elements of different kinds. And you get rid of these since you are using FIFO.

Other than that, if you have retransmission on, it might be good to have transmit pause on as well.

If the above is not correct, please give more input on your clocks so your prescales and bit timing can be reviewed.

Best regards,

Tero