cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with ST710 library CAN identifier manipulation macros

parrino
Associate II
Posted on January 10, 2006 at 15:21

Problem with ST710 library CAN identifier manipulation macros

3 REPLIES 3
parrino
Associate II
Posted on December 12, 2005 at 10:37

Hello

I have a problem with CAN identifier manipulation macros.

For exemple, I want to send on the CAN bus the nine following CAN messages with extended identifiers

Id=0x00107F0, DLC=8, Data=[0x08, 0x17, 0x26, 0x35, 0x44, 0x53, 0x62, 0x71])

Id=0x00107EF, DLC=7, Data=[0x27, 0x36, 0x45, 0x54, 0x63, 0x75, 0x86])

Id=0x00107EE, DLC=6, Data=[0x46, 0x56, 0x65, 0x74, 0x83, 0x95])

Id=0x00107ED, DLC=5, Data=[0x65, 0x76, 0x85, 0x94, 0xA3])

Id=0x00107EC, DLC=4, Data=[0x84, 0x96, 0xA5, 0xB4])

Id=0x00107EB, DLC=3, Data=[0xA3, 0xB6, 0xC5])

Id=0x00107EA, DLC=2, Data=[0xC2, 0xD6])

Id=0x00107E9, DLC=1, Data=[0xE1])

Id=0x00107E8, DLC=0, Data=[])

I used STR710-EVAL board to send CAN messages on one side and CANalyser in spy mode to read CAN messages on the other side.

When I use ST macro, CANalyser read

Id=(0x1FC00020), DLC=8, Data=0x08, 0x17, 0x26, 0x35, 0x44, 0x53, 0x62, 0x71

Id=(0x1FBC0020), DLC=7, Data=0x27, 0x36, 0x45, 0x54, 0x63, 0x75, 0x86

And so on ...

But if I replace (in function CAN_SendMessage, file can.c) :

''CAN->sMsgObj[0].A1R = EXT_FIXED_ID_ARB_L(pCanMsg->Id);'' by ''CAN->sMsgObj[0].A1R = 0xFFFF & pCanMsg->Id;''

and

''CAN->sMsgObj[0].A2R = (CAN->sMsgObj[0].A2R & 0xE000) | EXT_FIXED_ID_ARB_H(pCanMsg->Id);'' by ''CAN->sMsgObj[0].A2R =

(CAN->sMsgObj[0].A2R & 0xE000) | (0x1FFF0000 & pCanMsg->Id) >>16;''

CANalyser read good identifiers :

Id=(0x107F0), DLC=8, Data=0x08, 0x17, 0x26, 0x35, 0x44, 0x53, 0x62, 0x71

Id=(0x107EF), DLC=7, Data=0x27, 0x36, 0x45, 0x54, 0x63, 0x75, 0x86

And so on ...

Can you tell me what is the problem ?

Thanks for your answer

davidbellegarde9
Associate II
Posted on December 14, 2005 at 13:02

About the Id, here is the way the code is implemented:

The pCanMsg->Id software buffer:

bit[28..0]

EXT Id part, STD id part

MSB------------------LSB

Then it is dispatched in the A1R and A2R (arbitration registers as follow:

A2R[12..2] for the STDID

MSB----LSB (ID[28..18] of A2R)

A2R[1..0] A1R[15..0] for the extended part

MSB---------------LSB (ID[17..16] of A2R and ID[15..0] of A1R)

Then a trame is sent or received as follow:

STDID[10..0] EXTID[17..0]

MSB-----LSB MSB-------LSB

Finally, the CANanalyser read this:

STDID[28..18] EXTID[17..0]

MSB-----------------------LSB

So if you compare the beginning and the end you should see a swap between the STDID and the EXTID, this should explain the problem. In fact there is no problem, I tried with your fisrt message ID and it works well.

From a CAN arbitration point of view, the STDID must be the MSBs but the code was not implemented like this. I think you could add a little function which would handle the Id.

e.g.

/*swap the Id*/

CAN_HandleId(canmsg* pCanMsg, u32 Id)

{

pCanMsg->Id = ((Id & 0x3FFFF)<

(Id & 0x1FFC0000)>>18));

}

parrino
Associate II
Posted on January 10, 2006 at 15:21

Hi Squirrel !

First, Happy new year !

You are right ! To have a good interpretation of extended Id, I use

* before send :

u32 can2libst(u32 Id)

{

return ((Id&0x1FFC0000)>>18) | ((Id&0x3FFFF)<

}

* after receive :

u32 libst2can(u32 Id)

{

return ((Id&0x7FF)<>11);

}

And it works perfectly with ST functions.

For standard ID, there is no problem and so I don't use the previous functions.

But now I have a problem with receive mask.

ST functions provide function to receive a range of Ids [LowId, HighId] : CAN_SetRxMsgObj

It works with [0, CAN_LAST_STD_ID] for standard ID or [0, CAN_LAST_EXT_ID] for extended Id.

For other values, the result is strange...

If I want to receive, for example standard Id range [5, 15], I never receive the Id 10 message sent by CANalyzer. But if use Id range [8, 11], I receive it !

I don't really understand how works mask and arbitration macros RANGE_ID_MSK and RANGE_ID_ARB.

When I read documentation, I understand the following :

If Mask Bit n = 1, Arbitration bit n is used to filter message

If Mask Bit n = 0, Arbitration bit n isn't used.

For example :

Mask = 0xC and Arb = 0x9

In binary :

1100 Mask

1001 Arb

10xx Accepted Id

So accepted Ids should be (in binary) 1000, 1001, 1010 and 1011 (ie 0x8, 0x9, 0xA, 0xB)

Is my interpretation correct ?

And what is wrong with my use of the CAN_SetRxMsgObj function ?

Thanks for your help !