Page 1 of 1

Energy Controller including CCS interface

Posted: Fri Oct 31, 2025 1:06 pm
by johu
As mentioned here I've always wanted to create an all-in-one energy controller to clean up the mess in my basement. It is based on the popular BeagleBone Black or Green, so it's called a "cape".

Hardware-wise it is mainly communication stuff. The task of the thing is to control various energy conversion equipment such as
- PV inverters
- Batteries (or BMSes to be precise)
- CCS
- Relays

It also talks to web services such as spot market price providers, data loggers and of course has infinite connectivity over Wifi or Ethernet.

I pretty much copied the hardware that I currently use so the interfaces are
- 2x CAN
- 1x PLC for CCS charging, including CP signalling
- 2 relay drivers
- Input for push button with LED (button just shorts out LED current

I might add RS485 as well as I have only used up 10 of 12 screw terminals.

So far this is how it looks
image.png
PLC part still to be done.

Re: Energy Controller including CCS interface

Posted: Fri Oct 31, 2025 3:32 pm
by tom91
RS485 is a good idea for an industrial AC energy meter, or do you have a plan to route those over something like Home Assistant?

Re: Energy Controller including CCS interface

Posted: Sat Nov 01, 2025 8:30 am
by johu
tom91 wrote: Fri Oct 31, 2025 3:32 pm RS485 is a good idea for an industrial AC energy meter, or do you have a plan to route those over something like Home Assistant?
Yes and also for simulating an energy meter e.g. for Huawei inverters that have no other means of controlling their feed-in power.

First cut done, only RS485 missing
image.png
SPI flash can be connected to the SPI bus for initial programming by the BeagleBone itself

Re: Energy Controller including CCS interface

Posted: Sat Nov 01, 2025 3:32 pm
by johu
Before ordering I wanted to make sure that I can talk to the QCA with the linux kernel.
1762008169487.jpg
It is a bit of a palaver.

Here's the howto running QCA7000 on BeagleBone via SPI

Find out which kernel your BeagleBone is running:

Code: Select all

> uname -r
< 5.10.168-ti-r71
Now you need to get the matching kernel. On your desktop PC run

Code: Select all

git clone https://github.com/RobertCNelson/ti-linux-kernel-dev.git
cd ti-linux-kernel-dev/
git checkout 5.10.168-ti-r71
./build_kernel.sh
obviously you need to checkout the version matching your kernel in the 3rd command

The script will now endlessly download stuff (I think the standard linux kernel) and patch it. Then it will open the configuration menu. You need to set

Code: Select all

Device Drivers -> Network Device Support -> Ethernet Driver Support -> [*] Qualcomm Devices -> <M> Qualcomm Atheros QCA7000 SPI support
So once you find Qualcomm Devices you select them with the space key. Then the various devices show up and you select ....QCA7000 SPI and press M.
Then navigate to the Save button and press it, then Exit by selecting "Exit" until the menu exits

Then the build process automatically starts.

Now in the "deploy" directory you will find 5.10.168-ti-r71-modules.tar.gz. Open it and navigate to

Code: Select all

 ./lib/modules/5.10.168-ti-r71/kernel/drivers/net/ethernet/qualcomm
Here you'll find two .ko.xz files. Copy them to your BeagleBone

Now back to the BeagleBone console. Extract the xz files and copy them into the kernel tree with

Code: Select all

xz -d qca_7k_common.ko.xz
xz -d qcaspi.ko.xz
sudo mkdir /lib/modules/5.10.168-ti-r71/kernel/drivers/net/ethernet/qualcomm
sudo mv *.ko /lib/modules/5.10.168-ti-r71/kernel/drivers/net/ethernet/qualcomm
sudo depmod -a
Now create the file

Code: Select all

/opt/source/bb.org-overlays/src/arm/BB-SPI0-QCASPI-00A0.dts
and put the following code into it:

Code: Select all

/*
 * Copyright (C) 2019 Tomas Arturo Herrera Castro <taherrera@uc.cl>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 * 
 * Written as part of my master's thesis at PUC Chile,
 * to run the BeagleBone as an OpenThread Border Router w/o an NCP.
 *
 * https://www.sltech.cl
 *
 * Compiled using: make ./src/arm/BB-SPI0-QCASPI-00A0.dtbo
 *
 * Tested on BeagleBone Black Rev. C + REB233-XPRO. Linux beaglebone 4.14.71-ti-r80.
 *
 */

/dts-v1/;
/plugin/;

#include <dt-bindings/board/am335x-bbw-bbb-base.h>
#include <dt-bindings/pinctrl/am33xx.h>
#include <dt-bindings/interrupt-controller/irq.h>

/ {
	/*
	 * Helper to show loaded overlays under: /proc/device-tree/chosen/overlays/
	 */
	fragment@0 {
		target-path="/";
		__overlay__ {

			chosen {
				overlays {
					BB-SPI0-QCASPI-00A0 = __TIMESTAMP__;
				};
			};
		};
	};

	/*
	 * Free up the pins used by the cape from the pinmux helpers.
	 */
	fragment@1 {
		target = <&ocp>;
		__overlay__ {
			P9_17_pinmux { status = "disabled"; };	/* P9_17 (A16) spi0_cs0.spi0_cs0 */
			P9_18_pinmux { status = "disabled"; };	/* P9_18 (B16) spi0_d1.spi0_d1 */
			P9_21_pinmux { status = "disabled"; };	/* P9_21 (B17) spi0_d0.spi0_d0 */
			P9_22_pinmux { status = "disabled"; };	/* P9_22 (A17) spi0_sclk.spi0_sclk */

			P9_15_pinmux { status = "disabled"; };	/* irq P9_15 (R13) gpmc_a0.gpio1[16] */
		};
	};

	fragment@2 {
		target = <&am33xx_pinmux>;
		__overlay__ {
			bb_qca_pins: bb_qca_pins {
				pinctrl-single,pins = <
					AM33XX_PADCONF(AM335X_PIN_GPMC_A0, PIN_INPUT_PULLDOWN, MUX_MODE7)    /* irq P9_15 (R13) gpmc_a0.gpio1[16] */
				>;
			};
			spi0_qca_s0: spi0_qca_s0 {
				pinctrl-single,pins = <
					AM33XX_PADCONF(AM335X_PIN_SPI0_SCLK, PIN_INPUT, MUX_MODE0) /* P9_22 (A17) spi0_sclk.spi0_sclk */
					AM33XX_PADCONF(AM335X_PIN_SPI0_D0, PIN_INPUT, MUX_MODE0)   /* P9_21 (B17) spi0_d0.spi0_d0 */
					AM33XX_PADCONF(AM335X_PIN_SPI0_D1, PIN_INPUT, MUX_MODE0)   /* P9_18 (B16) spi0_d1.spi0_d1 */
					AM33XX_PADCONF(AM335X_PIN_SPI0_CS0, PIN_INPUT, MUX_MODE0)  /* P9_17 (A16) spi0_cs0.spi0_cs0 */
				>;
			};
		};
	};

	fragment@3 {
		target = <&spi0>;
		__overlay__ {
			#address-cells = <1>;
			#size-cells = <0>;

			status = "okay";
			pinctrl-names = "default";
			pinctrl-0 = <&spi0_qca_s0>;

			eth1: qcaspi@0 {
				compatible = "qca,qca7000";

				pinctrl-names = "default";
				pinctrl-0 = <&bb_qca_pins>;

				spi-max-frequency = <12000000>;
				reg = <0>;
				interrupt-parent = <&gpio1>;
				interrupts = <16 IRQ_TYPE_EDGE_RISING>; /* gpio1[16] active high */
			};
		};
	};
	
};
The interrupt line of the QCA chip is connected to P9_15 and the other pins are connected to P9 as well:
SPI0_CS:17 -> CS
SPI0_D1:18 -> MOSI
SPI0_D0:21 -> MISO
SPI0_CLK:22 -> CLK

Now compile the device trees and copy the new file where it is expected with

Code: Select all

cd /opt/source/bb.org-overlays/
make
sudo cp src/arm/BB-SPI0-QCASPI-00A0.dtbo /lib/firmware/
Now in /boot/uEnv.txt enable the new file with

Code: Select all

uboot_overlay_addr0=BB-SPI0-QCASPI-00A0.dtbo
Of course it can be any other addrX, too if you're already using other files.
Now reboot and watch the debug terminal in case something goes wrong.

Ultimately you should see

Code: Select all

[   28.949382] qcaspi spi0.0: ver=0.2.7-i, clkspeed=12000000, burst_len=5000, pluggable=0
[   29.041706] qcaspi spi0.0: Using random MAC address: 56:7b:be:8b:cd:74
Check that you can find the chip with

Code: Select all

> int6klist -v -i eth1

00000000 00 B0 52 00 00 01 AA 38 9F A8 13 32 88 E1 00 00 ..R....8...2....
00000010 A0 00 B0 52 00 00 00 00 00 00 00 00 00 00 00 00 ...R............
00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000030 00 00 00 00 00 00 00 00 00 00 00 00             ............    

00000000 AA 38 9F A8 13 32 04 65 65 FF FF FF 88 E1 00 01 .8...2.ee.......
00000010 A0 00 B0 52 00 22 25 4D 41 43 2D 51 43 41 37 30 ...R."%MAC-QCA70
00000020 30 35 2D 31 2E 31 2E 30 2E 37 33 30 2D 30 34 2D 05-1.1.0.730-04-
00000030 32 30 31 34 30 38 31 35 2D 43 53 00 CC CC CC CC 20140815-CS.....
Now pyPLC should run as well

Re: Energy Controller including CCS interface

Posted: Tue Nov 11, 2025 12:12 pm
by PoloLbricolo
Super interesting subject ! Could this be used to do bi-directional charging from solar / to house ?

Re: Energy Controller including CCS interface

Posted: Tue Nov 11, 2025 4:56 pm
by uhi22
This is exactly the topic. However, this is just the control box, it needs an additional power device like a hybrid solar inverter.

Re: Energy Controller including CCS interface

Posted: Wed Nov 12, 2025 5:57 pm
by johu
And it's on the table
1762892021784.jpg
Almost worked out of the box, some resistors were not fitted and there ist a minor mistake in the pin mapping of the boost converter that makes +-12V for CP PWM.

With that fixed we have PWM
image.png
and the QCA chip is detected and communicates

Currently no firmware on the flash, I'm trying to figure out whether I can flash it via plctools without messing with the solder jumpers. If anyone knows where to find a firmware image for the QCA7005 or how to extract it from uhis binary, let me know
https://github.com/uhi22/Ioniq28Investi ... _33_79.bin

Re: Energy Controller including CCS interface

Posted: Wed Nov 12, 2025 10:26 pm
by johu
Flashed the image directly today, works well with the solder jumpers.

Changed the PIB file for EVSE use and simply flashed with plctool. I had to change more than the 4 items commonly mentioned here, used this script: https://github.com/qca/open-plc-utils/b ... ac/evse.sh

I also changed the MAC address using "modpib -m" as otherwise it's the same as Focccis.

Then started CP PWM, connected to Foccci which woke right up and off we go into CurrentDemand :)

