Help with code: s32k144_Project_FlexCAN

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Help with code: s32k144_Project_FlexCAN

1,813 次查看
p_decesare
Contributor III

Hi,

I modified the example "s32k144_Project_FlexCAN" for the s32k144 board to receive only the CAN Message with the ID 0X555. I wrote this code in the main function:

p_decesare_1-1600264167504.png

 

I want that every time the CAN message arrives, the s32k144 receives the CAN Message and the Red Led is turn on; in contrast, the Blue Led is turn on.
But when I debug my code I'm not able to see the switch between red and blue led.

How could I solve this problem?
In addition how it is possibile to print on the console the ID of CAN message? Finally how Could I modify the code in order to receive more IDs than one?

 

Thanks

Best regards,

Paola

 

0 项奖励
6 回复数

1,785 次查看
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi p_decesare,

Did you initialize the PTD0 and PTD15? The project only initialize the PT16 by default.
If you want to only receive CAN Message with the ID 0X555, you can direct #define NODE_B in FlexCAN.h.(The codes has configure check all ID bits and allow 0x555 by default.)

NODE_B FlexCAN.png

Once you receive the CAN Message with the ID 0X555, the ricevuto will be true.
The this condition will never be established: if (((CAN0->IFLAG1 >> 4) & 0) && ricevuto)
And the blue LED will never light.

Please try to debug:

	  for (;;)
	  {                        			/* Loop: if a msg is received, transmit a msg */
		if ((CAN0->IFLAG1 >> 4)) {  /* If CAN 0 MB 4 flag is set (received msg), read MB4 */
		  FLEXCAN0_receive_msg ();      /* Read message */
		  PTD->PSOR |= 1<<0 | 1<<16;
		  PTD->PCOR |= 1<<15;
		}
		else{
		  PTD->PSOR |= 1<<15 | 1<<16;
		  PTD->PCOR |= 1<<0;
		}
	  }


If you put a breakpoint PTD->PCOR |= 1<<15;, you will see the red LED light once. And then the codes will turn off red LED and light bule LED.


If you want to use print on the console the ID of CAN message, please refer the "S32K144_Project_LPUART".

S32K144_Project_LPUART.png


The ID of CAN message(RxID) will be read in FLEXCAN0_receive_msg.

RxID FLEXCAN0_receive_msg.png

Best Regards,
Robin

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

1,783 次查看
p_decesare
Contributor III

Hi Robin,

thank you for your help. I initialized the PTD0 and PTD15.
I modified the code as you answered but it still doens't run perfectly. In my configuration if I wrote on the console the character equal to "a" the message CAN is transmitted and in the same time, I want that the red led of s32k144 is turn on. The led is always blue.

I have a question: the condition CAN0->IFLAG1 >> 4) & 1 is true when the reception of CAN message is finished or it is true at the start of reception?
I need a condition that is true at the start of the reception because then, I must acquire thank the ADC the physical value of CAN-High e CAN-Low.

Thanks for your help

Best regards

Paola 

0 项奖励

1,761 次查看
Robin_Shen
NXP TechSupport
NXP TechSupport
I want that every time the CAN message arrives, the s32k144 receives the CAN Message and the Red Led is turn on; in contrast, the Blue Led is turn on.

Would you please let me know when you want this light Red LED trun off? If you want to turn off the Red LED immediately when no CAN Message arrive, then the time to keep the Red LED on may be too short.(You may need to observe the signal of the Red LED by using oscilloscope). Otherwise you need to add delay for it, so that you can see the Red LED Blink by eyes instead of oscilloscope when the CAN message arrive.

The condition CAN0->IFLAG1 >> 4) & 1 is true each successful transmission or reception. The FLEXCAN0_receive_msg will Clear CAN 0 MB 4 flag(make the CAN0->IFLAG1 >> 4) & 1 is false).

I am afraid the IFLAG1 does not meet your needs, because the reception has finished.

FLEXCAN0_receive_msg.png55.4.2.11 Interrupt Flags 1 register (IFLAG1).png

Best Regards,
Robin

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

1,752 次查看
p_decesare
Contributor III

Hi Robin,

thank you for your help. For the transmission of CAN message I adopted the methodology that if the user wrote the character "a" on the console, so the CAN message is transmitted. The code that is on the s32k144 is just for the reception. So I want that just when I wrote "a" the red Led is turn on; in contrast the blue led is turn on.
Robin could I ask you some things about CAN that I didn't understand? In the function FlexCAN_receive_msg I don't understand how the variable RXCODE, RXID are stored. I don't understand what means 4*msg_buf_size + 0 or +1. I'm studying the chapter of CAN on RM but I have some difficulties.

Finally, if you could, can tell me how it is possible to read more IDs? In this case, I know that should implemented more message buffer. But for the fact that, I'm not able to comprehend very well how to store the ID, the DATA FIELD, can help me?

 

Thank you for your time

Best regards,

Paola 

 

p_decesare_0-1600420988464.png

 

0 项奖励

1,722 次查看
Robin_Shen
NXP TechSupport
NXP TechSupport
In the function FlexCAN_receive_msg I don't understand how the variable RXCODE, RXID are stored. I don't understand what means 4*msg_buf_size + 0 or +1.

55.4.3 Message buffer structure.png

how it is possible to read more IDs?

For more IDs, please refer the answer in : FlexCan S32K142 Need "simple" CAN0 Filters / matching example

 

1,718 次查看
p_decesare
Contributor III

Hi @Robin_Shen ,

thank you for your answer and for the share of the example where there are more IDs transmitted.
Ok I understand how the variables of Identifier, Data are stored. Finally I have the last question: I saw on the RM, that the CODE for the reception of Message (page 1719) could assume different values, but in RM there isnt't the meaning of 0111. I ask you this because in the function FLEXCAN Receive there is:


(CAN0->RAMn[ 4*MSG_BUF_SIZE + 0] & 0x07000000) >> 24

0x07000000, that means that CODE is equal to 0111. I don't understand this. 
At the end, I want to know how to establish the dimension of variable #define MSG_BUF_SIZE 4. In this example, is there four because are transmitted 32 bit as data field??

Thanks for your help

Best regards,

Paola

0 项奖励