C4 with new DIN Rail CAN&I2C Interface Board to replace my C2 HomeAutomation

Post Reply
User avatar
joerg
Posts: 1729
Joined: Tue Apr 01, 2014 2:14 am
languages_spoken: german, english, español
ODROIDs: C1, C1+, C2, N1, N2, C4
Location: Germany
Has thanked: 155 times
Been thanked: 331 times
Contact:

C4 with new DIN Rail CAN&I2C Interface Board to replace my C2 HomeAutomation

Post by joerg »

Presenting my just received PCB for installing a C4 into a DIN Rail case.
It brings 2 times CAN with MCP2515 and TJA1051 and for compatibility with my existing IO also 1 time I2C@5V to screw terminals. Also two relay outputs controlled from GPIO.
I am waiting some parts. When I got them I will provid more information. :)
photo_2022-10-12_11-46-34.jpg
photo_2022-10-12_11-46-34.jpg (224.22 KiB) Viewed 344 times
photo_2022-10-12_11-46-41.jpg
photo_2022-10-12_11-46-41.jpg (193.31 KiB) Viewed 344 times
Last edited by joerg on Wed Oct 12, 2022 7:00 pm, edited 1 time in total.
These users thanked the author joerg for the post (total 3):
tobetter (Wed Oct 12, 2022 7:06 pm) • odroid (Wed Oct 12, 2022 8:26 pm) • mctom (Mon Oct 31, 2022 6:20 pm)

User avatar
joerg
Posts: 1729
Joined: Tue Apr 01, 2014 2:14 am
languages_spoken: german, english, español
ODROIDs: C1, C1+, C2, N1, N2, C4
Location: Germany
Has thanked: 155 times
Been thanked: 331 times
Contact:

Re: C4 with new DIN Rail Can&I2C Interface Board to replace my C2 HomeAutomation

Post by joerg »

reserved

User avatar
joerg
Posts: 1729
Joined: Tue Apr 01, 2014 2:14 am
languages_spoken: german, english, español
ODROIDs: C1, C1+, C2, N1, N2, C4
Location: Germany
Has thanked: 155 times
Been thanked: 331 times
Contact:

Re: C4 with new DIN Rail Can&I2C Interface Board to replace my C2 HomeAutomation

Post by joerg »

reserved

User avatar
joerg
Posts: 1729
Joined: Tue Apr 01, 2014 2:14 am
languages_spoken: german, english, español
ODROIDs: C1, C1+, C2, N1, N2, C4
Location: Germany
Has thanked: 155 times
Been thanked: 331 times
Contact:

[Crime] The Dupont Connection

Post by joerg »

photo_2022-10-31_08-55-17.jpg
photo_2022-10-31_08-55-17.jpg (433.9 KiB) Viewed 254 times
To investigate: Crystal of MCP2515 does not swing
These users thanked the author joerg for the post:
odroid (Mon Oct 31, 2022 7:17 pm)

User avatar
joerg
Posts: 1729
Joined: Tue Apr 01, 2014 2:14 am
languages_spoken: german, english, español
ODROIDs: C1, C1+, C2, N1, N2, C4
Location: Germany
Has thanked: 155 times
Been thanked: 331 times
Contact:

Re: C4 with new DIN Rail CAN&I2C Interface Board to replace my C2 HomeAutomation

Post by joerg »

Now I figured out, to make the two CAN interfaces work.
It' a problem with the driver mcp251x. I use a dtbo can01.dtbo self made like this:

Code: Select all

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/meson-g12a-gpio.h>
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/interrupt-controller/irq.h>
#include <dt-bindings/interrupt-controller/arm-gic.h>

