Implemented blocking write method in CMT2300 driver and use it in sendEsbPacket.

This commit is contained in:
Thomas Basler 2023-04-09 23:13:58 +02:00
parent 6331210b94
commit 5b648b63ac
3 changed files with 44 additions and 3 deletions

View File

@ -25,6 +25,41 @@ bool CMT2300A::isChipConnected()
return CMT2300A_IsExist();
}
bool CMT2300A::write(const uint8_t* buf, uint8_t len)
{
CMT2300A_GoStby();
CMT2300A_ClearInterruptFlags();
/* Must clear FIFO after enable SPI to read or write the FIFO */
CMT2300A_EnableWriteFifo();
CMT2300A_ClearTxFifo();
CMT2300A_WriteReg(CMT2300A_CUS_PKT15, len); // set Tx length
/* The length need be smaller than 32 */
CMT2300A_WriteFifo(buf, len);
if (!(CMT2300A_ReadReg(CMT2300A_CUS_FIFO_FLAG) & CMT2300A_MASK_TX_FIFO_NMTY_FLG)) {
return false;
}
if (!CMT2300A_GoTx()) {
return false;
}
uint32_t timer = millis();
while (!(CMT2300A_MASK_TX_DONE_FLG & CMT2300A_ReadReg(CMT2300A_CUS_INT_CLR1))) {
if (millis() - timer > 95) {
return false;
}
}
CMT2300A_ClearInterruptFlags();
CMT2300A_GoSleep();
return true;
}
bool CMT2300A::setPALevel(int8_t level)
{
uint16_t Tx_dBm_word;

View File

@ -19,6 +19,8 @@ public:
*/
bool isChipConnected();
bool write(const uint8_t* buf, uint8_t len);
bool setPALevel(int8_t level);
private:

View File

@ -485,11 +485,15 @@ void HoymilesRadio_CMT::sendEsbPacket(CommandAbstract* cmd)
cmd->getCommandName().c_str(), cmtChToFreq(cmtCurrentCh).c_str());
cmd->dumpDataPayload(Hoymiles.getMessageOutput());
// Still here for to handle CMD56 correctly (inverter serial etc.)
memcpy(cmtTxBuffer, cmd->getDataPayload(), cmd->getDataSize());
cmtTxLength = cmd->getDataSize();
_txTimeout.set(100);
cmtNextState = CMT_STATE_TX_START;
if (_radio->write(cmd->getDataPayload(), cmd->getDataSize())) {
_packetSent = false; // still bad hack, to be removed
cmtNextState = CMT_STATE_RX_START;
} else {
Hoymiles.getMessageOutput()->println("TX SPI Timeout");
}
_busyFlag = true;
_rxTimeout.set(cmd->getTimeout());