Page 1 of 1

Reading CAN ID issue

Posted: Fri Feb 27, 2015 10:18 am
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

Re: Reading CAN ID issue

Posted: Fri Feb 27, 2015 12:03 pm
by hyperion007
There is no attached program...

Re: Reading CAN ID issue

Posted: Mon Mar 02, 2015 9:03 am
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

Re: Reading CAN ID issue

Posted: Mon Mar 02, 2015 11:32 am
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

Re: Reading CAN ID issue

Posted: Mon Mar 02, 2015 12:26 pm
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

Re: Reading CAN ID issue

Posted: Mon Mar 02, 2015 12:30 pm
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

Re: Reading CAN ID issue

Posted: Mon Mar 02, 2015 12:59 pm
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

Re: Reading CAN ID issue

Posted: Mon Mar 02, 2015 1:28 pm
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.

Re: Reading CAN ID issue

Posted: Mon Mar 02, 2015 1:47 pm
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.

Re: Reading CAN ID issue

Posted: Mon Mar 02, 2015 2:15 pm
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

Re: Reading CAN ID issue

Posted: Mon Mar 02, 2015 2:53 pm
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.

Re: Reading CAN ID issue

Posted: Mon Mar 02, 2015 3:04 pm
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

Re: Reading CAN ID issue

Posted: Mon Mar 02, 2015 3:11 pm
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

Re: Reading CAN ID issue

Posted: Mon Mar 02, 2015 3:52 pm
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 152 times
Receiver.fcfx
(11.13 KiB) Downloaded 180 times
Try playing with the Node TX Buffer 0 Message ID and see for yourself :)

Re: Reading CAN ID issue

Posted: Mon Mar 02, 2015 4:25 pm
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

Re: Reading CAN ID issue

Posted: Mon Mar 02, 2015 4:48 pm
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 157 times

Re: Reading CAN ID issue

Posted: Mon Mar 02, 2015 4:52 pm
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!

Re: Reading CAN ID issue

Posted: Mon Mar 02, 2015 4:54 pm
by Chris_MIRA
Hi Benj,
That's great, can I just check where Im meant to put the file in FC6?
Regards,
Chris

Re: Reading CAN ID issue

Posted: Mon Mar 02, 2015 4:56 pm
by Benj
Hi Chris,

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

Re: Reading CAN ID issue

Posted: Tue Mar 03, 2015 9:57 am
by Chris_MIRA
All installed tested and working :D :D
Thanks for you help!
Chris