CAN driver code for MPC5668G

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

CAN driver code for MPC5668G

1,544 Views
sukruthrameshba
Contributor III

Can i get simple CAN driver code for MPC 5668g in which transmit and receive functionality is configured for CAN_F block?

Labels (1)
Tags (1)
10 Replies

1,186 Views
sukruthrameshba
Contributor III

Hello Mr Petr,

Thanks for your response.

I looked into the code. It is working fine with the transmit functionality. But I am not able see the received message on MB5.

As per my requirement , I use only CAN_F channel for transmission and reception. I don't need CAN_B.

By "Other node" , I meant  "CANoe" not from CAN_B.

So I need CAN_F block to transmit any message with STD_ID and

it should receive any message if the ID matches and show that on configured MB(Lets say MB5).

I tried modifying the code you sent, But I am not able to see the receive functionality.

It will be helpful if you can  send me the code which have only the above requirements:)

I will attach my modified code too:)

Thanks,

Sukruth

0 Kudos

1,186 Views
PetrS
NXP TechSupport
NXP TechSupport

see attached code...

BR, Petr

1,186 Views
sukruthrameshba
Contributor III

Please have a look at the modified code.

0 Kudos

1,186 Views
sukruthrameshba
Contributor III

Okay...Lets say i need to receive an id labelled with 555 sent from the other node.

Can you advise me the MB and mask register setting for the same?

And according to this code only MB5 has to receive. But all MBs from MB0 to MB5 are receiving. I want to configure one MB for reception.

I am not clear with ID table setting( why exactly the shift operation is being used?)

0 Kudos

1,186 Views
PetrS
NXP TechSupport
NXP TechSupport

Once you enable self-receive functionality the module is allowed to receive frames transmitted by itself, if there is matching MB. If this is not needed, just set the SRXDIS bit.

If there is matching RX MB or RX FIFO which is “free to receive” the message transmitted from other node must be received regardless of SRXDIS bit.

So check the MBs and mask registers setting. If RX FIFO is enabled , set properly the ID table and mask registers.

If you will have doubts with receive operation still, describe clearly what kinds of messages you want to receive, so MB and mask registers setting can be advised.

0 Kudos

1,186 Views
PetrS
NXP TechSupport
NXP TechSupport

From your code I see you configure CAN_E, CAN_F in the same manner. CAN_E is not used anymore in your code.

CAN_F is sending a message and you also wait on CAN_F for receive message on FIFO.

So if you want to self-receive frames then clear the SRXDIS bit in MCR register.

Moreover if using the RX FIFO you have to properly set the ID table. You are still using addresses for CAN_B module. Change ID table addresses to reflect desired module. For example

#define ID_Table0_CANF (*(vuint32_t* )(0xfffd40e0))

#define ID_Table1_CANF (*(vuint32_t* )(0xfffd40e4))

#define ID_Table2_CANF (*(vuint32_t* )(0xfffd40e8))

#define ID_Table3_CANF (*(vuint32_t* )(0xfffd40eC))

#define ID_Table4_CANF (*(vuint32_t* )(0xfffd40f0))

#define ID_Table5_CANF (*(vuint32_t* )(0xfffd40f4))

#define ID_Table6_CANF (*(vuint32_t* )(0xfffd40f8))

#define ID_Table7_CANF (*(vuint32_t* )(0xfffd40fc))

Petr

1,186 Views
sukruthrameshba
Contributor III

Thank you so much!

I updated these changes and it is working now:)

But I have one small problem, as I have enabled SRXDIS it is receiving its own frame.

But when I am sending CAN frame from the other node,  I am not able to see that in that particular Rx buffer.

Do you  have any suggestions for this?

0 Kudos

1,186 Views
PetrS
NXP TechSupport
NXP TechSupport

The example posted in your other thread (https://community.nxp.com/thread/397245) is not enough?

The CAN_F is used to transmit message and CAN B to receive, you can simply modify it for reception on CAN_F too.

BR, Petr

0 Kudos

1,186 Views
sukruthrameshba
Contributor III

Please view the updated code and let me know the changes I need to make.

0 Kudos

1,186 Views
sukruthrameshba
Contributor III

I tried modifying the example code for reception on CAN_F. But it was not working. Message buffer which was configured to receive was not getting the transmitted message. Can you please help me out in resolving this issue?

I will attach the updated code via mail:)

Thank you.

0 Kudos