Analog reading of CP PWM divided value reliably detects states A-C

Also tested CAN which also works. Very suspicious, no mistakes? huh

Re: Energy Controller including CCS interface

Posted: Thu Nov 13, 2025 12:11 pm
by johu
And here's another closeup of the CP PWM slew rate
image.png
On V2 will probably change it to TLV1805

Re: Energy Controller including CCS interface

Posted: Fri Nov 14, 2025 4:54 pm
by johu
And it's in :)
1763138635066.jpg
Just a reminder of what it used to look like
Image

The switch became redundant for now because Ethernet is now only needed for inverter comms.

With a bit of consolidation I could go back to my single DIN rail enclosure

Re: Energy Controller including CCS interface

Posted: Sun Nov 16, 2025 3:40 pm
by johu
haha, managed to boot strap the SPI flash without solder jumpers on my second module :) All you need is the firmware image from uhis repo (https://github.com/uhi22/Ioniq28Investi ... _33_79.bin) and open-plc-utils.

We start with

Code: Select all

> int6klist -v
< 00000000 00 B0 52 00 00 01 AA 38 9F A8 13 32 88 E1 00 00 ..R....8...2....
00000010 A0 00 B0 52 00 00 00 00 00 00 00 00 00 00 00 00 ...R............
00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000030 00 00 00 00 00 00 00 00 00 00 00 00             ............    

00000000 AA 38 9F A8 13 32 00 B0 52 00 00 01 88 E1 00 01 .8...2..R.......
00000010 A0 00 B0 52 00 06 0B 42 6F 6F 74 4C 6F 61 64 65 ...R...BootLoade
00000020 72 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r...............
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000050 00 00 00 00 00 00 00 00 7C 58 1B 00 00 00 00 00 ........|X......
00000060 01 00 00 00 3F 00 00 00 00 00 00 00             ....?.......    

00:B0:52:00:00:01
See how it says "BootLoader"? That's what we want.

Then do

Code: Select all

nvmsplit -v CCM_FlashDump_SpiFlash_2MB_Ioniq_00_33_79.bin
nvmmerge CCM_FlashDump_SpiFlash_2MB_Ioniq_00_33_79-0* > softloader.nvm
tail -c +65537 CCM_FlashDump_SpiFlash_2MB_Ioniq_00_33_79.bin > firmware.bin
nvmsplit firmware.bin
nvmmerge firmware-* > firmware.nvm
tail -c +917505 CCM_FlashDump_SpiFlash_2MB_Ioniq_00_33_79.bin > pib.bin
nvmsplit pib.bin
nvmmerge pib-0* > evse.pib
setpib evse.pib 74 hfid "EVSE"
setpib evse.pib F4 byte 2
setpib evse.pib 1653 byte 2
setpib evse.pib 1C98 long 10240 long 102400
setpib evse.pib 1F80 byte 0
setpib evse.pib 16D2 byte 0
setpib evse.pib 16D3 byte 1
modpib -M 04:65:65:FF:FF:00 evse.pib
plcboot -F -S softloader.nvm -N firmware.nvm -P evse.pib
First command results in 3 files from the "file system" of the flash. We merge them back together.
Then we splice 64k from the beginning of the file which brings us to the firmware "partition" and repeat the same trick. Same with the PIB file which we modify for EVSE use.

And now we get

Code: Select all

> int6klist -v
< 00000000 00 B0 52 00 00 01 AA 38 9F A8 13 32 88 E1 00 00 ..R....8...2....
00000010 A0 00 B0 52 00 00 00 00 00 00 00 00 00 00 00 00 ...R............
00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000030 00 00 00 00 00 00 00 00 00 00 00 00             ............    

00000000 AA 38 9F A8 13 32 04 65 65 FF FF 00 88 E1 00 01 .8...2.ee.......
00000010 A0 00 B0 52 00 22 25 4D 41 43 2D 51 43 41 37 30 ...R."%MAC-QCA70
00000020 30 35 2D 31 2E 31 2E 30 2E 37 33 30 2D 30 34 2D 05-1.1.0.730-04-
00000030 32 30 31 34 30 38 31 35 2D 43 53 00 CC CC CC CC 20140815-CS.....
00000040 CC CC CC CC CC 00 00 00 00 00 00 00 00 00 00 00 ................
00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000110 00 00 00 00 00 7C 58 1B 00 00 00 00 00 01 00 00 .....|X.........
00000120 00 3F 00 00 00 00 00 00 00                      .?.......       

04:65:65:FF:FF:00
So the new firmware and the new MAC address from the PIB file.

Re: Energy Controller including CCS interface

Posted: Wed Nov 19, 2025 10:15 am
by johu
I set up a wiki page https://openinverter.org/wiki/FoccciCape

I've also added the precharge supply back in. I connected a 10uF 400V elcap and a 1M resistor to the output. This gives it a pretty deterministic voltage ramp which I think is also slow enough (0-400V in 6s) so that the vehicle will just report precharge completed.

Will start selling it on the shop soon. Hows interest?

Re: Energy Controller including CCS interface

Posted: Wed Nov 19, 2025 5:37 pm
by PoloLbricolo
I'll be interested, quite curious if my old Tesla will let me draw power out of it.