Reading CAN ID issue

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
Chris_MIRA
Posts: 186
Joined: Wed Jan 23, 2013 3:43 pm
Has thanked: 2 times
Been thanked: 21 times
Contact:

Reading CAN ID issue

Post by Chris_MIRA »

Hi,
Im having trouble reading a CAN ID using the component macro (see attached code, CAN_HB send macro). The problem is that I cant get the code to recognise the ID of the sent message. Ive tried using all the "Get Rx Id" options simple, high and low. The attached test programme looks for a message, gets the message ID and sends its own can message with the ID of the original received message in D0. When run, and sending a message with id 20 the id number read is 1. I was expecting a decimal 20? Is this a FC problem or am I doing something silly?
Regards,
Chris

hyperion007
Posts: 528
Joined: Sat Dec 01, 2012 1:23 pm
Location: Sweden
Has thanked: 49 times
Been thanked: 101 times
Contact:

Re: Reading CAN ID issue

Post by hyperion007 »

There is no attached program...

Chris_MIRA
Posts: 186
Joined: Wed Jan 23, 2013 3:43 pm
Has thanked: 2 times
Been thanked: 21 times
Contact:

Re: Reading CAN ID issue

Post by Chris_MIRA »

okay, there were problems with the server, it must not of up-loaded, hopefully now attached, Ive commented in the code on the CAN_HB macro where the problem seems to be occurring!
Regards,
Chris
Attachments
DSPIC ECIO Zombie Cool-E.fcfx
(21.51 KiB) Downloaded 199 times

EtsDriver
Posts: 444
Joined: Tue Apr 15, 2014 4:19 pm
Location: Kajaani, Finland
Has thanked: 345 times
Been thanked: 227 times
Contact:

Re: Reading CAN ID issue

Post by EtsDriver »

You have CAN receive buffer 0 filter set as 1.

https://www.dropbox.com/s/5gl7ux6ax7cmz ... C.PNG?dl=0

You can try this :
https://www.dropbox.com/s/vqapiefbpsks3 ... 2.PNG?dl=0
Set your CAN_RX_ID to 20. Set this using macro or directly from CAN1 component settings, or
https://www.dropbox.com/s/z8ida6qe38r22 ... 3.PNG?dl=0
Select the buffer to accept all, or...
Benj - Click to see topic related wrote: Of course, for simple CAN applications you may wish to only accept one or two messages. Setting the mask to 0x7FF in this instance would mean that only the message ID specified by each filter would be accepted, e.g.

Mask1 = 0x7FF
Filter2 = 0x100
Filter5 = 0x200
Last edited by EtsDriver on Mon Mar 02, 2015 1:49 pm, edited 1 time in total.
Ill just keep the good work up!

Chris_MIRA
Posts: 186
Joined: Wed Jan 23, 2013 3:43 pm
Has thanked: 2 times
Been thanked: 21 times
Contact:

Re: Reading CAN ID issue

Post by Chris_MIRA »

Im sorry but I don't understand your reply and I cant see the attached images (there is just a small X and the image doesn't down load.

Just to clarify what Im doing, Im trying to test the id of a received message but the get id macro doesn't return the received id.
For example if I send a can message over CAN to the micro, using the macro "Get ID simple" and variable CAN_id returns a value of 1
The same message sent again to the micro over can but with id 200 also returns 1
If I change the macro from id simple to id Hi or id lo gives a result but with the count shifted to the left 3 places and if id low, 5 places to the right!

Please see the new attached test file using a PIC 16F1939 that Im using as the macro to sort this out. Im sending the test message to it via CAN using a CAN tool.
When using get id simple, I would expect the return value to be in decimal?
Regards
Chris
Attachments
CAN Test.fcfx
(11.41 KiB) Downloaded 196 times

Chris_MIRA
Posts: 186
Joined: Wed Jan 23, 2013 3:43 pm
Has thanked: 2 times
Been thanked: 21 times
Contact:

Re: Reading CAN ID issue

Post by Chris_MIRA »

Having just re-read your last reply,
I don't think the problem is with the MASK / filters, they seem to be working fine, the issue is that I cant correctly read the ID of a message that has been received!
Regards,
Chris

Chris_MIRA
Posts: 186
Joined: Wed Jan 23, 2013 3:43 pm
Has thanked: 2 times
Been thanked: 21 times
Contact:

Re: Reading CAN ID issue

