Skip to content

Commit

Permalink
Merge remote-tracking branch 'tbnobody/OpenDTU/master' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
helgeerbe committed Apr 28, 2023
2 parents 2d14d9f + 90a0cb6 commit dae4c6f
Show file tree
Hide file tree
Showing 17 changed files with 432 additions and 187 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ Compatibility with OpenDTU is most likly related to the serial number of the inv
* English, german and french web interface
* Displays (SSD1306, SH1106, PCD8544)
* Status LEDs
* Konfiguration management (export / import configurations)
* Configuration management (export / import configurations)
* Dark Theme

## Features for developers
Expand Down Expand Up @@ -467,6 +467,13 @@ A documentation of all available MQTT Topics can be found here: [MQTT Documentat

A documentation of the Web API can be found here: [Web-API Documentation](docs/Web-API.md)

## OpenDTU Breakoutboard
We sat down together and designed a PCB. This is 100% compatible with openDTU and has space for all extensions such as display and LEDs. You can find the PCB design here: https://github.com/marove2000/openDTU_BreakoutBoard

A ready to solder kit can be found here: https://shop.blinkyparts.com/en/OpenDTU-Your-evaluation-for-your-balcony-solar-system/blink237542

<img src="docs/builds/opendtu_breakoutboard.jpg" alt='OpenDTU Breakout Board with Case' height='300px'><img src="docs/builds/thumbnail.jpg" alt='OpenDTU Breakout Board with Case' height='300px'>

## Available cases

* <https://www.thingiverse.com/thing:5435911>
Expand Down
190 changes: 190 additions & 0 deletions docs/DeviceProfiles/opendtu_fusion.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
[
{
"name": "OpenDTU Fusion v1",
"nrf24": {
"miso": 48,
"mosi": 35,
"clk": 36,
"irq": 47,
"en": 38,
"cs": 37
},
"eth": {
"enabled": false,
"phy_addr": -1,
"power": -1,
"mdc": -1,
"mdio": -1,
"type": 0,
"clk_mode": 0
},
"led": {
"led0": 17,
"led1": 18
}
},
{
"name": "OpenDTU Fusion v1 with SSD1306 Display",
"nrf24": {
"miso": 48,
"mosi": 35,
"clk": 36,
"irq": 47,
"en": 38,
"cs": 37
},
"eth": {
"enabled": false,
"phy_addr": -1,
"power": -1,
"mdc": -1,
"mdio": -1,
"type": 0,
"clk_mode": 0
},
"led": {
"led0": 17,
"led1": 18
},
"display": {
"type": 2,
"data": 2,
"clk": 1
}
},
{
"name": "OpenDTU Fusion v1 with SH1106 Display",
"nrf24": {
"miso": 48,
"mosi": 35,
"clk": 36,
"irq": 47,
"en": 38,
"cs": 37
},
"eth": {
"enabled": false,
"phy_addr": -1,
"power": -1,
"mdc": -1,
"mdio": -1,
"type": 0,
"clk_mode": 0
},
"led": {
"led0": 17,
"led1": 18
},
"display": {
"type": 3,
"data": 2,
"clk": 1
}
},
{
"name": "OpenDTU Fusion v2 with CMT2300A and NRF24",
"nrf24": {
"miso": 48,
"mosi": 35,
"clk": 36,
"irq": 47,
"en": 38,
"cs": 37
},
"cmt": {
"clk": 6,
"cs": 4,
"fcs": 21,
"sdio": 5,
"gpio2": 3,
"gpio3": 8
},
"eth": {
"enabled": false,
"phy_addr": -1,
"power": -1,
"mdc": -1,
"mdio": -1,
"type": 0,
"clk_mode": 0
},
"led": {
"led0": 17,
"led1": 18
}
},
{
"name": "OpenDTU Fusion v2 with CMT2300A, NRF24 and SH1106 Display",
"nrf24": {
"miso": 48,
"mosi": 35,
"clk": 36,
"irq": 47,
"en": 38,
"cs": 37
},
"cmt": {
"clk": 6,
"cs": 4,
"fcs": 21,
"sdio": 5,
"gpio2": 3,
"gpio3": 8
},
"eth": {
"enabled": false,
"phy_addr": -1,
"power": -1,
"mdc": -1,
"mdio": -1,
"type": 0,
"clk_mode": 0
},
"led": {
"led0": 17,
"led1": 18
},
"display": {
"type": 3,
"data": 2,
"clk": 1
}
},
{
"name": "OpenDTU Fusion v2 with CMT2300A, NRF24 and SSD1306 Display",
"nrf24": {
"miso": 48,
"mosi": 35,
"clk": 36,
"irq": 47,
"en": 38,
"cs": 37
},
"cmt": {
"clk": 6,
"cs": 4,
"fcs": 21,
"sdio": 5,
"gpio2": 3,
"gpio3": 8
},
"eth": {
"enabled": false,
"phy_addr": -1,
"power": -1,
"mdc": -1,
"mdio": -1,
"type": 0,
"clk_mode": 0
},
"led": {
"led0": 17,
"led1": 18
},
"display": {
"type": 2,
"data": 2,
"clk": 1
}
}
]
2 changes: 1 addition & 1 deletion docs/MQTT_Topics.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Serial will be replaced with the serial number of the respective device.
| dtu/status | R | Indicates whether OpenDTU network is reachable | online / offline |
| dtu/uptime | R | Time in seconds since startup | seconds |

## Inverter total topicss
## Inverter total topics

Enabled inverter means, that only inverters with "Poll inverter data" enabled are considered.

Expand Down
9 changes: 9 additions & 0 deletions docs/builds/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Builds using different boards

## ESP32 Dev Board

### Build by @tbnobody, jan and @marove2000
* Used build environment: generic
* Case: https://www.printables.com/de/model/441037-opendtu-breakoutboard-case
* Soldering Kit: https://shop.blinkyparts.com/en/OpenDTU-Breakoutboard-Your-evaluation-for-your-balcony-solar-system/blink237542
* Breakout board: https://github.com/marove2000/openDTU_BreakoutBoard
![](opendtu_breakoutboard.jpg)
![](thumbnail.jpg)

### Build by @Marc--
* Used build environment: generic
* Case: https://www.thingiverse.com/thing:5435911
Expand Down
Binary file added docs/builds/opendtu_breakoutboard.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/builds/thumbnail.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 27 additions & 17 deletions lib/CMT2300a/cmt_spi3.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
#include <driver/spi_master.h>
#include <esp_rom_gpio.h> // for esp_rom_gpio_connect_out_signal

SemaphoreHandle_t paramLock=NULL;
#define SPI_PARAM_LOCK() do {} while (xSemaphoreTake(paramLock, portMAX_DELAY) != pdPASS)
#define SPI_PARAM_UNLOCK() xSemaphoreGive(paramLock)
SemaphoreHandle_t paramLock = NULL;
#define SPI_PARAM_LOCK() \
do { \
} while (xSemaphoreTake(paramLock, portMAX_DELAY) != pdPASS)
#define SPI_PARAM_UNLOCK() xSemaphoreGive(paramLock)

// for ESP32 this is the so-called HSPI
// for ESP32-S2/S3/C3 this nomenclature does not really exist anymore,
// it is simply the first externally usable hardware SPI master controller
#define SPI_CMT SPI2_HOST

spi_device_handle_t spi_reg, spi_fifo;

Expand All @@ -22,10 +29,12 @@ void cmt_spi3_init(int8_t pin_sdio, int8_t pin_clk, int8_t pin_cs, int8_t pin_fc
.max_transfer_sz = 32,
};
spi_device_interface_config_t devcfg = {
.command_bits = 0,
.address_bits = 0,
.command_bits = 1,
.address_bits = 7,
.dummy_bits = 0,
.mode = 0, // SPI mode 0
.cs_ena_pretrans = 1,
.cs_ena_posttrans = 1,
.clock_speed_hz = spi_speed,
.spics_io_num = pin_cs,
.flags = SPI_DEVICE_HALFDUPLEX | SPI_DEVICE_3WIRE,
Expand All @@ -34,8 +43,8 @@ void cmt_spi3_init(int8_t pin_sdio, int8_t pin_clk, int8_t pin_cs, int8_t pin_fc
.post_cb = NULL,
};

ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &buscfg, 0));
ESP_ERROR_CHECK(spi_bus_add_device(SPI2_HOST, &devcfg, &spi_reg));
ESP_ERROR_CHECK(spi_bus_initialize(SPI_CMT, &buscfg, SPI_DMA_DISABLED));
ESP_ERROR_CHECK(spi_bus_add_device(SPI_CMT, &devcfg, &spi_reg));

