modify can_pal example (nxp s32144)

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

modify can_pal example (nxp s32144)

Jump to solution
3,176 Views
pierpaolo_dini
Contributor III

Hello, everybody,
I'm new to using the NXP s32k144 and I'm having some difficulties, so I'm hoping someone can help me out.
The goal I need to achieve is actually very simple: with an Arduino I send some messages via CAN protocol (I use an MCP2515 and the mcp2515.h library) and I would like to have NXP read them and check the id and time stamp in order to activate a led if the id is equal to one previously set and save the timestamp in a variable.
Everything is very simple.
The problem is that with the changes made to the can_pal design studio example I can't read any message.

pastedImage_1.png

The one in the picture is the infinite loop I use, everything that was in the loop while I commented it while the rest of the code remained unchanged.

So I wanted to know what should be the way to use the example functions to receive all the id's on the bus and access the timestamp.

Thank you in advance to those who will find the time to answer me.

PS : obviously NXP is powered by external 12Volt.

Tags (3)
0 Kudos
Reply
1 Solution
2,901 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Pierpaolo,

Sorry for my last reply!
The can_pal_s32k144 example is configured Standard ID, so FLEXCAN_MSG_ID_STD should be input instead of CAN_MSG_ID_EXT.
I have test the below codes on S32K144EVB with CAN FD analyzer, it is able to turn on and turn off the LEDs no matter what CAN ID the CAN FD analyzer sent.

CAN_ConfigRxBuff(&can_pal1_instance, RX_MAILBOX, &buffCfg, RX_MSG_ID);
CAN_SetRxFilter(&can_pal1_instance, FLEXCAN_MSG_ID_STD, RX_MAILBOX, 0x0);

For more detail about how CAN_ConfigRxBuff and CAN_SetRxFilter works, please refer the answer in S32K146 CAN receive problem.

CAN_SetRxFilter.png

Best Regards,

Robin

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

6 Replies
2,901 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Pierpaolo Dini,

The can_pal_s32k144 example will check the RX_MSG_ID configured by CAN_ConfigRxBuff(&can_pal1_instance, RX_MAILBOX, &buffCfg, RX_MSG_ID);
If you want to receive all the IDs, please refer the answer in S32K146 CAN receive problem.

About the timestamp, please try to access it by recvMsg.cs.

can_message_t.png

Table 55-10. Message buffer structure — example with 64-byte payload.png

Best Regards,

Robin

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply
2,901 Views
pierpaolo_dini
Contributor III

Hi,
thanks for picking up.

Actually I still have problems reading the ID of the CAN message that I send through Arduino Uno and mcp2515 module.
I must say that I have basic knowledge of C language so most probably I'm missing something trivial.
But in principle it should not be very different from how you can read from Arduino.
Once initialized a suitable structure to save a CAN message, I invoke the "receive" function and save the message just read in that structure (passed for reference).
From the link you suggested I saw that lines of code had to be added.
Anyway I can't print the fields (and probably NXP is not even reading the messages sent by Arduino...).

I modified the code as shown in the picture (I put it on a different text editor to make the screen but clearly I use Design Studio XD).

I have clearly verified that Arduino sends the message it has to send through a Peak (which does nothing but analyze the traffic).

I just wanted to turn on a led when the message read has ID = 0x555 and extract ID and TIMESTAMP.


pastedImage_1.png

PS : I've noticed that in the initialization of the buffer structure there is the enable FD field, but I didn't understand if for FD it's indicated that the message format is CAN-FD type (I use standard CAN so should I put false???).

0 Kudos
Reply
2,901 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

So, only the bits sets are checked, for example, if you set this to 0 all the messages will be received, and depending of the bits set, the corresponding bits will be ignored of the ID.

Please try:

CAN_ConfigRxBuff(&can_pal1_instance, RX_MAILBOX, &buffCfg, 0x555);

CAN_SetRxFilter(&can_pal1_instance, CAN_MSG_ID_EXT, RX_MAILBOX, 0x00000000);

Best Regards,

Robin

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply
2,901 Views
pierpaolo_dini
Contributor III

Hi, thanks again for picking up.
Actually, it gives me the following problem now when I do the debugging procedure.

pastedImage_1.png

I'm sorry but have absolutely no idea what kind of problem this is XD.

Are there some particular pre-settings to do?

Further, I notice that when you invoke the function "CAN_ConfigRxBuff" one of the arguments is the ID 0x555, but this you can write because you know the msg_id. If you do not know? Pass as argument 0x000 ?? 

Regards.

Pierpaolo

0 Kudos
Reply
2,902 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Pierpaolo,

Sorry for my last reply!
The can_pal_s32k144 example is configured Standard ID, so FLEXCAN_MSG_ID_STD should be input instead of CAN_MSG_ID_EXT.
I have test the below codes on S32K144EVB with CAN FD analyzer, it is able to turn on and turn off the LEDs no matter what CAN ID the CAN FD analyzer sent.

CAN_ConfigRxBuff(&can_pal1_instance, RX_MAILBOX, &buffCfg, RX_MSG_ID);
CAN_SetRxFilter(&can_pal1_instance, FLEXCAN_MSG_ID_STD, RX_MAILBOX, 0x0);

For more detail about how CAN_ConfigRxBuff and CAN_SetRxFilter works, please refer the answer in S32K146 CAN receive problem.

CAN_SetRxFilter.png

Best Regards,

Robin

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

2,901 Views
pierpaolo_dini
Contributor III

Hi, thank you very much. This solved the problem.

Best Regards.

0 Kudos
Reply