1934384_en-US

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

1934384_en-US

1934384_en-US

S32K3 FlexCan in Polling mode

Hello, 

Im trying to set up the CAN on S32K3, I did not found an example based on polling (not interrupts), using RTD and no Autosar, I did the following config :

Pins used are PTA28 – PTA27 (CAN-0)

Kazarian_0-1723987822402.png


Standard CAN with 500Kb – 8 bytes payload

Kazarian_1-1723987847508.png

Clock for CAN enabled

Kazarian_2-1723987869097.png


FlexCan_Send function will execute successfully only once, after that the bus goes into busy state and will not transmit any CAN frame, after adding   FlexCAN_Ip_AbortTransfer seems to work, but im not sure if this was the correct approach ?



Flexcan_Ip_StatusType FlexCan_Send(uint16_t Idx, uint8_t *data)
{
       Flexcan_Ip_StatusType retVal = E_NOT_OK;

       Flexcan_Ip_DataInfoType tx_info =
       {
             .msg_id_type = FLEXCAN_MSG_ID_STD,
             .data_length = 8u,
             .is_polling = FALSE,             /* Specifies if the MB is in polling mode */
             .is_remote = FALSE,              /* Specifies if the frame is standard or remote */
       };

       if(FlexCAN_Ip_GetTransferStatus(INST_BOARD_INITPERIPHERALS_FLEXCAN_0, TX_MB_IDX) == FLEXCAN_STATUS_BUSY)
       {
             FlexCAN_Ip_AbortTransfer(INST_BOARD_INITPERIPHERALS_FLEXCAN_0, TX_MB_IDX);
       }

       retVal = FlexCAN_Ip_Send(INST_BOARD_INITPERIPHERALS_FLEXCAN_0,TX_MB_IDX,&tx_info, Idx, &data[0]);

       return retVal;
}


A Task runs each 5ms for reading the CAN frames in polling mode, the FlexCAN_Ip_Receive keep returning Status_Busy


__attribute__((__noreturn__)) void Can_Polling_Tsk_5ms( void *pvParameters )
{
	(void)pvParameters;

	for( ;; )
	{
		FlexCan_Read();
		vTaskDelay(pdMS_TO_TICKS(5));
	}
}

Flexcan_Ip_StatusType FlexCan_Read()
{
       Flexcan_Ip_StatusType retVal = E_NOT_OK;
       Flexcan_Ip_MsgBuffType recvBuff;


       retVal = FlexCAN_Ip_Receive(INST_BOARD_INITPERIPHERALS_FLEXCAN_0, RX_MB_IDX, &recvBuff, TRUE);

       if(retVal == FLEXCAN_STATUS_SUCCESS)
       {
             // Process the received frame...
       }

       return retVal;
}

Thank you.

Re: S32K3 FlexCan in Polling mode

Hi @Kazarian,

Sorry for the late reply. You can refer to this community post: S32K1xx-FlexCAN Mask Setting Demo - NXP Community. It does refer to the S32K1xx, but the theory is the same.

You must call the functions below in stop or freeze mode.

FlexCAN_Ip_SetRxMaskType();
FlexCAN_Ip_SetRxMbGlobalMask();

This community post may also prove helpful: Solved: S32K344 FlexCAN: How to setup Rx MB mask to receive the CAN FD messages with different IDs? ....

Best regards,
Julián 

Re: S32K3 FlexCan in Polling mode

Hello @Julián_AragónM 

Any idea how you can set the RX filter for a range of IDs ?

Regards.

Re: S32K3 FlexCan in Polling mode

Thanks a lot @Julián_AragónM this works, 

There is another question on how to enable the reception of all Ids not only the ID configured with the function FlexCAN_Ip_ConfigRxMb :


retVal |= FlexCAN_Ip_ConfigRxMb(INST_BOARD_INITPERIPHERALS_FLEXCAN_0, RX_MB_IDX, &rx_info, MSG_ID);

is there a function where i can set a kind of mask across a range of Ids i want to receive, say for example from 0x10 to 0x74D.


Regards.

Re: S32K3 FlexCan in Polling mode

Hi @Kazarian,

I understand you are creating your own functions implementing the RTD. Even though it is working, the abort mechanism provides a safe way to request the abortion of a pending transmission. A feedback mechanism is provided to inform the CPU whether the transmission was aborted, or the frame could not be aborted and was transmitted instead.

There is an existing polling example (although it is based in S32K312) in the following community post: Example S32K312 CAN Transmit & Receive Using Polling mode DS3.5 RTD300 - NXP Community.

It implements both write and read in polling mode like this:

    rx_info.is_polling = TRUE; //Dinesh
    FlexCAN_Ip_Send(INST_FLEXCAN_0, TX_MB_IDX, &rx_info, MSG_ID, (uint8 *)&dummyData);
    // Polling
    while(FlexCAN_Ip_GetTransferStatus(INST_FLEXCAN_0, TX_MB_IDX) != FLEXCAN_STATUS_SUCCESS)
    {
    	FlexCAN_Ip_MainFunctionWrite(INST_FLEXCAN_0, TX_MB_IDX);
    }

    // Polling
    while(FlexCAN_Ip_GetTransferStatus(INST_FLEXCAN_0, RX_MB_IDX) != FLEXCAN_STATUS_SUCCESS)
    {
    	FlexCAN_Ip_MainFunctionRead(INST_FLEXCAN_0, RX_MB_IDX);
    }

Nevertheless, if your configuration is working, there should be no problem.

Best regards,
Julián

タグ(1)
評価なし
バージョン履歴
最終更新日:
‎11-21-2025 12:20 PM
更新者: