S32K144 RX FIFO CAN Receiving via polling

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

S32K144 RX FIFO CAN Receiving via polling

ソリューションへジャンプ
454件の閲覧回数
Kunal_Gettobyte
Contributor III

Hi i am using S32K144 microcontroller and using CAN0 in Rx FIFO mode. I want to create a demo example code in which i want to receive CAN data in Rx FIFO mode via Interrupts.

Rx FIFO is configured, in 8 Rx FiFo Filter and Format A configurations. 

 

These are my configurations:

Kunal_Gettobyte_0-1718387751460.png

 

Motive is to create a simple CAN Rx FiFo Demo code in which am receiving CAN data via Rx FIFO polling mechanism.

 

/*!
** @file main.c
** @brief
**         Main module.
**         This module contains user's application code.
*/
/*!
**  @addtogroup main_module main module documentation
**  @{
*/
/* MODULE main */


/* Including necessary configuration files. */
#include "Mcal.h"
#include "Clock_Ip.h"
#include "FlexCAN_Ip.h"
#include "Port.h"


#define MSG_ID 800u
#define TX_MB_IDX 0U


void TestDelay(uint32 delay);
void TestDelay(uint32 delay)
{
   static volatile uint32 DelayTimer = 0;
   while(DelayTimer<delay)
   {
       DelayTimer++;
   }
   DelayTimer=0;
}


int main(void)
{
	Flexcan_Ip_StatusType FlexCAN_Api_Status;
    /* Write your code here */
    Clock_Ip_Init(&Mcu_aClockConfigPB[0]);

#if defined (FEATURE_CLOCK_IP_HAS_SPLL_CLK)
    while ( CLOCK_IP_PLL_LOCKED != Clock_Ip_GetPllStatus() )
    {
        /* Busy wait until the System PLL is locked */
    }
    Clock_Ip_DistributePll();
#endif

    /* Initialize all pins using the Port driver */
    Port_Init(NULL_PTR);

    Flexcan_Ip_DataInfoType rx_info = {
            .msg_id_type = FLEXCAN_MSG_ID_STD,
            .data_length = 8u,
            .is_polling = TRUE,
            .is_remote = FALSE
    };
    Flexcan_Ip_IdTableType x[8] = {


    		{
    		.isRemoteFrame = FALSE,
			.isExtendedFrame = FALSE,
			.id = 0x320
    		},
			{
			.isRemoteFrame = FALSE,
			.isExtendedFrame = FALSE,
			.id = 0x330
			 },
			 {
			.isRemoteFrame = FALSE,
			.isExtendedFrame = FALSE,
			.id = 0x340
			 },
			 {
			.isRemoteFrame = FALSE,
			.isExtendedFrame = FALSE,
			.id = 0x350
			 },
			 {
			.isRemoteFrame = FALSE,
			.isExtendedFrame = FALSE,
			.id = 0x360
			 },
			 {
			.isRemoteFrame = FALSE,
			.isExtendedFrame = FALSE,
			.id = 0x370
			 },

			 {
			.isRemoteFrame = FALSE,
			.isExtendedFrame = FALSE,
			.id = 0x380
			 },

			 {
			.isRemoteFrame = FALSE,
			.isExtendedFrame = FALSE,
			.id = 0x390
			 }

    };

    Flexcan_Ip_MsgBuffType y;

    FlexCAN_Api_Status = FlexCAN_Ip_EnterFreezeMode_Privileged(INST_FLEXCAN_0);

    FlexCAN_Ip_Init(INST_FLEXCAN_0, &FlexCAN_State0, &FlexCAN_Config0);

    FlexCAN_Api_Status = FlexCAN_Ip_SetStartMode(INST_FLEXCAN_0);

    for(;;)
   {

// Entering into Freeze Mode so that can do Rx FiFo Configurations
       FlexCAN_Api_Status = FlexCAN_Ip_EnterFreezeMode_Privileged(INST_FLEXCAN_0);

// Doing Rx FiFo Configuration and settings its filter table for CAN acceptance critaria
	   FlexCAN_Api_Status = FlexCAN_Ip_ConfigRxFifo_Privileged(INST_FLEXCAN_0, FLEXCAN_RX_FIFO_ID_FORMAT_A, &x);

// Using Blocking function, to wait till some CAN data is received
	   FlexCAN_Api_Status = FlexCAN_Ip_RxFifoBlocking(INST_FLEXCAN_0, &y, 10000);

   }

    return 0;
}

