Skip to main content
Explorer
April 17, 2024
Solved

MB1549-U575ZIQ-C03 Board ,FDCAN don't work at FDCAN_MODE_NORMAL

  • April 17, 2024
  • 6 replies
  • 1404 views

board:MB1549-U575ZIQ-C03  (mcu stm32U575)

I debug the FDCNA function with a CANalyst tool 

1. Work at FDCAN_MODE_BUS_MONITORING mode, It can receive data from the CANalyst tool 

2. Work at FDCAN_MODE_EXTERNAL_LOOPBACK,It can receive data itself and the canslyst tool can receive the data

3. Work at FDCAN_MODE_NORMAL, It cann't receive data,and send data fail 

void MX_FDCAN1_Init(void)

{

hfdcan1.Instance = FDCAN1;

hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1;

hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;

hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;

hfdcan1.Init.AutoRetransmission = DISABLE;

hfdcan1.Init.TransmitPause = DISABLE;

hfdcan1.Init.ProtocolException = DISABLE;

hfdcan1.Init.NominalPrescaler = 32;

hfdcan1.Init.NominalSyncJumpWidth = 1;

hfdcan1.Init.NominalTimeSeg1 = 2;

hfdcan1.Init.NominalTimeSeg2 = 2;

hfdcan1.Init.DataPrescaler = 1;

hfdcan1.Init.DataSyncJumpWidth = 1;

hfdcan1.Init.DataTimeSeg1 = 1;

hfdcan1.Init.DataTimeSeg2 = 1;

hfdcan1.Init.StdFiltersNbr = 0;

hfdcan1.Init.ExtFiltersNbr = 0;

hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_QUEUE_OPERATION;

if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)

{

Error_Handler();

}

#if 1

FDCAN_FilterTypeDef FDCAN1_RXFilter;

FDCAN1_RXFilter.IdType=FDCAN_STANDARD_ID;

FDCAN1_RXFilter.FilterIndex=0;

FDCAN1_RXFilter.FilterType=FDCAN_FILTER_RANGE;

FDCAN1_RXFilter.FilterConfig=FDCAN_FILTER_TO_RXFIFO0;

FDCAN1_RXFilter.FilterID1=0x0000;

FDCAN1_RXFilter.FilterID2=0x0000;

if(HAL_FDCAN_ConfigFilter(&hfdcan1,&FDCAN1_RXFilter)!=HAL_OK)

{

Error_Handler();

}





HAL_FDCAN_Start(&hfdcan1);

HAL_FDCAN_ActivateNotification(&hfdcan1,FDCAN_IT_RX_FIFO0_NEW_MESSAGE,0);

#endif



/* USER CODE END FDCAN1_Init 2 */



}



void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle)

{



GPIO_InitTypeDef GPIO_InitStruct = {0};

RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};

if(fdcanHandle->Instance==FDCAN1)

{

/* USER CODE BEGIN FDCAN1_MspInit 0 */



/* USER CODE END FDCAN1_MspInit 0 */



/** Initializes the peripherals clock

*/

PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_FDCAN1;

PeriphClkInit.Fdcan1ClockSelection = RCC_FDCAN1CLKSOURCE_PLL1;

if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)

{

Error_Handler();

}

/* FDCAN1 clock enable */

__HAL_RCC_FDCAN1_CLK_ENABLE();



__HAL_RCC_GPIOD_CLK_ENABLE();

/**FDCAN1 GPIO Configuration

PD0 ------> FDCAN1_RX

PD1 ------> FDCAN1_TX

*/

GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;

GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

GPIO_InitStruct.Pull = GPIO_PULLUP;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;

GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1;

HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);



/* FDCAN1 interrupt Init */

HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 4, 0);

HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn);

/* USER CODE BEGIN FDCAN1_MspInit 1 */



/* USER CODE END FDCAN1_MspInit 1 */

}

}

uint8_t FDCAN1_Send_Msg(uint8_t* msg)

{



fdcan1_TxHeader.Identifier = 0x001;

fdcan1_TxHeader.IdType = FDCAN_STANDARD_ID;

fdcan1_TxHeader.TxFrameType = FDCAN_DATA_FRAME;

fdcan1_TxHeader.DataLength = FDCAN_DLC_BYTES_8;

fdcan1_TxHeader.ErrorStateIndicator = FDCAN_ESI_ACTIVE;

fdcan1_TxHeader.BitRateSwitch = FDCAN_BRS_OFF;

fdcan1_TxHeader.FDFormat = FDCAN_CLASSIC_CAN;

fdcan1_TxHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS;

fdcan1_TxHeader.MessageMarker = 0x52;



if(HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan1,&fdcan1_TxHeader,msg)!=HAL_OK) return 1;//发送

