Flexcan function implement based on S32k358

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

Flexcan function implement based on S32k358

2,054 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
12 Replies

1,996 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

1,981 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

1,964 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

1,949 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

1,927 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

916 Views
Shivanand
Contributor II

Hello @Julián_AragónM.
Im also working on RD-K358BMU, im trying to implement can standard transmit using cmu can, the transmission being successful once but i can't see in can analyzer and next it goes into busy state. Please could you help?



 Dio_WriteChannel(DioConf_DioChannel_CMU_CAN_STBY, STD_LOW);
    
 for (int i=0;i<100000;i++);
    
 CanIf_Init(NULL_PTR);
 
Can_43_FLEXCAN_Init(&Can_43_FLEXCAN_Config_VS_0);
 
Can_43_FLEXCAN_SetControllerMode(CMU_CAN,CAN_CS_STARTED);
 
Can_43_FLEXCAN_EnableControllerInterrupts(CMU_CAN);
 
 
 
void can_test()
{
 
volatile Std_ReturnType RetVal = FLEXCAN_STATUS_ERROR;
 
Can_datasend.SduDataPtr=can_tx_data_arr;
Can_datasend.SduLength=sizeof(can_tx_data_arr);
 
while(1)
{
RetVal=CanIf_Transmit(CMU_CAN,&Can_datasend);
 
if (RetVal == FLEXCAN_STATUS_SUCCESS)
printf("Success:%d\r\n",RetVal);
 
else if (RetVal == FLEXCAN_STATUS_ERROR)
printf("CAN tx failed:%d\r\n",RetVal);
 
else if (RetVal == FLEXCAN_STATUS_BUSY)
printf("CAN tx Busy:%d\r\n",RetVal);
vTaskDelay(1000);
}
 
}
0 Kudos
Reply

911 Views
BillWen
Contributor II
Hi Shivanand:
I'm not NXP TechSupport. Just my experience and suggestion.
Is your CMU can transceiver TJA1443?
Because I check the TJA1443 data sheet, I think standby pin should be high if the chip is in Normal mode.
I also use this can, but I think my function is work.
You can try this
Dio_WriteChannel(DioConf_DioChannel_CMU_CAN_STBY, STD_HIGH);

Thanks
BR, BillWen
0 Kudos
Reply

908 Views
Shivanand
Contributor II

Hi @BillWen 

I have tried making the pin High, still it is not working. could you send your reference project

 

0 Kudos
Reply

867 Views
BillWen
Contributor II
Hi Shivanand:
I think you can try the following code, it should be work, if not, maybe there are some problems on your MCAL setting.

void can_test(void)
{
uint8 canData[8] = {0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89};
Can_PduType Can_PduInfo;

Can_PduInfo.id = 0x444;
Can_PduInfo.swPduHandle = 0U;
Can_PduInfo.length = 8U;
Can_PduInfo.sdu = canData;

while(1)
{
Can_43_FLEXCAN_Write(CanHardwareObject_CMU_TX, &Can_PduInfo);
}

}
Thanks
BR, BillWen
0 Kudos
Reply

862 Views
Shivanand
Contributor II

Hello @BillWen

Yes, please could you help me with MCAL settings .

 

0 Kudos
Reply

818 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @Shivanand,

Both TJA1153 and TJA1443 are pin compatible, the only difference is the ERROR pin in the TJA1443. The previous example I mentioned in this thread (Example S32K344 FlexCAN_Ip TX/RX/EnhanceRXFIFO test S32DS3.4 RTD200 - NXP Community.) configures the TJA1153 with the setupCanXCVR function.

TJA1443 does not require any special initialization, it has 2 control pins, EN and STB_N, which are used to switch between device modes.

You can still use the previously mentioned project or look into the community for other projects.  This following community post shows the full configuration of the project with a TJA1443: Solved: FlexCAN driver (on S32K3X4EVB-T172 EVB) can't access via PCAN - NXP Community.

Hope this helps

0 Kudos
Reply

797 Views
Shivanand
Contributor II

Hello @Julián_AragónM 

I have checked the TJA1463 configuration; its fine, but I'm unable to transmit data through CAN. Is there any issue with the code part?

0 Kudos
Reply