CAN Bus

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
User avatar
dhylands
Posts: 2253
Joined: Mon Jan 06, 2014 6:08 pm
Location: Shuswap, BC, Canada
Contact:

Re: CAN Bus

Postby dhylands » Thu Mar 02, 2017 11:32 pm

giacomoalbe wrote:Many thanks @dhylands for the lighting fast answer!

You are a life saver, really!

Since I noticed you are really a PRO with CAN and uPython , I'd like to ask two questions about what you said:

1) Does the STBY pin need to be connected to ground? If I leave it simply as is (no connection) would't it be "0" always?
According to the datasheet, the STBY pin has an internal pullup, so with nothing connected it will be a 1 (i.e. in Standby Mode).
2) Is it possible to increase the baud rate with the by changing the settings in the can init OR with MCP2562 the maximum speed is 125kbaud? This chip should support high speed CAN, so it seems to be that this can be easily achieved by setting things in the right way, but asking is never wrong, in my opinion :D :D
The datasheet says that the MCP2161/2 is rated for 1 Mbps. I just happened to pick 125 kbits for experimenting. In my notes I have the following (which I think I got from another post in the forum):

Code: Select all

# This worked for 125k baud rate
can1.init(CAN.NORMAL, extframe=False, prescaler=16, sjw=1, bs1=14, bs2=6)
# This worked for 250k baud rate
can1.init(CAN.NORMAL, extframe=False, prescaler=8, sjw=1, bs1=14, bs2=6)
# This worked for 500k baud rate
can1.init(CAN.NORMAL, extframe=False, prescaler=4, sjw=1, bs1=14, bs2=6)
# This worked for 1M baud rate
can1.init(CAN.NORMAL, extframe=False, prescaler=2, sjw=1, bs1=14, bs2=6)

Tomorrow morning I'll try to apply your suggestion both in the hardware and in the software, then I'll let you know if I'll work!

After that should be a good thing to post a guide somewhere on the Web in order for other to easily manage to setup CAN communication with uPython! Thinking about doing this, in order to give back to the (astonishingly kind) community who helped out!
It would probably be good to put some examples on the doc page.

giacomoalbe
Posts: 4
Joined: Thu Dec 22, 2016 10:15 pm

Re: CAN Bus

Postby giacomoalbe » Fri Mar 03, 2017 6:45 pm

First of all, thank you very much for the help provided!

I'm glad to say that I was able to make them work! I've got a nicely set up system in which 2 uPython are able to communicate.

Soon I've to add other boards too, so maybe I'm going to ask something else!

And yes, I'd like to add some more examples in the CAN page of the Docs as soon as I have some spare time!

Thank you again and hope this helped someone else too!


Return to “The MicroPython pyboard”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest