Odd CAN MCP2515 behavior

Post Reply
magicsmoke
Posts: 6
Joined: Mon Jul 19, 2021 2:14 am
languages_spoken: english
ODROIDs: N2+
Has thanked: 0
Been thanked: 0
Contact:

Odd CAN MCP2515 behavior

Post by magicsmoke »

Hi.

I'm implementing CAN bus with my N2+

I've installed the MCP2515 as the guide states. Whenever I start the CAN controller, it starts to spam the BUS with data.

I've attached a couple of images of CAN_H diff CAN_L.

Image
Image

My linux version is Odroid's Ubuntu
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.2 LTS"
NAME="Ubuntu"
VERSION="20.04.2 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.2 LTS"
VERSION_ID="20.04"

root@odroid:~# cat /proc/version
Linux version 4.9.241-114 (root@builder_n2) (gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-6ubuntu2) ) #1 SMP PREEMPT Tue Apr 20 13:25:36 UTC 2021



If anyone could shed some light on what could be going wrong, i'm all ears.

magicsmoke
Posts: 6
Joined: Mon Jul 19, 2021 2:14 am
languages_spoken: english
ODROIDs: N2+
Has thanked: 0
Been thanked: 0
Contact:

Re: Odd CAN MCP2515 behavior

Post by magicsmoke »

I've managed to get the bus not to crash when setting the bus to listen-only mode.

It's listening fine, but once it tries to send something it just floods the BUS.

User avatar
odroid
Site Admin
Posts: 37753
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 1910 times
Been thanked: 1183 times
Contact:

Re: Odd CAN MCP2515 behavior

Post by odroid »

Did you follow this wiki page?
https://wiki.odroid.com/common/applicat ... io/can-bus

Did you see tons of garbage data from candump command after sending something?

magicsmoke
Posts: 6
Joined: Mon Jul 19, 2021 2:14 am
languages_spoken: english
ODROIDs: N2+
Has thanked: 0
Been thanked: 0
Contact:

Re: Odd CAN MCP2515 behavior

Post by magicsmoke »

Hi there.

After a bunch of debugging it was a stupid hardware issue on my part on why the diff pair looked bad.

The problem is definitely something regarding software side on the n2+.

I believe it is something to do with the 8Mhz oscillator on the module.

Could you advise how I could change the parameter.

Attached is images of the scope decoding the CANbus correctly.

Also is attached candump where the ID is wrong and there is apparently no data..

Image

Image

User avatar
odroid
Site Admin
Posts: 37753
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 1910 times
Been thanked: 1183 times
Contact:

Re: Odd CAN MCP2515 behavior

Post by odroid »

The CAN adapter board what we used for testing also has a 8Mhz X-Tal oscillator.
Which parameters do you want to change?

BTW, because we have no experience of using CAN bus in the real world, our support must be very limited.
We just performed a loop-back test and simple direct connection test between two ODROID-N2 boards as described in the WiKi page.

magicsmoke
Posts: 6
Joined: Mon Jul 19, 2021 2:14 am
languages_spoken: english
ODROIDs: N2+
Has thanked: 0
Been thanked: 0
Contact:

Re: Odd CAN MCP2515 behavior

Post by magicsmoke »

Ah,

That probably explains it then.. yeah it seems to be a common problem if the frequency is not the same..

Looking at the other thread of the CAN issues, the user there mentioned changing the spi-max-frequency to the oscillator frequency.

I've not got too much experience with building new kernels and linux operating systems, so i'll try and see if that gets it to work..

btw this isn't an odroid specific issue it seems, looks like rpi also has the same issue with mismatched frequencies.

User avatar
odroid
Site Admin
Posts: 37753
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 1910 times
Been thanked: 1183 times
Contact:

Re: Odd CAN MCP2515 behavior

Post by odroid »

Can you measure the stock default clock frequency of the SPI-CLK pin?

You don't need to compile kernel to adjust the SPI clock frequency probably.
We could increase it up to 100Mhz(72Mhz) on C4 and N2 boards from user land application software on the fly.
viewtopic.php?p=309474#p309474

User avatar
tobetter
Posts: 8148
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 474 times
Been thanked: 1275 times
Contact:

Re: Odd CAN MCP2515 behavior

Post by tobetter »

