External CAN BUS component suspect

Any bugs you encounter with Flowcode should be discussed here.
Post Reply
PAAbbott
Posts: 18
http://meble-kuchenne.info.pl
Joined: Mon Dec 28, 2020 7:24 am
Location: South Africa
Has thanked: 17 times
Been thanked: 4 times

External CAN BUS component suspect

Post by PAAbbott »

Good day Flow code 9 Team

I am currently working on developing a product for a client

It requires the external CAN BUS component and I am having some difficulties
The framework and possible problems are as follows
I have not worked with the Can Bus component before, but I think that I am not too far of with my research.
As I do get data intermittently, however, some signs lead me to think that there may be potentially some contributing factors to my struggles.
That may not be connected to my knowledge or research levels on Can Bus.
I suspect that the config settings are not being passed to the external MCP2515 Device as I have to include some custom c-code addressing the config of the device to get the intermittent data that was mentioned previously.
My current goal is to establish consistent and solid Can Bus communications with an external sensor as the rest of the signal processing and outputs will be based on the data coming in on the Can Bus.
I will include the code being used currently in my attempts to achieve this with the focus being on the Can Bus test section.
It would be highly appreciated if, someone could review my code and point out if I am making a mistake or missing something and provide me with some guidance as I still need to get the TX side sorted as well
Or if there is some bug in the Can Bus component to fix it and help me with an update to my flow code program package.
Your guidance and assistance will be highly appreciated

Kind regards
Andre
Attachments
CAN INT.7z
(5.96 KiB) Downloaded 174 times

LeighM
Valued Contributor
Posts: 401
Joined: Mon Dec 07, 2020 1:00 pm
Has thanked: 73 times
Been thanked: 218 times

Re: External CAN BUS component suspect

Post by LeighM »

Hi Andre,
Just some ideas ...
I would first check that the SPI to the MCP2515 is working reliably
The ShowLEDs function is useful for this, to toggle the output pins on the MCP2515 
Could try slower speed and try Sample End.
The MCP2515 is running with a 8MHz crystal?, might be worth checking you are getting an accurate 500bps with that (20 MHz is better)

PAAbbott
Posts: 18
Joined: Mon Dec 28, 2020 7:24 am
Location: South Africa
Has thanked: 17 times
Been thanked: 4 times

Re: External CAN BUS component suspect

Post by PAAbbott »

Good day Leigh

The MPC 2515 is fitted with a 16 MHz crystal as i am using a can bus shield see the pdf zip for precise config data
The main chip is a 18F45K20 and there are logic level converters to accommodate the level change
as for the SPI I will investigate it deeper especially using the LED set that you have pointed out

Please see the attached scope capture frames of the spi bus in the mean time as it is because these that i did not suspect the spi at the start

with regards to the slower speed are you referring to the SPI speed or the CAN BUS speed

I will revert back to you as soon as I have completed the SPI check

Your guidance and assistance are highly appreciated

Kind regards
Andre
Attachments
CAN-BUS Shield v2.0 WITH NOTES .pdf.7z
(380.81 KiB) Downloaded 163 times
SCK & MOSI .png
SCK & MOSI .png (46.3 KiB) Viewed 4444 times
SCK & MISO.png
SCK & MISO.png (43.92 KiB) Viewed 4444 times

PAAbbott
Posts: 18
Joined: Mon Dec 28, 2020 7:24 am
Location: South Africa
Has thanked: 17 times
Been thanked: 4 times

Re: External CAN BUS component suspect

Post by PAAbbott »

Good day Leigh

I have added two LEDs to the Can Bus Shield on the relevant pins and confirmed all the SPI connections and using the show LEDs function

I can definitely alter the state of the LEDs reliably and predictably repeatedly is no problem at all

Your assistance and input is highly appreciated

kind regards

Andre

LeighM
Valued Contributor
Posts: 401
Joined: Mon Dec 07, 2020 1:00 pm
Has thanked: 73 times
Been thanked: 218 times

Re: External CAN BUS component suspect

Post by LeighM »

OK, sounds good.
Note that CheckRx() returns non-zero when a new message is received.
So when zero is returned there will be no new ID and data to read.
Have you checked the bit rate of the CAN bus is correct, with your oscilloscope?

PAAbbott
Posts: 18
Joined: Mon Dec 28, 2020 7:24 am
Location: South Africa
Has thanked: 17 times
Been thanked: 4 times

Re: External CAN BUS component suspect

Post by PAAbbott »

Good day LeighM

Thank you for your response the time and afford is highly appreciated

Some bizzy days of Meetings, Paper work and details checks later on the project i have some feed back

I would like to start with

1. I noticed that you stated the CheckRx() returns non-zero when a new message is received
however during this entire time I have observed it, I have only received a one or zero and it correlated the expectation that there is only
data when a one is return and no data when a zero is returned. Your (non-zero) wording brings to mined the question is there any others
state besides zero and one that I have not yet encounter but may encounter in the future

2. I have checked the timing and can confidentially say that I believe that my initial assessment of a potential bug is now stronger
the hardware checked out all good the scope measurements as well this is only true if I insert a bit of hack code that was put to together
based on various bits of research and sources and diving in deep flow code insides
It is my conclusion that the settings shown in the red block is some how not sent or sent incorrectly to the external component or omitted
during compiling suspect it is closer to the front end of things because if I include the code in the green block inside of a
custom c-code icon the CAN bus comes to life and operate I have the same story when it comes to the processors main clock which i have
to include the code in the second green block that I have had to do sins I started with flow code and got use to it, I also noted that 16Mhz
is not on the Can OSC list

could this be a bug, my platforms configuration or operators error, if I am not mistaken it is suppose to be that the settings is entered in
the prosperity block and that's it for the configuration

I am hoping you can help with my questions

Ones again thank you for your assistance time and effort it is highly appreciated

kind regards

Andre
Attachments
Main Osc.png
Main Osc.png (24.25 KiB) Viewed 4375 times
Canbus Code hack.png
Canbus Code hack.png (39.69 KiB) Viewed 4375 times
Can bus propertys 1.png
Can bus propertys 1.png (42.8 KiB) Viewed 4375 times

User avatar
p.erasmus
Posts: 434
Joined: Thu Dec 03, 2020 12:01 pm
Location: Russia / Россия
Has thanked: 104 times
Been thanked: 88 times

Re: External CAN BUS component suspect

Post by p.erasmus »

HI,
The MPC 2515 is fitted with a 16 MHz crystal as i am using a can bus shield see the pdf zip for precise config data
Just one question in your first post you metioned that you are using a 16Mhz clock to the MCP2515
if this is the case then the OSC setting in the MCP2515 component is incorrect (8Mhz)

P1.jpg
P1.jpg (24.46 KiB) Viewed 4370 times
Regards Peter - QME Electronics

LeighM
Valued Contributor
Posts: 401
Joined: Mon Dec 07, 2020 1:00 pm
Has thanked: 73 times
Been thanked: 218 times

Re: External CAN BUS component suspect

Post by LeighM »

Hi Andre,

1) CheckRx() only returns 0 or 1

2) The CAN component only supports 8MHz or 20MHz options,
so the properties set for an Osc of 8MHz will not give the expected CAN bus rate when the hardware is using 16MHz
(You could try setting a bus rate of 250 @ 8Mhz, which would give 500 @ 16MHz)

Am I correct in thinking that with your own C code setting the bit time segments your project is working well?

PAAbbott
Posts: 18
Joined: Mon Dec 28, 2020 7:24 am
Location: South Africa
Has thanked: 17 times
Been thanked: 4 times

Re: External CAN BUS component suspect

Post by PAAbbott »

Good day p.erasmus

Thank you for your time and effort in responding

Your observation is correct, however it is because the component property's only gives you a selection between 8Mhz and 20Mhz
and no options for any alternatives or costume ones, which was surprising to me because during my hardware research the design using a 16Mhz
Crystal featured on a regular basses, as for the shield I selected it because of time constants and I consider it as a known good hardware design

and did not considered fiddling with it as an option until I was more familiarized with Can Bus and considering it is designed for Arduino
the the thought of the frequency not being there is even more surprising our will it only be available only ones I buy the Arduino package

Hence why I considered my platform package as a contributing factor all along as well as my lack of exposure to CAN Bus specific

Is there any technical reason that only those two frequencies are available to select from perhaps

I am hoping you can help with my questions

Ones again thank you for your assistance time and effort it is highly appreciated

kind regards

Andre

User avatar
p.erasmus
Posts: 434
Joined: Thu Dec 03, 2020 12:01 pm
Location: Russia / Россия
Has thanked: 104 times
Been thanked: 88 times

Re: External CAN BUS component suspect

Post by p.erasmus »

Hi Andre.

You are welcome!
As long as the FC component Clock setting and the HW clock does not correspond the component will result in Baudrate Errors.
I would change the HW Clock(XT) to the MCP2515 to a 8 or 20Mhz,I always use 20Mhz it give a good operation speed

It would be great if Matrix add the 16Mhz setting because many HW boards supports 16Mhz :D
Regards Peter - QME Electronics

Post Reply