Flexcan function implement based on S32k358

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Flexcan function implement based on S32k358

825 Views
BillWen
Contributor II

Hi everyone:

First of all, my purpose is implement the can function on s32k358, and I am trying to modify by Can_Example_S32K358 for now. This example is can internal loopback test, I want to use it to modify to Can sent message then use PCAN-VIEW to check can message if the can sent message successful.

I already create the port configuration for VCU_CAN, pin "PTB0" & "PTB1", and the following is my main function, I can't get message by PCAN-VIEW, do anyone have idea or experience on this, I really need some help for this, thanks.

 

int main(void) 
{
    uint8 u8TimeOut = 100U;
    CanIf_bTxFlag = FALSE;
    CanIf_bRxFlag = FALSE;
    /* Initialize the Mcu driver */
#if (MCU_PRECOMPILE_SUPPORT == STD_ON)
    Mcu_Init(NULL_PTR);
#elif (MCU_PRECOMPILE_SUPPORT == STD_OFF)
    Mcu_Init(&Mcu_Config_VS_0);
#endif /* (MCU_PRECOMPILE_SUPPORT == STD_ON) */
    /* Initialize the clock tree and apply PLL as system clock */
    Mcu_InitClock(McuConf_McuModeSettingConf_McuModeSettingConf_0);
 
    /* Initialize all pins using the Port driver */
    Port_Init(NULL_PTR);
 
    /* Initialize CanIf driver */
    CanIf_Init(NULL_PTR);
 
 
#if (MCU_NO_PLL == STD_OFF)
    while ( MCU_PLL_LOCKED != Mcu_GetPllStatus() )
    {
        /* Busy wait until the System PLL is locked */
    }
 
    Mcu_DistributePllClock();
#endif
 
    Mcu_SetMode(McuModeSettingConf_0);
 
    /* Initialize Platform driver */
    Platform_Init(NULL_PTR);  
    static Can_PduType Can_PduInfo;
    
    /* Can_CreatePduInfo(id, swPduHandle,length, sdu) */
    Can_PduInfo = Can_CreatePduInfo(0U, 0U, 8U, Can_au8Sdu8bytes);
    /* Initilize Can driver */
#if (CAN_43_FLEXCAN_PRECOMPILE_SUPPORT == STD_ON)
    Can_43_FLEXCAN_Init(NULL_PTR);
#else
    Can_43_FLEXCAN_Init(&Can_43_FLEXCAN_Config_VS_0);
#endif
    Can_43_FLEXCAN_SetControllerMode(CanController_0, CAN_CS_STARTED);
    while(count<20)
    {
        if((Can_43_FLEXCAN_Write(CanHardwareObject_1, &Can_PduInfo) == E_OK))
        {
            /* Wait until the message is successfully sent */
            //while(!CanIf_bTxFlag)
            while((!CanIf_bTxFlag) && (u8TimeOut != 0U))
            {
                Can_43_FLEXCAN_MainFunction_Write();
                Can_DummyDelay(100U); /* Optional delay */
                u8TimeOut--;
            }
            /* Reset the flag for the next transmission */
            CanIf_bTxFlag = FALSE;
 
            count++;
        }
        Can_DummyDelay(1000U);
    }
 
    Can_43_FLEXCAN_SetControllerMode(CanController_0, CAN_CS_STOPPED);
    Can_43_FLEXCAN_DeInit();
 
    Exit_Example((CanIf_bTxFlag && CanIf_bRxFlag) == TRUE);
    
    return (0U);
}
 
 
 
Thanks
BR, BillWen
0 Kudos
Reply
5 Replies

767 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @BillWen,

If the FlexCAN module is being configured as loopback, you will not see anything on the pins. The module needs to be configured for normal/user operation. Also, please confirm if the CAN transceiver need to be configured firstly in your board, there are various demo codes in the community to use as reference: 

Also check if the PCAN-VIEW is configured with the correct values for baud rate, sampling point, etc. 

Best regards,
Julián

 

 

0 Kudos
Reply

752 Views
BillWen
Contributor II

Hi Julian : 

Thanks for your reply.

Now, I can get CAN message from PCAN-VIEW by "Phy_665a_example_S32K358_CANFD_DS/Phy_665a_example_S32K358_CANFD_DS" this example code. So my purpose is set up a new can function in new project.

I already set up the Dio, platform, Port, Mcu, Can_43_flexcan, these MCAL setting, but still cannot get signal. Do you know what else I need to set? I use BJB_CAN to test, so I think I don't need to set up the SPI, right?

 

If you have any idea, please tell me, thanks a lot.

 

Thanks

BR, BillWen

0 Kudos
Reply

735 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @BillWen,

Are you using the evaluation boards for this example? Please keep in mind the connections for this project:

Julin_AragnM_0-1724350373351.png

The CAN bus is configured at 500kbps and a CAN ID of 4. If you are using BJB_CAN, then SPI is not needed. Could you clarify what are you referring to when saying "cannot get signal"? 

Are you unable to send or receive messages with the MCU? Or the PCAN tool? 

Best regards,
Julián

 

0 Kudos
Reply

720 Views
BillWen
Contributor II

Hi Julian:

Thanks for your reply.

My hardware environment is the following EVB board, and pin define is S32K358_172MQFP

 

BillWen_0-1724373294662.png

1. I can use "Phy_665a_example_S32K358_CANFD_DS" this example code to sent Can tx message by BJB_CAN, and I can get signal from PCAN-VIEW can analyzer.

2. I want to create a can function just like "Phy_665a_example_S32K358_CANFD_DS" on a new project, so I need to create port, platform, canif, Dio, Flexcan... setting. After I create these MCAL setting, I can't get can signal by can analyzer

3. About the Can transceiver work on normal mode, I only need to write "Dio_WriteChannel(DioConf_DioChannel_BJB_CAN_STBY, STD_LOW)" if I want to use BJB_CAN, right?

 

What information I need to provide to you and let you help me to figure out what's the problem? I stuck here for many days, please help me, thanks.

 

Thanks a lot

BR, BIll

 

0 Kudos
Reply

698 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @BillWen,

Yes, in order to enable the CAN transceiver, the BJB CAN Standby pin needs to be driven to low. Also, keep in mind that a small delay is added after initializing the transceiver:

    Dio_WriteChannel(DioConf_DioChannel_BJB_CAN_STBY, STD_LOW);
    OsIf_Wait(500U);

    /* Initialize CanIf driver */
    CanIf_Init(NULL_PTR);

    /* Initialize Can driver */
    Can_43_FLEXCAN_Init(NULL_PTR);

If you are not specifically using the MC33665ACANFDEVB, you can also use the Can_Example_S32K358 from the RTD package, which does configure the CAN instance as loopback, but you can change it back to user mode and test it with the analyzer.

If this is still not working, please double-check the FlexCAN configuration differences between your project and the Phy_665a_example_S32K358_CANFD_DS. You can also share your project through here (or private message) to compare the differences in configuration.

Best regards,
Julián

0 Kudos
Reply