2025-07-15 10:23 AM - last edited on 2025-07-15 10:50 AM by mƎALLEm
Hi, I made an STM32G4 and TCAN1044VDRQ1 setup and tried to use the FDCAN, but I couldn't get it to work. There is no response from the transceiver. I tried all the bit timings and used calculators to compute the values. I used a USB-to-CAN FD analyzer and sent a message, but there is no response in the HAL_FDCAN_RxFifo0Callback interrupt.
It is not getting triggered when a message comes in. I don’t know what to do. I’ve spent too much time on this. Any help would be appreciated. Thank you. I don’t know what other details I need to share, if you think you need something, please let me know and I’ll send a reply.
void CAN_Init(uint8_t can_id) {
hfdcan1.Instance = FDCAN1;
hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1;
hfdcan1.Init.FrameFormat = FDCAN_FRAME_FD_NO_BRS;
hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
hfdcan1.Init.AutoRetransmission = ENABLE;
hfdcan1.Init.TransmitPause = DISABLE;
hfdcan1.Init.ProtocolException = DISABLE;
hfdcan1.Init.NominalPrescaler = 1;
hfdcan1.Init.NominalSyncJumpWidth = 3;
hfdcan1.Init.NominalTimeSeg1 = 8;
hfdcan1.Init.NominalTimeSeg2 = 3;
hfdcan1.Init.DataPrescaler = 1;
hfdcan1.Init.DataSyncJumpWidth = 3;
hfdcan1.Init.DataTimeSeg1 = 8;
hfdcan1.Init.DataTimeSeg2 = 3;
hfdcan1.Init.StdFiltersNbr = 1;
hfdcan1.Init.ExtFiltersNbr = 0;
hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) Error_Handler();
sFilterConfig.IdType = FDCAN_STANDARD_ID;
sFilterConfig.FilterIndex = 0;
sFilterConfig.FilterType = FDCAN_FILTER_MASK;
sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
sFilterConfig.FilterID1 = can_id;
sFilterConfig.FilterID2 = 0x7FF;
if (HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig) != HAL_OK) Error_Handler();
if (HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_REJECT, FDCAN_REJECT, FDCAN_REJECT_REMOTE, FDCAN_REJECT_REMOTE) != HAL_OK) Error_Handler();
if (HAL_FDCAN_Start(&hfdcan1) != HAL_OK) Error_Handler();
}
2025-07-16 10:18 AM
1. I supplied a both the voltages now
2. STB is connected to GPIO (PC13) and made LOW
3. I know a person who did an arbitration speed of 1mbps and data speed of 8mbps, and tested over 30m distance with jumper wire ribbon cable. This is his board USB-CANFD that doesn't use a external clock.
It's okay i will try it cause my board also doesn't have an HSE and i cant make a new at the moment. If possible can you help with using the internal crystal it's okay if it doesn't work for me in the end i just want to try.
2025-07-16 10:33 AM
@kavinkumar wrote:
3. I know a person who did an arbitration speed of 1mbps and data speed of 8mbps, and tested over 30m distance with jumper wire ribbon cable. This is his board USB-CANFD that doesn't use a external clock.
1- The function will be not guaranteed with HSI. It may present issues over temperature for example..
@kavinkumar wrote:
It's okay i will try it cause my board also doesn't have an HSE and i cant make a new at the moment. If possible can you help with using the internal crystal it's okay if it doesn't work for me in the end i just want to try.
2- Just modify Loopback with Normal in the project I've attached and modify the examle to send to/receive from the USB bridge.
2025-07-16 10:46 AM
Thank you i hanged the model to Normal Mode and made a simple code to send CAN message every with a 1 second delay if you find anything wrong please let me know.
Also i kept all the remaining bit timings same (if you could let me know how to calculated those it will be really helpful)
2025-07-16 10:41 PM - edited 2025-07-16 11:00 PM
Hi @mƎALLEm I tested with the Normal Mode but as soon as i power the TCAN1044 +5v the program freezes and the led blinking is always on (I have a 1 sec delay LED blink inside the while loop to check whether the loop runs but it doesn't) until i remove (Unsolder the CAN transceiver) the program always freezes and as i removed the CAN IC the program works and the LED blinks
Never mind: the IC was damaged changed to a new one
2025-07-16 11:37 PM
@mƎALLEm Didn't work but found something the the program freezes whenever I connect my USB To CAN analyzer. if not it is sending the DATA 3 times and then freezes maybe the TxFifo is getting filled
I have attached my main code other than that everything is from your setup. Thank you
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_FDCAN1_Init();
/* USER CODE BEGIN 2 */
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
void Send_CAN_Message(void)
{
TxHeader.Identifier = 0x444; // Standard ID
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_STORE_TX_EVENTS;
TxHeader.MessageMarker = 0xAB;
if (HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan1, &TxHeader, TxData0) != HAL_OK)
{
Error_Handler();
}
}
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
Send_CAN_Message(); // Send CAN message
HAL_Delay(1000); // Wait 1 second
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_3, GPIO_PIN_RESET);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_3, GPIO_PIN_SET);
HAL_Delay(1000);
}
/* USER CODE END 3 */
}