Can Bus message id problem

Moderator: Benj

Post Reply
Zane
Flowcode v5 User
Posts: 199
Joined: Thu Sep 10, 2009 10:57 pm
Location: New Zealand
Has thanked: 93 times
Been thanked: 76 times
Contact:

Can Bus message id problem

Post by Zane »

Hi,

I have found that when setting a message id in the canbus module by using the macro SetTxId that when it is received by another node (the node is set to accept all messages) that the lsb of the message id is stripped and cannot be seen by the node receiving the data ie a message id that is odd cannot be seen. If you set the message id via the external properties box and then send the data any message id is received correctly. Any help with this would be great.

Thanks

Zane

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Can Bus message id problem

Post by Benj »

Hello Zane,

If you look in the CAN component help file then you will see that the ID value is shifted 5 places to the right.

eg for ID 1

IDlow = 0b00100000 / 0x20 / 32
IDhigh = 0b00000000 / 0x00 / 0

The easiest way to calculate this is to put your required ID into an INT variable and then do the following to split the INT into a low and hi byte.

INTvar = IDvalue eg 1
IDlow = INTvar << 5
IDhigh = INTvar >> 3

To recombine into a single ID variable on the receive side you would have to do the following.

INTvar = IDhigh << 3
INTvar = INTvar | (IDlow >> 5)

Hope this helps.

Zane
Flowcode v5 User
Posts: 199
Joined: Thu Sep 10, 2009 10:57 pm
Location: New Zealand
Has thanked: 93 times
Been thanked: 76 times
Contact:

Re: Can Bus message id problem

Post by Zane »

Hi Ben,

Yes i have already done this taking the message id and applying the given algorithm. If i set a message id via the macro and it is say 2 and then it is converted via the algorithm, the receiving node when reading the message id value after its is converted back again is also 2. If i have a message id of say 3 the recieving node will will see it as 2. If i have a message id of 7 the recieving node will see it as 6.

As i mentioned in my last post if you set the message id via the external properties box, the message id that is set is recieved corectly by the recieving node. The issue is only relates to the SetTxId macro.

Thanks for your help.

Zane

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Can Bus message id problem

Post by Benj »

Hello Zane,

Are you sure you have your calculations correct. It sounds like the least significant bit is being left off.

Eg.

ID 2 in binary is 0b00000010 you are receiving 0x00000010
ID 3 in binary is 0b00000011 you are receiving 0x00000010
ID 7 in binary is 0b00000111 you are receiving 0x00000110

As you say the receiver is working correctly when it is passed a ID from the external properties so this makes me think that the error is in the transmit ID calculation before you pass the SetTxID macro the ID values.

Maybe you could attach your program and I'll see if I can spot anything untoward.

Zane
Flowcode v5 User
Posts: 199
Joined: Thu Sep 10, 2009 10:57 pm
Location: New Zealand
Has thanked: 93 times
Been thanked: 76 times
Contact:

Re: Can Bus message id problem

Post by Zane »

Hi Ben,

I have two basic programs, A transmits data from buffer 0, the message id is set via variable C and data is set from variables A and B.
Program B recieves data from buffer 0 and and places the transmitted data in variables A and B and the message id is calculated and placed in the variable ID. See how you go with this but every time i try and send a message with an odd ID the lsb is stripped so the id comes out even.
After this if the message id is set in the external properties box in program A, in program B when the message id is read and calculated back out again and placed in the variable ID, the message id is correct.
Once again thanks for your help.

Zane
Attachments
a.fcf
Send
(7.5 KiB) Downloaded 349 times
b.fcf
Recieve
(8.5 KiB) Downloaded 354 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Can Bus message id problem

Post by Benj »

Hello Zane,

Your flowcharts looked like they should have worked. I spotted that your ID variables was still down as a byte in bioth programs so I have changed this and I have also slightly changed the technique to create the ID variable.

Let me know how you get on using these versions of the programs.
Attachments
b.fcf
(8.5 KiB) Downloaded 355 times
a.fcf
(7.5 KiB) Downloaded 350 times

Zane
Flowcode v5 User
Posts: 199
Joined: Thu Sep 10, 2009 10:57 pm
Location: New Zealand
Has thanked: 93 times
Been thanked: 76 times
Contact:

Re: Can Bus message id problem

Post by Zane »

Hi Ben,

I have downloaded both examples you have supplied me but the same problem is still present.

Thanks for yor help

Zane

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Can Bus message id problem

Post by Benj »

Hi Zane,

Thats very odd. How are you showing the ID at the receiver end? If your lighting LEDs could it be that pin 0 has been damaged and is not lighting the LED?

What chip are you using? Are you using the internal or external CAN driver?

Zane
Flowcode v5 User
Posts: 199
Joined: Thu Sep 10, 2009 10:57 pm
Location: New Zealand
Has thanked: 93 times
Been thanked: 76 times
Contact:

Re: Can Bus message id problem

Post by Zane »

Hi Ben,

I am using no hardware at the moment, just using the two instances of flowcode running the two programs using flowserver as the interface between the two and viewing the variables on screen.

I have attached 3 programs, SendIdProperties which sets the message ID via the properties box and is set to 17. When ruuning this in conjunction with the receive program, when pausing the receive program the message ID shows up as 17 (variable "id"). The other program SendIdMacro sets the message ID via the macro. When running this with the receive program, this time the message ID shows itself as 16 (variable "id").

I have tried all sorts of things but no matter what i do when setting the message ID via a macro the LSB is always stripped. Thanks for patience with this.

Kind Regards

Zane
Attachments
SendIdMacro.fcf
(7.5 KiB) Downloaded 366 times
SendIdProperties.fcf
(7 KiB) Downloaded 349 times
Receive.fcf
(7.5 KiB) Downloaded 364 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Can Bus message id problem

Post by Benj »

Hi Zane,

Right now I see that the problem lies somewhere in the simulation. The program should work correctly on the hardware. I will see if I can track down the bug in the Vnet communications.

Zane
Flowcode v5 User
Posts: 199
Joined: Thu Sep 10, 2009 10:57 pm
Location: New Zealand
Has thanked: 93 times
Been thanked: 76 times
Contact:

Re: Can Bus message id problem

Post by Zane »

Hi Ben,

Thanks for your work with this. I have not tried with any hardware yet, just in the process of making some boards for myself so should be able to try sometime this week. I will let you know how we go.

Kind Regards

Zane

Zane
Flowcode v5 User
Posts: 199
Joined: Thu Sep 10, 2009 10:57 pm
Location: New Zealand
Has thanked: 93 times
Been thanked: 76 times
Contact:

Re: Can Bus message id problem

Post by Zane »

Hi Ben,

I have completed some circuit boards and have set message ID's to odd and even values and everything works fine.

Thanks

Zane

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Can Bus message id problem

Post by Benj »

Hi Zane,

Thats great many thanks for letting me know. :) Hopefully we can get the simulation problem nailed down and fixed.

Post Reply