CanBus Read Example

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

Moderator: Benj

jhill
Posts: 58
Joined: Thu Jan 31, 2019 3:46 pm
Has thanked: 11 times
Been thanked: 12 times
Contact:

CanBus Read Example

Postby jhill » Tue Mar 10, 2020 12:54 pm

Hi,

Can anybody point me to an flowcode 8 example of using the CAN bus component makro to recieve packets, the example looks to be transmit only?

Best Regards

James

User avatar
LeighM
Matrix Staff
Posts: 2014
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 480 times
Been thanked: 691 times
Contact:

Re: CanBus Read Example

Postby LeighM » Wed Mar 11, 2020 11:40 am

Hi James
You need to setup your CAN component RX buffer properties (mask and filter if needed, or just Accept All)
Program flow is then a case of doing an Initialise at startup.
Then loop calling CheckRx (with the required buffer as a parameter)
If it returns true, then a message is waiting to be read.
At which point call GetRxDataCount, GetRxData etc
Hope that helps
These users thanked the author LeighM for the post:
jhill (Thu Mar 12, 2020 8:47 am)
Rating: 5%
 

jhill
Posts: 58
Joined: Thu Jan 31, 2019 3:46 pm
Has thanked: 11 times
Been thanked: 12 times
Contact:

Re: CanBus Read Example

Postby jhill » Thu Mar 12, 2020 8:47 am

Thankyou Liegh, Ill try that and see how it goes.

Kind Regards,

James

jhill
Posts: 58
Joined: Thu Jan 31, 2019 3:46 pm
Has thanked: 11 times
Been thanked: 12 times
Contact:

Re: CanBus Read Example

Postby jhill » Sun Mar 29, 2020 7:51 pm

Hi Leigh,

I am trying to recieve a standard can bus message of 8 bytes from id 0x611 and am having a few issues, please see program attached.

No matter how i set the filter in the component proterties, it makes no difference to the recieved data. Data is recieved even if i select reject all. Secondly the recieved data, i.e can message id and length seem random? As far as i undertand it the id should be 0x??? and the data length for a standard message 8 bytes?
Hardware in a ecio 40 and a mcp2515.

Would you mind taking a look at the attched?

Best Regards

James
Capture.PNG
Capture.PNG (52.43 KiB) Viewed 477 times
Attachments
Can V 0.2.fcfx
(21.13 KiB) Downloaded 15 times

User avatar
LeighM
Matrix Staff
Posts: 2014
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 480 times
Been thanked: 691 times
Contact:

Re: CanBus Read Example

Postby LeighM » Mon Mar 30, 2020 9:25 am

A few possibilities:
What MCP2515 hardware are you using? Does it have 20MHz crystal? (Some Arduino modules have 16MHz)
You could use the ShowLEDs() macro to toggle outputs on the MCP2515 to check that the SPI is connected and working?
What is the incoming rate of the CAN messages? You have got quite some delays and printing, is there enough time to do that between messages?
You have an extra ID=GetRxIdent() - but that's not a major issue

jhill
Posts: 58
Joined: Thu Jan 31, 2019 3:46 pm
Has thanked: 11 times
Been thanked: 12 times
Contact:

Re: CanBus Read Example

Postby jhill » Mon Mar 30, 2020 10:28 am

Hi Leigh,
Thank you for getting back to me. The hardware is an old Elektor project, i have checked the crystal and it is 20Mhz. It looks like the SPI is connected and working as if i disconnect the can bus i no longer receive messages, but I will try toggling the outputs as you suggest.
I also have a Raspberry pi and usb can interface on the bus where i can recieve and decode the messages, so i know they are present on the bus.
I added the delays as an experiment as i have found on previous flowcode projects that if i don’t add delays between spi transactions it just doesn’t work, so I can remove these if they are not required in this case.
Best Regards
James
Attachments
Capture.PNG
Capture.PNG (74.95 KiB) Viewed 456 times

jhill
Posts: 58
Joined: Thu Jan 31, 2019 3:46 pm
Has thanked: 11 times
Been thanked: 12 times
Contact:

Re: CanBus Read Example

Postby jhill » Wed Apr 01, 2020 12:41 pm

Hi Leigh,

Following your advise a found I was unable to toggle the binary outputs.I subseqently found a connection issue between the MCP2515 and the MCP2551. Fixing this resolved everything. Outputs now toggle and the recieved CAN data is as expected.

Thanks for pointing me in the right direction.

Best Regards

James.
These users thanked the author jhill for the post:
Benj (Wed Apr 01, 2020 2:14 pm)
Rating: 5%