Create separate definition for the 860MHz band of the CMT2300A

This is required to support different countries in the future. The defines where moved to function to change the values dynamically
This commit is contained in:
Thomas Basler 2024-01-13 14:33:55 +01:00
parent abc53f4257
commit 58f0121c11
7 changed files with 50 additions and 49 deletions

View File

@ -85,14 +85,16 @@
; RSSI Offset = 0 ; RSSI Offset = 0
; RSSI Offset Sign = 0 ; RSSI Offset Sign = 0
*/ */
#ifndef __CMT2300A_PARAMS_H #ifndef __CMT2300A_PARAMS_860_H
#define __CMT2300A_PARAMS_H #define __CMT2300A_PARAMS_860_H
#include "cmt2300a_defs.h" #include "cmt2300a_defs.h"
#include <stdint.h> #include <stdint.h>
#define CMT_BASE_FREQ_860 860000000
/* [CMT Bank] with RSSI offset of +- 0 (and Tx power double bit not set) */ /* [CMT Bank] with RSSI offset of +- 0 (and Tx power double bit not set) */
static uint8_t g_cmt2300aCmtBank[CMT2300A_CMT_BANK_SIZE] = { static uint8_t g_cmt2300aCmtBank_860[CMT2300A_CMT_BANK_SIZE] = {
0x00, 0x00,
0x66, 0x66,
0xEC, 0xEC,
@ -108,7 +110,7 @@ static uint8_t g_cmt2300aCmtBank[CMT2300A_CMT_BANK_SIZE] = {
}; };
/* [System Bank] */ /* [System Bank] */
static uint8_t g_cmt2300aSystemBank[CMT2300A_SYSTEM_BANK_SIZE] = { static uint8_t g_cmt2300aSystemBank_860[CMT2300A_SYSTEM_BANK_SIZE] = {
0xAE, 0xAE,
0xE0, 0xE0,
0x35, 0x35,
@ -124,7 +126,7 @@ static uint8_t g_cmt2300aSystemBank[CMT2300A_SYSTEM_BANK_SIZE] = {
}; };
/* [Frequency Bank] 860 MHz */ /* [Frequency Bank] 860 MHz */
static uint8_t g_cmt2300aFrequencyBank[CMT2300A_FREQUENCY_BANK_SIZE] = { static uint8_t g_cmt2300aFrequencyBank_860[CMT2300A_FREQUENCY_BANK_SIZE] = {
0x42, 0x42,
0x32, 0x32,
0xCF, 0xCF,
@ -136,7 +138,7 @@ static uint8_t g_cmt2300aFrequencyBank[CMT2300A_FREQUENCY_BANK_SIZE] = {
}; };
/* [Data Rate Bank] */ /* [Data Rate Bank] */
static uint8_t g_cmt2300aDataRateBank[CMT2300A_DATA_RATE_BANK_SIZE] = { static uint8_t g_cmt2300aDataRateBank_860[CMT2300A_DATA_RATE_BANK_SIZE] = {
0xA6, 0xA6,
0xC9, 0xC9,
0x20, 0x20,
@ -164,7 +166,7 @@ static uint8_t g_cmt2300aDataRateBank[CMT2300A_DATA_RATE_BANK_SIZE] = {
}; };
/* [Baseband Bank] - EU */ /* [Baseband Bank] - EU */
static uint8_t g_cmt2300aBasebandBank[CMT2300A_BASEBAND_BANK_SIZE] = { static uint8_t g_cmt2300aBasebandBank_860[CMT2300A_BASEBAND_BANK_SIZE] = {
0x12, 0x12,
0x1E, 0x1E,
0x00, 0x00,
@ -197,7 +199,7 @@ static uint8_t g_cmt2300aBasebandBank[CMT2300A_BASEBAND_BANK_SIZE] = {
}; };
/* [Tx Bank] 13 dBm */ /* [Tx Bank] 13 dBm */
static uint8_t g_cmt2300aTxBank[CMT2300A_TX_BANK_SIZE] = { static uint8_t g_cmt2300aTxBank_860[CMT2300A_TX_BANK_SIZE] = {
0x70, 0x70,
0x4D, 0x4D,
0x06, 0x06,

View File

@ -1,10 +1,10 @@
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
/* /*
* Copyright (C) 2023 Thomas Basler and others * Copyright (C) 2023-2024 Thomas Basler and others
*/ */
#include "cmt2300wrapper.h" #include "cmt2300wrapper.h"
#include "cmt2300a.h" #include "cmt2300a.h"
#include "cmt2300a_params.h" #include "cmt2300a_params_860.h"
CMT2300A::CMT2300A(uint8_t pin_sdio, uint8_t pin_clk, uint8_t pin_cs, uint8_t pin_fcs, uint32_t spi_speed) CMT2300A::CMT2300A(uint8_t pin_sdio, uint8_t pin_clk, uint8_t pin_cs, uint8_t pin_fcs, uint32_t spi_speed)
{ {
@ -242,6 +242,11 @@ bool CMT2300A::rxFifoAvailable()
) & CMT2300A_ReadReg(CMT2300A_CUS_INT_FLAG); ) & CMT2300A_ReadReg(CMT2300A_CUS_INT_FLAG);
} }
uint32_t CMT2300A::getBaseFrequency()
{
return CMT_BASE_FREQ_860; // from Frequency Bank in cmt2300a_params.h
}
void CMT2300A::flush_rx(void) void CMT2300A::flush_rx(void)
{ {
CMT2300A_ClearRxFifo(); CMT2300A_ClearRxFifo();
@ -261,12 +266,12 @@ bool CMT2300A::_init_radio()
} }
/* config registers */ /* config registers */
CMT2300A_ConfigRegBank(CMT2300A_CMT_BANK_ADDR, g_cmt2300aCmtBank, CMT2300A_CMT_BANK_SIZE); CMT2300A_ConfigRegBank(CMT2300A_CMT_BANK_ADDR, g_cmt2300aCmtBank_860, CMT2300A_CMT_BANK_SIZE);
CMT2300A_ConfigRegBank(CMT2300A_SYSTEM_BANK_ADDR, g_cmt2300aSystemBank, CMT2300A_SYSTEM_BANK_SIZE); CMT2300A_ConfigRegBank(CMT2300A_SYSTEM_BANK_ADDR, g_cmt2300aSystemBank_860, CMT2300A_SYSTEM_BANK_SIZE);
CMT2300A_ConfigRegBank(CMT2300A_FREQUENCY_BANK_ADDR, g_cmt2300aFrequencyBank, CMT2300A_FREQUENCY_BANK_SIZE); CMT2300A_ConfigRegBank(CMT2300A_FREQUENCY_BANK_ADDR, g_cmt2300aFrequencyBank_860, CMT2300A_FREQUENCY_BANK_SIZE);
CMT2300A_ConfigRegBank(CMT2300A_DATA_RATE_BANK_ADDR, g_cmt2300aDataRateBank, CMT2300A_DATA_RATE_BANK_SIZE); CMT2300A_ConfigRegBank(CMT2300A_DATA_RATE_BANK_ADDR, g_cmt2300aDataRateBank_860, CMT2300A_DATA_RATE_BANK_SIZE);
CMT2300A_ConfigRegBank(CMT2300A_BASEBAND_BANK_ADDR, g_cmt2300aBasebandBank, CMT2300A_BASEBAND_BANK_SIZE); CMT2300A_ConfigRegBank(CMT2300A_BASEBAND_BANK_ADDR, g_cmt2300aBasebandBank_860, CMT2300A_BASEBAND_BANK_SIZE);
CMT2300A_ConfigRegBank(CMT2300A_TX_BANK_ADDR, g_cmt2300aTxBank, CMT2300A_TX_BANK_SIZE); CMT2300A_ConfigRegBank(CMT2300A_TX_BANK_ADDR, g_cmt2300aTxBank_860, CMT2300A_TX_BANK_SIZE);
// xosc_aac_code[2:0] = 2 // xosc_aac_code[2:0] = 2
uint8_t tmp; uint8_t tmp;

View File

@ -4,7 +4,6 @@
#include <stdint.h> #include <stdint.h>
#define CMT2300A_ONE_STEP_SIZE 2500 // frequency channel step size for fast frequency hopping operation: One step size is 2.5 kHz. #define CMT2300A_ONE_STEP_SIZE 2500 // frequency channel step size for fast frequency hopping operation: One step size is 2.5 kHz.
#define CMT_BASE_FREQ 860000000 // from Frequency Bank in cmt2300a_params.h
#define FH_OFFSET 100 // value * CMT2300A_ONE_STEP_SIZE = channel frequency offset #define FH_OFFSET 100 // value * CMT2300A_ONE_STEP_SIZE = channel frequency offset
#define CMT_SPI_SPEED 4000000 // 4 MHz #define CMT_SPI_SPEED 4000000 // 4 MHz
@ -86,6 +85,8 @@ public:
bool rxFifoAvailable(); bool rxFifoAvailable();
uint32_t getBaseFrequency();
/** /**
* Empty the RX (receive) FIFO buffers. * Empty the RX (receive) FIFO buffers.
*/ */
@ -109,4 +110,4 @@ private:
int8_t _pin_cs; int8_t _pin_cs;
int8_t _pin_fcs; int8_t _pin_fcs;
uint32_t _spi_speed; uint32_t _spi_speed;
}; };

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
/* /*
* Copyright (C) 2024 Thomas Basler and others * Copyright (C) 2023-2024 Thomas Basler and others
*/ */
#include "HoymilesRadio_CMT.h" #include "HoymilesRadio_CMT.h"
#include "Hoymiles.h" #include "Hoymiles.h"
@ -8,37 +8,28 @@
#include <FunctionalInterrupt.h> #include <FunctionalInterrupt.h>
#define HOY_BOOT_FREQ 868000000 // Hoymiles boot/init frequency after power up inverter or connection lost for 15 min #define HOY_BOOT_FREQ 868000000 // Hoymiles boot/init frequency after power up inverter or connection lost for 15 min
#define HOY_BASE_FREQ 860000000
// offset from initalized CMT base frequency to Hoy base frequency in channels
#define CMT_BASE_CH_OFFSET ((CMT_BASE_FREQ - HOY_BASE_FREQ) / CMT2300A_ONE_STEP_SIZE / FH_OFFSET)
// frequency can not be lower than actual initailized base freq + 250000 uint32_t HoymilesRadio_CMT::getFrequencyFromChannel(const uint8_t channel) const
#define MIN_FREQ ((HOY_BASE_FREQ + (CMT_BASE_CH_OFFSET > 1 ? CMT_BASE_CH_OFFSET : 1) * CMT2300A_ONE_STEP_SIZE * FH_OFFSET))
// =923500, 0xFF does not work
#define MAX_FREQ ((HOY_BASE_FREQ + 0xFE * CMT2300A_ONE_STEP_SIZE * FH_OFFSET))
uint32_t HoymilesRadio_CMT::getFrequencyFromChannel(const uint8_t channel)
{ {
return (CMT_BASE_FREQ + (CMT_BASE_CH_OFFSET + channel) * FH_OFFSET * CMT2300A_ONE_STEP_SIZE); return (_radio->getBaseFrequency() + channel * getChannelWidth());
} }
uint8_t HoymilesRadio_CMT::getChannelFromFrequency(const uint32_t frequency) uint8_t HoymilesRadio_CMT::getChannelFromFrequency(const uint32_t frequency) const
{ {
if ((frequency % 250000) != 0) { if ((frequency % getChannelWidth()) != 0) {
Hoymiles.getMessageOutput()->printf("%.3f MHz is not divisible by 250 kHz!\r\n", frequency / 1000000.0); Hoymiles.getMessageOutput()->printf("%.3f MHz is not divisible by %d kHz!\r\n", frequency / 1000000.0, getChannelWidth());
return 0xFF; // ERROR return 0xFF; // ERROR
} }
if (frequency < MIN_FREQ || frequency > MAX_FREQ) { if (frequency < getMinFrequency() || frequency > getMaxFrequency()) {
Hoymiles.getMessageOutput()->printf("%.2f MHz is out of Hoymiles/CMT range! (%.2f MHz - %.2f MHz)\r\n", Hoymiles.getMessageOutput()->printf("%.2f MHz is out of Hoymiles/CMT range! (%.2f MHz - %.2f MHz)\r\n",
frequency / 1000000.0, MIN_FREQ / 1000000.0, MAX_FREQ / 1000000.0); frequency / 1000000.0, getMinFrequency() / 1000000.0, getMaxFrequency() / 1000000.0);
return 0xFF; // ERROR return 0xFF; // ERROR
} }
if (frequency < 863000000 || frequency > 870000000) { if (frequency < 863000000 || frequency > 870000000) {
Hoymiles.getMessageOutput()->printf("!!! caution: %.2f MHz is out of EU legal range! (863 - 870 MHz)\r\n", Hoymiles.getMessageOutput()->printf("!!! caution: %.2f MHz is out of EU legal range! (863 - 870 MHz)\r\n",
frequency / 1000000.0); frequency / 1000000.0);
} }
return (frequency - CMT_BASE_FREQ) / CMT2300A_ONE_STEP_SIZE / FH_OFFSET - CMT_BASE_CH_OFFSET; // frequency to channel return (frequency - _radio->getBaseFrequency()) / getChannelWidth(); // frequency to channel
} }
bool HoymilesRadio_CMT::cmtSwitchDtuFreq(const uint32_t to_frequency) bool HoymilesRadio_CMT::cmtSwitchDtuFreq(const uint32_t to_frequency)
@ -191,14 +182,16 @@ bool HoymilesRadio_CMT::isConnected() const
return _radio->isChipConnected(); return _radio->isChipConnected();
} }
uint32_t HoymilesRadio_CMT::getMinFrequency() uint32_t HoymilesRadio_CMT::getMinFrequency() const
{ {
return MIN_FREQ; // frequency can not be lower than actual initailized base freq + 250000
return _radio->getBaseFrequency() + getChannelWidth();
} }
uint32_t HoymilesRadio_CMT::getMaxFrequency() uint32_t HoymilesRadio_CMT::getMaxFrequency() const
{ {
return MAX_FREQ; // =923500, 0xFF does not work
return _radio->getBaseFrequency() + 0xFE * getChannelWidth();
} }
uint32_t HoymilesRadio_CMT::getChannelWidth() uint32_t HoymilesRadio_CMT::getChannelWidth()

View File

@ -26,12 +26,12 @@ public:
bool isConnected() const; bool isConnected() const;
static uint32_t getMinFrequency(); uint32_t getMinFrequency() const;
static uint32_t getMaxFrequency(); uint32_t getMaxFrequency() const;
static uint32_t getChannelWidth(); static uint32_t getChannelWidth();
static uint32_t getFrequencyFromChannel(const uint8_t channel); uint32_t getFrequencyFromChannel(const uint8_t channel) const;
static uint8_t getChannelFromFrequency(const uint32_t frequency); uint8_t getChannelFromFrequency(const uint32_t frequency) const;
private: private:
void ARDUINO_ISR_ATTR handleInt1(); void ARDUINO_ISR_ATTR handleInt1();

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
/* /*
* Copyright (C) 2023 Thomas Basler and others * Copyright (C) 2023-2024 Thomas Basler and others
*/ */
#include "HMS_Abstract.h" #include "HMS_Abstract.h"
#include "Hoymiles.h" #include "Hoymiles.h"
@ -19,7 +19,7 @@ bool HMS_Abstract::sendChangeChannelRequest()
} }
auto cmdChannel = _radio->prepareCommand<ChannelChangeCommand>(); auto cmdChannel = _radio->prepareCommand<ChannelChangeCommand>();
cmdChannel->setChannel(HoymilesRadio_CMT::getChannelFromFrequency(Hoymiles.getRadioCmt()->getInverterTargetFrequency())); cmdChannel->setChannel(Hoymiles.getRadioCmt()->getChannelFromFrequency(Hoymiles.getRadioCmt()->getInverterTargetFrequency()));
cmdChannel->setTargetAddress(serial()); cmdChannel->setTargetAddress(serial());
_radio->enqueCommand(cmdChannel); _radio->enqueCommand(cmdChannel);

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
/* /*
* Copyright (C) 2023 Thomas Basler and others * Copyright (C) 2023-2024 Thomas Basler and others
*/ */
#include "HMT_Abstract.h" #include "HMT_Abstract.h"
#include "Hoymiles.h" #include "Hoymiles.h"
@ -21,9 +21,9 @@ bool HMT_Abstract::sendChangeChannelRequest()
} }
auto cmdChannel = _radio->prepareCommand<ChannelChangeCommand>(); auto cmdChannel = _radio->prepareCommand<ChannelChangeCommand>();
cmdChannel->setChannel(HoymilesRadio_CMT::getChannelFromFrequency(Hoymiles.getRadioCmt()->getInverterTargetFrequency())); cmdChannel->setChannel(Hoymiles.getRadioCmt()->getChannelFromFrequency(Hoymiles.getRadioCmt()->getInverterTargetFrequency()));
cmdChannel->setTargetAddress(serial()); cmdChannel->setTargetAddress(serial());
_radio->enqueCommand(cmdChannel); _radio->enqueCommand(cmdChannel);
return true; return true;
}; };