/ {

	fragment@0 {
		target-path = "/";
		__overlay__ {
			clocks {
				mcp251x_osc: mcp251x_osc {
					compatible = "fixed-clock";
					#clock-cells = <0x0>;
					clock-frequency = <16000000>;
					//clock-accuracy = <100>;
					clock-output-names = "mcp251x_osc";
					status = "okay";
				};
			};
		};
	};

	fragment@1 {
		target = <&spicc0>;

		__overlay__ {
			status = "okay";
        pinctrl-0 = <&spicc0_x_pins>;
        #address-cells = <1>;
        #size-cells = <0>;
        cs-gpios = <&gpio GPIOX_10 GPIO_ACTIVE_LOW>, <&gpio GPIOH_6 GPIO_ACTIVE_LOW>, <&gpio GPIOA_15 GPIO_ACTIVE_LOW>;
			can1: can@2 {
				compatible = "microchip,mcp2515";
				clocks = <&mcp251x_osc>;
				interrupt-parent = <&gpio_intc>;
				/* INTR on GPIOX_4 */
				interrupts = <81 IRQ_TYPE_LEVEL_LOW>;
				reg = <0x02>;
				spi-max-frequency = <10000000>;
				status = "okay";
				//spi-cpol;
			};
			can0: can@1 {
				compatible = "microchip,mcp2515";
				clocks = <&mcp251x_osc>;
				interrupt-parent = <&gpio_intc>;
				/* INTR on GPIOX_3 */
				interrupts = <80 IRQ_TYPE_LEVEL_LOW>;
				reg = <0x01>;
				spi-max-frequency = <10000000>;
				status = "okay";
				//spi-cpol;
			};
		};
	};

	fragment@2 {
		target = <&spicc0_x_pins>;

		__overlay__ {
			mux {
				groups = "spi0_mosi_x",
						"spi0_miso_x",
						"spi0_clk_x";
				function = "spi0";
				#bias-pull-up;
				bias-disable;
				drive-strength-microamp = <4000>;
			};
		};
	};
};
But when the C4 with kernel 5.15 is started up the log says that 2nd interface not went to configuration mode.
I spent only the first mcp2515 a 16Mhz crystal, the second gets the clock signal from the first one CLKOUT:
Bildschirmfoto vom 2022-11-13 12-25-02.png
Bildschirmfoto vom 2022-11-13 12-25-02.png (59.91 KiB) Viewed 194 times
With the dtbo as above I can remove the driver with modprobe -r mcp251x and load it again. Then the second interface also comes up. Why it is so? I think the first mcp2515 is not yet ready initialized when the second is probed and so the CLKOUT is not yet there. It's there when the driver starts the second time. BTW, when I switch the can0 and can1 in the dtbs file this workaround doesn't work and the second interface stays uninitialized.
Thinking modify the driver code once more to make a delay into the probe function. I have modified the code already to enable the CLKOUT.
Or does exist another trick to have the first interface initialized ready before the next interface is probed?

Another thing, there was a bug in my PCB :( . The pin 8 of TJA1051 was stripped to 5V, not to GND. This makes silent mode and disables the sending part. When I made this I was somehow thinking that it is Enable pin. :x
These users thanked the author joerg for the post (total 2):
steve.jeong (Mon Nov 14, 2022 9:10 am) • odroid (Mon Nov 14, 2022 10:18 am)

User avatar
joerg
Posts: 1729
Joined: Tue Apr 01, 2014 2:14 am
languages_spoken: german, english, español
ODROIDs: C1, C1+, C2, N1, N2, C4
Location: Germany
Has thanked: 155 times
Been thanked: 331 times
Contact:

Re: C4 with new DIN Rail CAN&I2C Interface Board to replace my C2 HomeAutomation

Post by joerg »

No luck until now.
I tried to set some delay time into the driver probe, but problem still occurs:

Code: Select all

dmesg
[    9.506336] mcp251x spi0.1 can0: MCP2515 successfully initialized.
[   11.547903] mcp251x spi0.2: MCP251x didn't enter in conf mode after reset
[   11.547999] mcp251x spi0.2: Probe failed, err=110
[   11.548012] mcp251x: probe of spi0.2 failed with error -110

sudo modprobe -r  mcp251x

sudo modprobe mcp251x

dmesg
[  804.272904] CAN device driver interface
[  804.284615] mcp251x spi0.1 can0: MCP2515 successfully initialized.
[  804.323902] IPv6: ADDRCONF(NETDEV_CHANGE): can0: link becomes ready
[  804.324275] mcp251x spi0.2 can1: MCP2515 successfully initialized.
[  805.347065] IPv6: ADDRCONF(NETDEV_CHANGE): can1: link becomes ready
There are 2 seconds between first can0 (that has 16MHz crystal) and failed can1 (that gets clock from first mcp2515).
After removing the kernel module and loading again, everything works.

I looked into options to dynamically load a dtbo, but it seems that the tool dtoverlay only exists in the Rpi world...

Code: Select all

Der Befehl 'dtoverlay' wurde nicht gefunden, kann aber installiert werden mit:
sudo apt install libraspberrypi-bin

User avatar
joerg
Posts: 1729
Joined: Tue Apr 01, 2014 2:14 am
languages_spoken: german, english, español
ODROIDs: C1, C1+, C2, N1, N2, C4
Location: Germany
Has thanked: 155 times
Been thanked: 331 times
Contact:

Re: C4 with new DIN Rail CAN&I2C Interface Board to replace my C2 HomeAutomation

Post by joerg »

And the solution is:

Make new blacklist file in /etc/modprobe.d

Code: Select all

sudo nano /etc/modprobe.d/blacklist-can.conf
Add this

Code: Select all

blacklist mcp251x
Add a cron job at reboot

Code: Select all

sudo crontab -e
Add this at the end of file

Code: Select all

@reboot /usr/sbin/modprobe mcp251x
No failed can interface anymore. :)
These users thanked the author joerg for the post:
mctom (Sun Nov 20, 2022 12:16 am)

Post Reply

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 2 guests