// FiFo
spi_device_interface_config_t devcfg2 = {
Expand All @@ -52,19 +61,20 @@ void cmt_spi3_init(int8_t pin_sdio, int8_t pin_clk, int8_t pin_cs, int8_t pin_fc
.pre_cb = NULL,
.post_cb = NULL,
};
ESP_ERROR_CHECK(spi_bus_add_device(SPI2_HOST, &devcfg2, &spi_fifo));
ESP_ERROR_CHECK(spi_bus_add_device(SPI_CMT, &devcfg2, &spi_fifo));

esp_rom_gpio_connect_out_signal(pin_sdio, spi_periph_signal[SPI2_HOST].spid_out, true, false);
esp_rom_gpio_connect_out_signal(pin_sdio, spi_periph_signal[SPI_CMT].spid_out, true, false);
delay(100);
}

void cmt_spi3_write(uint8_t addr, uint8_t dat)
{
uint8_t tx_data[2];
tx_data[0] = ~addr;
tx_data[1] = ~dat;
uint8_t tx_data;
tx_data = ~dat;
spi_transaction_t t = {
.length = 2 * 8,
.cmd = 1,
.addr = ~addr,
.length = 8,
.tx_buffer = &tx_data,
.rx_buffer = NULL
};
Expand All @@ -76,12 +86,13 @@ void cmt_spi3_write(uint8_t addr, uint8_t dat)

uint8_t cmt_spi3_read(uint8_t addr)
{
uint8_t tx_data, rx_data;
tx_data = ~(addr | 0x80); // negation and MSB high (read command)
uint8_t rx_data;
spi_transaction_t t = {
.cmd = 0,
.addr = ~addr,
.length = 8,
.rxlength = 8,
.tx_buffer = &tx_data,
.tx_buffer = NULL,
.rx_buffer = &rx_data
};
SPI_PARAM_LOCK();
Expand All @@ -96,7 +107,6 @@ void cmt_spi3_write_fifo(const uint8_t* buf, uint16_t len)
uint8_t tx_data;

spi_transaction_t t = {
.flags = SPI_TRANS_MODE_OCT,
.length = 8,
.tx_buffer = &tx_data, // reference to write data
.rx_buffer = NULL
Expand Down
4 changes: 3 additions & 1 deletion lib/Hoymiles/src/Hoymiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#include "inverters/HM_4CH.h"
#include <Arduino.h>

#define HOY_SEMAPHORE_TAKE() xSemaphoreTake(_xSemaphore, portMAX_DELAY)
#define HOY_SEMAPHORE_TAKE() \
do { \
} while (xSemaphoreTake(_xSemaphore, portMAX_DELAY) != pdPASS)
#define HOY_SEMAPHORE_GIVE() xSemaphoreGive(_xSemaphore)

HoymilesClass Hoymiles;
Expand Down
39 changes: 39 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,42 @@ build_flags = ${env.build_flags}
-DHOYMILES_PIN_CS=10
-DHOYMILES_PIN_IRQ=4
-DHOYMILES_PIN_CE=5


[env:opendtufusionv1]
board = esp32-s3-devkitc-1
upload_protocol = esp-builtin
debug_tool = esp-builtin
debug_speed = 12000
build_flags = ${env.build_flags}
-DHOYMILES_PIN_MISO=48
-DHOYMILES_PIN_MOSI=35
-DHOYMILES_PIN_SCLK=36
-DHOYMILES_PIN_IRQ=47
-DHOYMILES_PIN_CE=38
-DHOYMILES_PIN_CS=37
-DLED0=17
-DLED1=18
-DARDUINO_USB_MODE=1

[env:opendtufusionv2]
board = esp32-s3-devkitc-1
upload_protocol = esp-builtin
debug_tool = esp-builtin
debug_speed = 12000
build_flags = ${env.build_flags}
-DHOYMILES_PIN_MISO=48
-DHOYMILES_PIN_MOSI=35
-DHOYMILES_PIN_SCLK=36
-DHOYMILES_PIN_IRQ=47
-DHOYMILES_PIN_CE=38
-DHOYMILES_PIN_CS=37
-DLED0=17
-DLED1=18
-DCMT_CLK=6
-DCMT_CS=4
-DCMT_FCS=21
-DCMT_GPIO2=3
-DCMT_GPIO3=8
-DCMT_SDIO=5
-DARDUINO_USB_MODE=1
Loading

0 comments on commit dae4c6f

Please sign in to comment.