Post by Chris_MIRA »

To illustrate the issue,
The attached image shows the data screen of the CAN Analyser
The message with ID 15 was sent using the CAN analyser,
The message with id 30 was sent from the micro in response (see second test programme sent previously). D0 of this message should be the id of the message that the micro received (in this case 15).
The fact that the micro sent the message suggests that it did receive a message.
regards,
Chris
Attachments
CAN Message.png
(188.04 KiB) Downloaded 1331 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: Reading CAN ID issue

Post by Benj »

Hi Chris,

How are you reading the received ID? I.e. which macro are you using?

The GetRxIDSimple macro should allow you to collect the number 15 without having to manipulate the bits of the ID to correspond with the way the ID registers are inside the chip.

EtsDriver
Posts: 444
Joined: Tue Apr 15, 2014 4:19 pm
Location: Kajaani, Finland
Has thanked: 345 times
Been thanked: 227 times
Contact:

Re: Reading CAN ID issue

Post by EtsDriver »

If you have receive filter active as ONE, it will only receive one according to book "Create 30 PIC Microcontroller Projects with Flowcode 6 by Bert van Dam".
https://www.dropbox.com/s/eoq7g1p025rwi ... 1.pdf?dl=0

EDIT: Fixed the image links to URL in my image containing message, sorry for that, dropbox doesnt like image embedding.
Ill just keep the good work up!

Chris_MIRA
Posts: 186
Joined: Wed Jan 23, 2013 3:43 pm
Has thanked: 2 times
Been thanked: 21 times
Contact:

Re: Reading CAN ID issue

Post by Chris_MIRA »

As in the attached CAN Test programme, Im using the macro "GetRXIDSIMPLE" the returned value is as shown in the screen shot. That's the problem using GetRXIDSIMPLE doesn't return the right value! I have tried the other macro's while investigating the problem and they also return the wrong value, in there case the value is shifted! I am trying to use GetRXIDSIMPLE but only get a returned value of 1 regardless of the id address of the RX message!
Regards,
Chris

PS, there is no filter set on the CAN Test programme and the CAN buffer is set to accept all messages

EtsDriver
Posts: 444
Joined: Tue Apr 15, 2014 4:19 pm
Location: Kajaani, Finland
Has thanked: 345 times
Been thanked: 227 times
Contact:

Re: Reading CAN ID issue

Post by EtsDriver »

Chris_MIRA wrote: PS, there is no filter set on the CAN Test programme and the CAN buffer is set to accept all messages
I meant the DSPIC_ECIO_Zombie_Cool-E thingy, there was set 1 as filter.
Ill just keep the good work up!

Chris_MIRA
Posts: 186
Joined: Wed Jan 23, 2013 3:43 pm
Has thanked: 2 times
Been thanked: 21 times
Contact:

Re: Reading CAN ID issue

Post by Chris_MIRA »

Yes, there is a filter on the "Zombie" test, but this filter appears to be working okay and letting the messages I need through while stopping the ones I don't...
Regards,
Chris

Chris_MIRA
Posts: 186
Joined: Wed Jan 23, 2013 3:43 pm
Has thanked: 2 times
Been thanked: 21 times
Contact:

Re: Reading CAN ID issue

Post by Chris_MIRA »

Hi,
Please see attached file, this contains a work around that seems to function okay, Im using the component macros "GET RX id Hi" and "GET RXid Low", then diving the low by 32 and multiplying the Hi by 8 before adding together to get the right Rx id.
As said this work around does work but the "Get Rx id Simple" doesn't.
Regards,
Chris
Attachments
CAN TestV2.fcfx
(12.17 KiB) Downloaded 119 times

EtsDriver
Posts: 444
Joined: Tue Apr 15, 2014 4:19 pm
Location: Kajaani, Finland
Has thanked: 345 times
Been thanked: 227 times
Contact:

Re: Reading CAN ID issue

Post by EtsDriver »

For me this is pretty important topic, because i have created CAN systems, and now im thinking them from hardware security point...

Taking a look at this issue.
**
I did some test with my "receiver code" that is ugly, but it works fine, recognize the CAN bus ID:s totally from Atmel and Pic multiboards... :O

