CAN Rx can't read specific data

cancel
Showing results for 
Search instead for 
Did you mean: 

CAN Rx can't read specific data

Jump to solution
643 Views
dlysam2716
Contributor III

kerryzhou

Hello! I have a question to ask,I use MK10FN1M0VLQ12 chip, I want to use CAN to control the system, but there is a problem is I already setup my CANID is 110, and the buffer name is stdcmd[8]={0x00U,0x00U,0x00U,0x00U,0x00U,0x01U,0x00U,0x00U} ,I need the CAN receive the command when stdcmd[5]=0x01; start the system. However, it always only CANID is correctly, then start the system. I try to revise it, but never changed. Is the buffer need to use Extended?  There are my code and setup, hope you can give me some advice. Thank you so much! 

the VIDEO show my problem clearly:

https://drive.google.com/file/d/1t3w1M5sCd9yrtf9aU3Q4iU5l-8rwX1Gv/view?usp=sharing 

https://drive.google.com/file/d/1OJTPvCPDPGFFo9noaYcA2RbwuZquqegM/view?usp=sharing 

Tags (3)
0 Kudos
1 Solution
494 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi

Check this FLexCAN ID filter post:

https://community.nxp.com/message/605315?commentID=605315#comment-605315 

And use the CAN analyzer tool to test your ID=110 really works at first, then connect your master board or other board.

 

Have a great day,

Kerry

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

View solution in original post

0 Kudos
7 Replies
493 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi yu-jung Chuang,

   Thank you for the interest in NXP kinetis product, I would like to provide service for you.

   What's the IDE you are using? KDS?

   Do you enable the ID filter?

   I have created a K60_120M CAN_LDD KDS project for your reference, I have tested that code, it works:

https://community.nxp.com/servlet/JiveServlet/download/577143-1-363554/K60_120M_CAN_LDD.rar 

  Your K10 can refer to it.

https://community.nxp.com/message/577143?commentID=577143#comment-577143 

Wish it helps you!

If you still have questions about it, please kindly let me know

 


Have a great day,

Kerry

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

0 Kudos
494 Views
dlysam2716
Contributor III

Thank you for your answer! I'm a beginner to learn how to use the hardware. I'm use KDS to make CAN work and I'm sure it's work now. I just use CAN1 to make it work, then make data from SPI display on  CAN receiver of PC not on KDS interface,so I don't use "Self receiption" and "Loopmode" , . But the problem is I wanna use CAN to control SPI transmittion work or not by CAN receiver of PC. So I set ID110 with bit5 equal 0x01 is my command to make SPI work,I mean when chip receive the CAN ID110 and bit5=0x01, then start work, but bit5=0x00 or 0x02 and others can't (fig.1).I already use your KDS project to try it. It can work, but CAN control also not work by this way. So I try to change this code like [ Frame.Data = InpData; ] to  [Frame.Data[5] = InpData[5];] or [Frame.Data[5] = InpData[5]&0x01;],they always wrong when I debug it, I don't know why..., maybe I should add the code [SetRxBufferState]? and I'm not sure whether "enable ID filter", thank you for patient.

0 Kudos
494 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi yu-jung Chuang,

   So, your kinetis flexcan receive the detail ID and data, when you receive the different ID, then you check the ID bit5, and judge whether you need to control the SPI or not, right?

   If yes, I think you don't need to control the SPI at first, you just use some printf to receive your IDs which you will be used, no matter the bit 5 is what, then you can test the CAN directly, after it works, then you can add your SPI code again.

   If you want to receive the ID bit5 both 0 and 1, you can don't use the ID mask, or the mask can recieve the ID bit5 both 0 and 1. Please test the CAN with the CAN transiver and anlayzer tool at first,

Wish it helps you!

If you still have questions about it, please kindly let me know

 


Have a great day,

Kerry

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

0 Kudos
494 Views
dlysam2716
Contributor III

Thank you for your advice, it's maybe more easier, but SPI just a little part . My project need control something accurate by this way. Firstly, forgive me,the "bit" should be correct "byte". The CAN format have 11byte right? and 3 byte is ID, then another 8 byte is data. when I set the bufferID on Component Inspector, it's mean already occupy 3byte(Frame.MessageID = 0x110U);.  So I check my CAN transiver. I found a problem, I sent the Message ID110 and Byte5=0x01 to my Masterboard receive into the buffer(CANRX[5]) by CAN transiver, the problem is CANRX[5] is zero, so my CAN transiver sent the message didn't fill the buffer. Is my CAN transmit format wrong? or this code [Error = CAN1_ReadFrame(MyCANPtr, 0U, &Frame);] just read ID then jump to OnFullRxBuffer event?


uint8_t CANRX[8]={0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U}; I sent 0x01 to Byte5 by CAN transiver, the Buffer inside should be changed like "CANRX[8]={0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00};" when I work it.  I just wanna when ID=110 and Byte5=0x01 to work.

0 Kudos
495 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi

Check this FLexCAN ID filter post:

https://community.nxp.com/message/605315?commentID=605315#comment-605315 

And use the CAN analyzer tool to test your ID=110 really works at first, then connect your master board or other board.

 

Have a great day,

Kerry

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

0 Kudos
494 Views
dlysam2716
Contributor III

Thank you for help!  I already solve it!

0 Kudos
494 Views
kerryzhou
NXP TechSupport
NXP TechSupport

You are welcome.

If you have the new question in the future, welcome to create the new case.

 

Have a great day,

Kerry

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

0 Kudos