magicsmoke wrote:
Fri Jul 23, 2021 3:21 pm
I've not got too much experience with building new kernels and linux operating systems, so i'll try and see if that gets it to work..
FYI, if you need to change the spi-max-frequency, you do not need to build whole linux source tree of Hardkernel's stock 4.9 kernel. Only need to build the device tree overlay file which must can0.dtb if you have not changed anything yet.

At the top directory of the Linux kernel source tree run thiese commands replace /media/boot/dtbs/odroidn2/can0.dtbo with arch/arm64/boot/dts/amlogic/overlays/odroidn2/can0.dtbo.

Code: Select all

make odroidg12_defconfig
make dtbs
Please find the link to change the spi-max-frequency in the device tree overlay.
https://github.com/hardkernel/linux/blo ... n0.dts#L18

magicsmoke
Posts: 6
Joined: Mon Jul 19, 2021 2:14 am
languages_spoken: english
ODROIDs: N2+
Has thanked: 0
Been thanked: 0
Contact:

Re: Odd CAN MCP2515 behavior

Post by magicsmoke »

Ill be able to check the frequency later.

Currently only able to try software fixes. I see I could update the can0.dtbo using DTC.

I'm trying to build the file but keep getting a syntax error.

Code: Select all

root@odroid:/# dtc -I dts -O dtb -o can0.dtbo can0.dts
Error: can0.dts:13.23-24 syntax error
FATAL ERROR: Unable to parse input tree

Code: Select all

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/meson-g12a-gpio.h>
#include <dt-bindings/gpio/gpio.h>

/ {
	fragment@0 {
		target = <&spicc0>;

		__overlay__ {
			status = "okay";

			can0: can@0 {
				compatible = "microchip,mcp2515";
				gpio-irq = <&gpio GPIOX_3 GPIO_ACTIVE_LOW>;
				reg = <1>;
				spi-max-frequency = <8000000>;
				status = "okay";
			};
		};
	};
};
There might be some options to get it working if I can play around with this.

magicsmoke
Posts: 6
Joined: Mon Jul 19, 2021 2:14 am
languages_spoken: english
ODROIDs: N2+
Has thanked: 0
Been thanked: 0
Contact:

Re: Odd CAN MCP2515 behavior

Post by magicsmoke »

tobetter wrote:
Fri Jul 23, 2021 3:33 pm
magicsmoke wrote:
Fri Jul 23, 2021 3:21 pm
I've not got too much experience with building new kernels and linux operating systems, so i'll try and see if that gets it to work..
FYI, if you need to change the spi-max-frequency, you do not need to build whole linux source tree of Hardkernel's stock 4.9 kernel. Only need to build the device tree overlay file which must can0.dtb if you have not changed anything yet.

At the top directory of the Linux kernel source tree run thiese commands replace /media/boot/dtbs/odroidn2/can0.dtbo with arch/arm64/boot/dts/amlogic/overlays/odroidn2/can0.dtbo.

Code: Select all

make odroidg12_defconfig
make dtbs
Please find the link to change the spi-max-frequency in the device tree overlay.
https://github.com/hardkernel/linux/blo ... n0.dts#L18

I attempted this already, had issues with getting toolchain installed, even though I followed the wiki instructions.

User avatar
tobetter
Posts: 8148
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 474 times
Been thanked: 1275 times
Contact:

Re: Odd CAN MCP2515 behavior

Post by tobetter »

magicsmoke wrote:
Fri Jul 23, 2021 4:01 pm
tobetter wrote:
Fri Jul 23, 2021 3:33 pm
magicsmoke wrote:
Fri Jul 23, 2021 3:21 pm
I've not got too much experience with building new kernels and linux operating systems, so i'll try and see if that gets it to work..
FYI, if you need to change the spi-max-frequency, you do not need to build whole linux source tree of Hardkernel's stock 4.9 kernel. Only need to build the device tree overlay file which must can0.dtb if you have not changed anything yet.

At the top directory of the Linux kernel source tree run thiese commands replace /media/boot/dtbs/odroidn2/can0.dtbo with arch/arm64/boot/dts/amlogic/overlays/odroidn2/can0.dtbo.

Code: Select all

make odroidg12_defconfig
make dtbs
Please find the link to change the spi-max-frequency in the device tree overlay.
https://github.com/hardkernel/linux/blo ... n0.dts#L18

I attempted this already, had issues with getting toolchain installed, even though I followed the wiki instructions.
Can you share the error what you faced?

Post Reply

Return to “Hardware and peripherals”

Who is online

Users browsing this forum: No registered users and 2 guests