ResponseStatusContainer E220LoRaTransmitter::init()
{
transmitter.begin();
auto configurationStatus = this->getConfiguration();
auto configuration = *(Configuration*)configurationStatus.data;
configuration.ADDL = 0x03;
configuration.ADDH = 0x00;
configuration.CHAN = 23;
configuration.SPED.uartBaudRate = UART_BPS_9600;
configuration.SPED.airDataRate = AIR_DATA_RATE_111_625;
configuration.SPED.uartParity = MODE_00_8N1;
configuration.OPTION.subPacketSetting = SPS_200_00;
configuration.OPTION.RSSIAmbientNoise = RSSI_AMBIENT_NOISE_DISABLED;
configuration.OPTION.transmissionPower = POWER_22;
configuration.TRANSMISSION_MODE.enableRSSI = RSSI_ENABLED;
configuration.TRANSMISSION_MODE.fixedTransmission = FT_FIXED_TRANSMISSION;
configuration.TRANSMISSION_MODE.enableLBT = LBT_DISABLED;
configuration.TRANSMISSION_MODE.WORPeriod = WOR_2000_011;
configurationStatus.close();
return this->configure(configuration);
}
ResponseStatusContainer E220LoRaTransmitter::configure(Configuration configuration)
{
this->transmitter.setMode(MODE_3_CONFIGURATION);
auto response = transmitter.setConfiguration(configuration, WRITE_CFG_PWR_DWN_SAVE);
this->transmitter.setMode(MODE_0_NORMAL);
return ResponseStatusContainer(response.code, response.getResponseDescription());
}
---
This is how I configure my LoRa module. However, whenever I try to set:
configuration.SPED.uartBaudRate = UART_BPS_XXXXXXX;
my microcontroller (Arduino Nano ESP32) goes into kernel panic at the moment of setting the configuration. I don't know if I'm doing something wrong—I am using
HardwareSerial
on digital pins 2 and 3, with the module connected in Normal Mode (M0 and M1 on D5 and D6). I use the following constructor:
E220LoRaTransmitter(HardwareSerial &serial, byte auxPin, byte m0Pin, byte m1Pin) : transmitter(&serial, auxPin, m0Pin, m1Pin, UART_BPS_RATE_XXXXXX) {};
(When XXXXXX is set to 9600 the module is correctly configured and works properly; with any other value I get the behavior described above).
The only "weird" thing I noticed is this method in your library:
RESPONSE_STATUS LoRa_E220::checkUARTConfiguration(MODE_TYPE mode)
{
if (mode == MODE_3_PROGRAM && this->bpsRate != UART_BPS_RATE_9600) {
return ERR_E220_WRONG_UART_CONFIG;
}
return E220_SUCCESS;
}
I don't understand why the check on the baud rate should fail with any value other than 9600, but changing that 9600 to any other value causes the module to refuse configuration:
ResponseStatus LoRa_E220::setConfiguration(Configuration configuration, PROGRAM_COMMAND saveType)
{
ResponseStatus rc;
rc.code = checkUARTConfiguration(MODE_3_PROGRAM);
if (rc.code != E220_SUCCESS)
return rc;
MODE_TYPE prevMode = this->mode;
rc.code = this->setMode(MODE_3_PROGRAM);
if (rc.code != E220_SUCCESS)
return rc;
// this->writeProgramCommand(saveType, REG_ADDRESS_CFG);
// configuration.HEAD = saveType;
configuration.COMMAND = saveType;
configuration.STARTING_ADDRESS = REG_ADDRESS_CFG;
configuration.LENGHT = PL_CONFIGURATION;
rc.code = this->sendStruct((uint8_t*)&configuration, sizeof(Configuration));
if (rc.code != E220_SUCCESS) {
this->setMode(prevMode);
return rc;
}
rc.code = this->receiveStruct((uint8_t*)&configuration, sizeof(Configuration));
#ifdef LoRa_E220_DEBUG
this->printParameters((Configuration *)&configuration);
#endif
rc.code = this->setMode(prevMode);
if (rc.code != E220_SUCCESS)
return rc;
if (WRONG_FORMAT == ((Configuration*)&configuration)->COMMAND) {
rc.code = ERR_E220_WRONG_FORMAT;
}
if (RETURNED_COMMAND != ((Configuration*)&configuration)->COMMAND ||
REG_ADDRESS_CFG != ((Configuration*)&configuration)->STARTING_ADDRESS ||
PL_CONFIGURATION != ((Configuration*)&configuration)->LENGHT) {
rc.code = ERR_E220_HEAD_NOT_RECOGNIZED;
}
return rc;
}