Arduino Nano and CAN coms (2)

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:

Arduino Nano and CAN coms (2)

Post by Chris_MIRA »

Hi,
This may be me doing something silly OR may be a bug....
Im trying to use CAN comms with an arduino Nano. I set the baud rate in flowcode normally (see programme attached) but the speeds I get out are non-standard!

For instance, setting 500 Bus in flowcode gives a hardware output of 200 kbaud (measured) and setting 1000 bus rate in Flowcode gives a 400 kbaud output (measured).

Is this a scaling bug or something Im doing wrong?
Thanks in advance for your help!
:D
Chris

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

Re: Arduino Nano and CAN coms (2)

Post by Chris_MIRA »

Ooops, forgot to load the programme....
Attachments
Arduino Nano Test.fcfx
(8.33 KiB) Downloaded 242 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: Arduino Nano and CAN coms (2)

Post by Benj »

Hi Chris,

As your using the external CAN option via the MCP2515 chip the baud rate should be ok. The AVR is only responsible for the SPI rate which shouldn't effect the CAN data rate.

I know Leigh has fixed some bugs here recently for the internal CAN so I will ask him and see if he knows anything.

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

Re: Arduino Nano and CAN coms (2)

Post by Chris_MIRA »

Hi Benj,
Thanks if you could ask, Im increasingly sure this is a bug rather than me doing something wrong, the CAN message id and data that is sent by the hardware is correct but the data rate (read directly from the hardware with resistor termination) is non-standard as I stated. Because the message is correct and is being sent at the correct time interval, Im not sure what else, other than a bug, it can be.... perhaps a scaling issue in the CAN macro?

regards,
Chris

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Arduino Nano and CAN coms (2)

Post by LeighM »

Hi Chris,

Are you using your own MCP2515 hardware? (Or our e-block)
If so, are you using a 20MHz crystal/clock on MCP2515?

Leigh

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

Re: Arduino Nano and CAN coms (2)

Post by Chris_MIRA »

Hi LeighM,

Im using a commercially available CAN module for the arduino Nano as it is to go into a product and is physically smaller. Im sure you have identified the problem as the oscillator on the module is 8Mhz rather than 20. As the Arduino CAN modules are very common and all seem to have the 8MHz clock (Ive just had a good look around on the internet and cant find any with other speeds), is it possible to provide a user input rate to the CAN module in FC6 or to accommodate different hardware clock speeds in another way? Im sure this would be very useful for others wanting to programme arduino and CAN in FC6.

Regards,
Chris

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Arduino Nano and CAN coms (2)

Post by LeighM »

Hi Chris,

Thanks for the feedback, it looks like an 8Mhz/20Mhz option would be very useful, and shouldn't be too difficult to add to the component.
I'll try and get this done.

Leigh

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

Re: Arduino Nano and CAN coms (2)

Post by Chris_MIRA »

LeighM,
That's great and would be really useful :D
have you any idea when you might be able to add a solution? Please let me know how things go.

regards,
Chris

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Arduino Nano and CAN coms (2)

Post by LeighM »

Hi Chris,

Could you please try the attached updated component?
I've added the code, but not had chance to test it.

Thanks,
Leigh
ps. 1000 kbaud won't be very accurate at 8MHz xstal
Attachments
CAN.fcpx
(23.21 KiB) Downloaded 241 times

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

Re: Arduino Nano and CAN coms (2)

Post by Chris_MIRA »

Leigh,
That's great, Im really impressed by the speed of response! Ive down loaded the file and hope to test later today... Ill let you know how I get on.
Thanks again for your response!

Regards

Chris

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

Re: Arduino Nano and CAN coms (2)

Post by Chris_MIRA »

Leigh,

I have tried the new CAN component file and all seems to be working well! Thanks again.... Will this mod go into the next FC update? :D
regards,
Chris

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Arduino Nano and CAN coms (2)

Post by LeighM »

Yes it will now that you have confirmed that it works :D

Thanks,
Leigh

Post Reply