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: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: CAN Bus

Post by 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: 9
Joined: Thu Dec 22, 2016 10:15 pm

Re: CAN Bus

Post by 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!

Ghost114
Posts: 1
Joined: Thu Mar 12, 2020 7:30 am

Re: CAN Bus

Post by Ghost114 » Tue Jun 16, 2020 8:47 am

if you initialise your can bus with :
can1.init(CAN.NORMAL, extframe=False)
the default baudrate is 28kbits/s.

This was tested with a logic analyzer.

Post Reply