DK9
Posts: 3
Joined: Sat Jan 28, 2017 3:01 pm

RPI3 mcp2515 issues

Sat Jan 28, 2017 3:23 pm

Cant get my head around this issue, even tho I've tested every single example, how-to and guides found in forums and other google searches.

Ive enable dtoverlay for mcp2515 and spi and it kind of seems to work, except clock setting.

Here's my outputs

/boot/config.txt

Code: Select all

dtparam=spi=on
dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25
#dtoverlay=mcp2515-can1,oscillator=16000000,interrupt=24
dtoverlay=spi-bcm2835
dtdebug=1
enable_uart=0
journal

Code: Select all

root@raspberrypi:~# journalctl | grep CAN
Jan 28 15:49:37 raspberrypi kernel: CAN device driver interface
root@raspberrypi:~# journalctl | grep can
root@raspberrypi:~# journalctl | grep SPI
root@raspberrypi:~# journalctl | grep spi
root@raspberrypi:~#
ip link

Code: Select all

root@raspberrypi:~# ip -s -d link show can0
3: can0: <NOARP,ECHO> mtu 16 qdisc noop state DOWN mode DEFAULT group default qlen 10
    link/can  promiscuity 0
    can state STOPPED restart-ms 0
	  mcp251x: tseg1 3..16 tseg2 2..8 sjw 1..4 brp 1..64 brp-inc 1
	  clock 8000000
	  re-started bus-errors arbit-lost error-warn error-pass bus-off
	  0          0          0          0          0          0
    RX: bytes  packets  errors  dropped overrun mcast
    0          0        0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    0          0        0       0       0       0
root@raspberrypi:~#
As seen in ip link details, clock is at 8Mhz but my controller has 16Mhz oscillator.
I have verified the controller to work with arduino. Also tried to compile new dtbo for can0 since i suspected osc value to be hardcoded in dtbo, but no success.

Any ideas ?
Or is there a way to get clock to 16mhz ?

bertr2d2
Posts: 98
Joined: Wed Aug 08, 2012 10:12 pm

Re: RPI3 mcp2515 issues

Sun Jan 29, 2017 5:20 am

Hi,

the 8 MHz is fine because
http://lxr.free-electrons.com/source/dr ... 1x.c?v=4.4

Code: Select all

1036         clk = devm_clk_get(&spi->dev, NULL);
1037         if (IS_ERR(clk)) {
1038                 if (pdata)
1039                         freq = pdata->oscillator_frequency;
1040                 else
1041                         return PTR_ERR(clk);
1042         } else {
1043                 freq = clk_get_rate(clk);
1044         }
...
1067         priv->can.clock.freq = freq / 2;
the frequency is devided by 2. This frequency is internally used to calculate the timing parameters.

Regards

Gerd
Easy to build CAN-Bus interface:
http://lnxpps.de/rpie

DK9
Posts: 3
Joined: Sat Jan 28, 2017 3:01 pm

Re: RPI3 mcp2515 issues

Sun Jan 29, 2017 11:29 am

bertr2d2 wrote:Hi,

the 8 MHz is fine because
http://lxr.free-electrons.com/source/dr ... 1x.c?v=4.4

Code: Select all

1036         clk = devm_clk_get(&spi->dev, NULL);
1037         if (IS_ERR(clk)) {
1038                 if (pdata)
1039                         freq = pdata->oscillator_frequency;
1040                 else
1041                         return PTR_ERR(clk);
1042         } else {
1043                 freq = clk_get_rate(clk);
1044         }
...
1067         priv->can.clock.freq = freq / 2;
the frequency is devided by 2. This frequency is internally used to calculate the timing parameters.

Regards

Gerd
I see...
For the record, that means, even tho can interfaces appear with other clocking values than the actual oscillator, clock is not reflecting MCP2515 configuration ?

Hooking other custom interfaces on the bus-line do receive and send frames, except RPI3.

Return to “Interfacing (DSI, CSI, I2C, etc.)”