My "node" and my "receiver" code.
NODE.fcfx
(8.09 KiB) Downloaded 134 times
Receiver.fcfx
(11.13 KiB) Downloaded 134 times
Try playing with the Node TX Buffer 0 Message ID and see for yourself :)
Last edited by EtsDriver on Mon Mar 02, 2015 4:29 pm, edited 1 time in total.
Ill just keep the good work up!

Chris_MIRA
Posts: 186
Joined: Wed Jan 23, 2013 3:43 pm
Has thanked: 2 times
Been thanked: 21 times
Contact:

Re: Reading CAN ID issue

Post by Chris_MIRA »

To EtsDriver,
Im sure the experts from Matrix will be along to give a proper answer in a min.

Ive just looked at the two programmes and have a couple of (hopefully helpful ) observations :D

For the "Node" code, you have the Rx buffer 0 to reject all, so you dont need to set any further masks or filters, it will just ignore all messages sent by other devices on the CAN network.

For the "Receiver" programme,

I cant see where you have placed the CAN communication icon on the dash board? If this isn't there, I cant bring it up to check the settings...

Im sorry if Im miss understanding as well, but fro myour past posts on this topic, I think there may be some confusion? Masks and filters are used to pre-select the range of message id's on the CAN network you want your micro to listen for, and screen out the message id's you are not interested in. The "getRx id Hi, id Low, id simple" are used to check the id of the message once you have received it. Hope this helps :D
Regards,
Chris

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: Reading CAN ID issue

Post by Benj »

Hello,

Thanks for detailing the problem, brought me right to the bug :D

The code was like this.

Code: Select all

.Return = (.lo >> 5) || (.hi << 3)
But should instead be like this. i.e a boolean OR instead of a true/false OR. No wonder you were getting an ID of 1!

Code: Select all

.Return = (.lo >> 5) | (.hi << 3)
So the attached component should fix the problem.
CAN.fcpx
(21.95 KiB) Downloaded 148 times

EtsDriver
Posts: 444
Joined: Tue Apr 15, 2014 4:19 pm
Location: Kajaani, Finland
Has thanked: 345 times
Been thanked: 227 times
Contact:

Re: Reading CAN ID issue

Post by EtsDriver »

Chris_MIRA wrote:To EtsDriver,
Im sure the experts from Matrix will be along to give a proper answer in a min.

Ive just looked at the two programmes and have a couple of (hopefully helpful ) observations :D

For the "Node" code, you have the Rx buffer 0 to reject all, so you dont need to set any further masks or filters, it will just ignore all messages sent by other devices on the CAN network.

For the "Receiver" programme,

I cant see where you have placed the CAN communication icon on the dash board? If this isn't there, I cant bring it up to check the settings...

Im sorry if Im miss understanding as well, but fro myour past posts on this topic, I think there may be some confusion? Masks and filters are used to pre-select the range of message id's on the CAN network you want your micro to listen for, and screen out the message id's you are not interested in. The "getRx id Hi, id Low, id simple" are used to check the id of the message once you have received it. Hope this helps :D
Regards,
Chris
The receiver node is receiver, that shows the recceived message (Any, becouse its RX mask is Accept all) ID to you on LCD.

Node is purposely RX buffer reject all, because it is only sending, not receiving anything.

Im using 2D panel objects, that may confuse you.

I have working thing on my desktop here, and it reads last can message from node and shows ID on the display.

This network consists of RECEIVER and one NODE.

Node sends dummy message with ID xxx to the CAN network and the Receiver takes that dummy message, and reads it ID using GetRxIdent, correctly the xxx ID what we used to send message.

Here im telling you, that the CAN ID reading using a component macro works fine at my applications. :o

EDIT: And Benj came with solution!
Ill just keep the good work up!

Chris_MIRA
Posts: 186
Joined: Wed Jan 23, 2013 3:43 pm
Has thanked: 2 times
Been thanked: 21 times
Contact:

Re: Reading CAN ID issue

Post by Chris_MIRA »

Hi Benj,
That's great, can I just check where Im meant to put the file in FC6?
Regards,
Chris

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: Reading CAN ID issue

Post by Benj »

Hi Chris,

The file needs to live here "C:\Program Files (x86)\Flowcode 6\components"

Chris_MIRA
Posts: 186
Joined: Wed Jan 23, 2013 3:43 pm
Has thanked: 2 times
Been thanked: 21 times
Contact:

Re: Reading CAN ID issue

Post by Chris_MIRA »

All installed tested and working :D :D
Thanks for you help!
Chris

Post Reply