How to read any received CAN id (and timestamp) in NXPS32144

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

How to read any received CAN id (and timestamp) in NXPS32144

1,280 Views
pierpaolo_dini
Contributor III

Hi everyone!

I have an NXP S32144 and I trying to set a very simple communication via CAN Protocol between an Arduino Uno with an MCP2515 additional module.

From the Arduino side, the program is very simple because I can use the library mcp2515.h which have the availability of some "high-level" function io order to set the id, the doc, and the data content. Further, in order to receive a message, once you initialize an adequate type of structure in which save the current message, you can access to that structure in a simple way and read the various field of the message itself;  and in order to write, similarly, you initialize that kind of adequate structure and assign the value you want to any field.

I expected something similar for NXP but is not so.

My try is the following:

- open an example from Design Studio: FLEX CAN

- and I have modified in the following way the main.c, FlexCan.c; and FlexCan.h :

   1)main.c:

main.PNG

 2)FlexCan.c:

pastedImage_2.png

3)in the FlexCan.h I just inserted the command line uint32_t ID_rx(void);

My idea is to save only the id of the currently received message in a variable (which clearly change any time that one new message arrives) and as a starting point I just want to print and after a control (in which I simply increment a counter variable to decide when turn on the green led).

I have tried to built and no problems occur but when I try the debug_ram procedure (clicking play button) i notice that on the console the printed id is always "0x0".

I also noticed that the led turn on when a click plays in the debug procedure, but this is strange because also if the reader id is wrong, the "if" condition is not satisfied.

Intuitively I understand that the FlexCan_init function must be modified but I do not know how in order to read any message received.

If someone can explain also the various function in order to understand how modify if I want to not only receive all possible can message, but also if I want to transmit a specific id with a specific periodicity

I do not have enough knowledge of embedded system or experience in programming, so maybe my problem is trivial but hopes someone can help me. 

Thanks in advance to who spent the time to help me.

Kind regards.

0 Kudos
6 Replies

1,114 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

you picked bareboard example. There are also SDK examples with high level functions. Take a look at this one:

c:\NXP\S32DS_ARM_v2.2\S32DS\software\S32SDK_S32K1xx_RTM_3.0.0\examples\S32K144\driver_examples\communication\can_pal\Sources\main.c

You can create sample project in this way:

File -> New -> S32DS Project from Example

Now do not select examples from "S32DS Example Project for S32K1xx" but scroll down to "S32SDK S32K1xx RTM v3.0.0 Example Projects"

And here search for can_pal_S32K144.

Regards,

Lukas

1,114 Views
pierpaolo_dini
Contributor III

Hi Lukas,
First of all, thank you for answering me.
I was checking that the example you are suggesting is not present if I download Design Studio from the nxp page to the link for DS for Arm v2.0. However, I downloaded from the DS for ARM 2.2 link and now opened it.
Surely a syntax that's closer to my knowledge so it's definitely helpful.
The only problem is that I can't even compile it because the libraries are not linked.

pastedImage_1.png

do I have to make any particular settings?

Thanks again in advance for your patience.

Best regards.

0 Kudos

1,113 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

did you click on Project -> Generate Processor Expert Code? Or there's an icon in Components window. This could be the reason...

Regards,

Lukas

1,113 Views
pierpaolo_dini
Contributor III

Hello Lukas,

I try to read the message-id using the can_pal example, but there is something I do not understand.

Basically, with the function CAN_Receive(&can_pal1_instance, RX_MAILBOX, &recvMsg), the current message received from the NXP should be saved in the previously initialized can_structure recvMsg. Should be easy to access to the id with the classic "structure_name.field_name". 

I modified the main as follows, maintaining the init functions of the can:

pastedImage_3.png

I just want to read the message-id and check if is equal to the only one on the bus (an Arduino send a message with id=0x55).

I am sure that the Arduino sends the message because I can check with a peak device on bus master SW.

pastedImage_8.png

For sure I doing something wrong but I do not understand what.

Others strange things are that when I do the debug procedure, the white led turn on (??) and that on the console I see this message:

pastedImage_9.png

Thanks again for your help.

Regards.

Pierpaolo.

0 Kudos

1,114 Views
pierpaolo_dini
Contributor III

Hi Lukas,

Actually I did not select "Generate Processor Expert Code". Now I can build the program.

Really thanks for your support in my trivial problem XD.

Best Regards.

0 Kudos

1,114 Views
pierpaolo_dini
Contributor III

Hello Lukas,

I try to read the message-id using the can_pal example, but there is something I do not understand.

Basically, with the function CAN_Receive(&can_pal1_instance, RX_MAILBOX, &recvMsg), the current message received from the NXP should be saved in the previously initialized can_structure recvMsg. Should be easy to access to the id with the classic "structure_name.field_name". 

I modified the main as follows, maintaining the init functions of the can:

pastedImage_3.png

I just want to read the message-id and check if is equal to the only one on the bus (an Arduino send a message with id=0x55).

I am sure that the Arduino sends the message because I can check with a peak device on bus master SW.

pastedImage_8.png

For sure I doing something wrong but I do not understand what.

Others strange things are that when I do the debug procedure, the white led turn on (??) and that on the console I see this message:

pastedImage_9.png

Thanks again for your help.

Regards.

Pierpaolo.

0 Kudos