/* END main */
/*!
** @}
*/

 

 

But using the above chronology of API and API, it is not working though i am sending data from my can analyzer tool, but no data is received, and it always gives timeout FlexCAN_Ip_RxFiFoBlocking API.

So Below questions are there:

1) Is chronology of my API's correct to receive data in RxFiFo via polling method?If not, what is the mistake I have done and what should be corrected one?

2) Do i have to terminate from freeze mode before receiving the CAN data? Is it because my system is still in freeze mode because of which no CAN data is able to receive?

3) We can use RxFiFo in polling way? As there is configuration feature in tool and also RxFiFoBlocking API? So, what should be set of APIS to use that feature?

Would be waiting to get reply and knowledge!!

 

 

 

 

 

0 件の賞賛
返信
1 解決策
428件の閲覧回数
Kunal_Gettobyte
Contributor III

Issue is solved.

 

My chronology of API's is wrong that is causing the issue. FlexCAN_Ip_ConfigRxFifo_Privileged() API should be used before starting the CAN module FlexCAN_Ip_SetStartMode().

 

Updated code is:

  Flexcan_Ip_MsgBuffType y;

  //  FlexCAN_Api_Status = FlexCAN_Ip_EnterFreezeMode_Privileged(INST_FLEXCAN_0);


    FlexCAN_Ip_Init(INST_FLEXCAN_0, &FlexCAN_State0, &FlexCAN_Config0);

    FlexCAN_Api_Status = FlexCAN_Ip_ConfigRxFifo_Privileged(INST_FLEXCAN_0, FLEXCAN_RX_FIFO_ID_FORMAT_A, &x);

    FlexCAN_Api_Status = FlexCAN_Ip_SetStartMode(INST_FLEXCAN_0);

    for(;;)
   {
//    FlexCAN_Api_Status = FlexCAN_Ip_EnterFreezeMode_Privileged(INST_FLEXCAN_0);

	  // FlexCAN_Api_Status = FlexCAN_Ip_ConfigRxFifo_Privileged(INST_FLEXCAN_0, FLEXCAN_RX_FIFO_ID_FORMAT_A, &x);
	   FlexCAN_Api_Status = FlexCAN_Ip_RxFifoBlocking(INST_FLEXCAN_0, &y, 10000);


   }

    return 0;
}

元の投稿で解決策を見る

0 件の賞賛
返信
1 返信
429件の閲覧回数
Kunal_Gettobyte
Contributor III

Issue is solved.

 

My chronology of API's is wrong that is causing the issue. FlexCAN_Ip_ConfigRxFifo_Privileged() API should be used before starting the CAN module FlexCAN_Ip_SetStartMode().

 

Updated code is:

  Flexcan_Ip_MsgBuffType y;

  //  FlexCAN_Api_Status = FlexCAN_Ip_EnterFreezeMode_Privileged(INST_FLEXCAN_0);


    FlexCAN_Ip_Init(INST_FLEXCAN_0, &FlexCAN_State0, &FlexCAN_Config0);

    FlexCAN_Api_Status = FlexCAN_Ip_ConfigRxFifo_Privileged(INST_FLEXCAN_0, FLEXCAN_RX_FIFO_ID_FORMAT_A, &x);

    FlexCAN_Api_Status = FlexCAN_Ip_SetStartMode(INST_FLEXCAN_0);

    for(;;)
   {
//    FlexCAN_Api_Status = FlexCAN_Ip_EnterFreezeMode_Privileged(INST_FLEXCAN_0);

	  // FlexCAN_Api_Status = FlexCAN_Ip_ConfigRxFifo_Privileged(INST_FLEXCAN_0, FLEXCAN_RX_FIFO_ID_FORMAT_A, &x);
	   FlexCAN_Api_Status = FlexCAN_Ip_RxFifoBlocking(INST_FLEXCAN_0, &y, 10000);


   }

    return 0;
}
0 件の賞賛
返信