Decode/Revert CAN Frame ID

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Decode/Revert CAN Frame ID

ソリューションへジャンプ
812件の閲覧回数
abdullah_cinar
Contributor III

Hi,

I am receiving hundreds of different CAN frames from a peripheral device to my MKV11Z64 MCU. When I want to send a frame, I use this macro:

FLEXCAN_ID_STD(rxIdentifier)

Then when I receive a CAN packet from the peripheral device, I need to check the frame id. So I use this:

printf("Message Id: 0x%.2X\r\n", rxFrame.id);

But it does not give me the correct value. I get 0x10C40000 as the frame id but it should be less than 0x7FF for standard IDs. Is there any reverse implementation of FLEXCAN_ID_STD macro to get the correct frame id?

I could have write my own macro by looking at the FLEXCAN_ID_STD implementation and do the reverse job but I don't understand why we can not just get the correct frame id directly.

Edit: I think when I shift the result to right for 18 bits, I get the correct result. Why does this happen?

ラベル(1)
0 件の賞賛
1 解決策
711件の閲覧回数
Sabina_Bruce
NXP Employee
NXP Employee

Hello Abdullah,

The reason you would have to do the shift to get the right id is due to the function that you are using. 

The sdk was designed to make it easier to create the message buffer, therefore different functions were implemented. One of them is FLEXCAN_ID_STD(rxIdentifier) as you can see in its declaration it is 

 (((uint32_t)(((uint32_t)(id)) << CAN_ID_STD_SHIFT)) & CAN_ID_STD_MASK) /*!< Standard Frame ID helper macro. */

With the shift being an 18 bit shift.

So in order to recover the id you will have to shift it to the right or redesign your implementation.

Best Regards,

Sabina

元の投稿で解決策を見る

0 件の賞賛
1 返信
712件の閲覧回数
Sabina_Bruce
NXP Employee
NXP Employee

Hello Abdullah,

The reason you would have to do the shift to get the right id is due to the function that you are using. 

The sdk was designed to make it easier to create the message buffer, therefore different functions were implemented. One of them is FLEXCAN_ID_STD(rxIdentifier) as you can see in its declaration it is 

 (((uint32_t)(((uint32_t)(id)) << CAN_ID_STD_SHIFT)) & CAN_ID_STD_MASK) /*!< Standard Frame ID helper macro. */

With the shift being an 18 bit shift.

So in order to recover the id you will have to shift it to the right or redesign your implementation.

Best Regards,

Sabina

0 件の賞賛