return 0;

}

void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)

{

/* Prevent unused argument(s) compilation warning */

UNUSED(hfdcan);

UNUSED(RxFifo0ITs);



if((RxFifo0ITs & FDCAN_IT_RX_FIFO0_NEW_MESSAGE) != RESET)

{

/* Retrieve Rx messages from RX FIFO0 */

memset(RxData, 0, sizeof(RxData));

if (HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &RxHeader, RxData) != HAL_OK)

{

Error_Handler();

}
}
}

 

    This topic has been closed for replies.
    Best answer by dylanou

    Thand you for your reply

    I find the cause of the problem

    The transceiver need to power of 5V, but I only provide 3.3V

    6 replies

    dylanouAuthor
    Explorer
    April 17, 2024

     

    hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;   // can not work

     

    hfdcan1.Init.Mode = FDCAN_MODE_BUS_MONITORING;   //  work well

     

    hfdcan1.Init.Mode = FDCAN_MODE_EXTERNAL_LOOPBACK;   //  work well

     

    Technical Moderator
    April 17, 2024

    Hello,

    1. Are you using a transceiver with another CAN node connected to the bus?  if it's not the case it won't work.
    2. These values are not recommended for CAN bit time settings::
      hfdcan1.Init.NominalPrescaler = 32;
      hfdcan1.Init.NominalTimeSeg1 = 2;
      hfdcan1.Init.NominalTimeSeg2 = 2

      See my answer in this thread.

    dylanouAuthor
    Explorer
    April 18, 2024

    Are you using a transceiver with another CAN node connected to the bus?

    1. had can  transceiver

    dylanou_0-1713402314461.png

     

    dylanouAuthor
    Explorer
    April 18, 2024

    work at FDCAN_MODE_BUS_MONITORING or  FDCAN_MODE_EXTERNAL_LOOPBACK ,It can receive or send data

    dylanouAuthor
    Explorer
    April 18, 2024
     
     

    config.png

    dylanouAuthor
    Explorer
    April 18, 2024

    I change below,but it doesn't work too

    hfdcan1.Instance = FDCAN1;
    
    hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV10;
    
    hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
    
    hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
    
    hfdcan1.Init.AutoRetransmission = DISABLE;
    
    hfdcan1.Init.TransmitPause = DISABLE;
    
    hfdcan1.Init.ProtocolException = DISABLE;
    
    hfdcan1.Init.NominalPrescaler = 2;
    
    hfdcan1.Init.NominalSyncJumpWidth = 1;
    
    hfdcan1.Init.NominalTimeSeg1 = 12;
    
    hfdcan1.Init.NominalTimeSeg2 = 3;
    
    hfdcan1.Init.DataPrescaler = 1;
    
    hfdcan1.Init.DataSyncJumpWidth = 1;
    
    hfdcan1.Init.DataTimeSeg1 = 1;
    
    hfdcan1.Init.DataTimeSeg2 = 1;
    
    hfdcan1.Init.StdFiltersNbr = 0;
    
    hfdcan1.Init.ExtFiltersNbr = 0;
    Technical Moderator
    April 18, 2024

    Hello,

    1. had can transceiver -> Need to provide more details about your transceiver's module: the transceiver datasheet + module schematics as this is an important point for analysis.
    2. work at FDCAN_MODE_BUS_MONITORING or FDCAN_MODE_EXTERNAL_LOOPBACK ,It can receive or send data. -> Expected behavior if there is a HW issue (external from the MCU: wiring, transceiver issue, clock source, not the correct CAN pins assigned etc ..) the CAN won't work. Loopback and Monitoring are less restrictive.
    3. Need to monitor CAN_Rx (Not CAN_H nor CAN_L) with an oscilloscope or logic analyzer. Do you see CAN activity on CAN_Rx?
    4. You need also to share your project (at least the ioc file)

    PS: please use </> button to insert your code.

    dylanouAuthorAnswer
    Explorer
    April 19, 2024

    Thand you for your reply

    I find the cause of the problem

    The transceiver need to power of 5V, but I only provide 3.3V