rpi-lora-tranceiver
rpi-lora-tranceiver copied to clipboard
Corrupted Data on receive
the transmission is working perfectly but i'm having issues on receiving packets i'm sending123456 either i receive them corrupted or i receive them scrambled like 142356 but sometimes and rarely i receive them correctly
There are two issues, once is addressed in the pull request, the setting of the modem is done too soon, before switching the modem to the LoRa mode. So in the SetupLoRa() function, they setup all the things, but they have no effect. The solution of this part is to set the LoRA mode early, before setting all the settings:
void SetupLoRa()
{
digitalWrite(RST, HIGH);
delay(100);
digitalWrite(RST, LOW);
delay(100);
byte version = readReg(REG_VERSION);
if (version == 0x22) {
// sx1272
printf("SX1272 detected, starting.\n");
sx1272 = true;
} else {
// sx1276?
digitalWrite(RST, LOW);
delay(100);
digitalWrite(RST, HIGH);
delay(100);
version = readReg(REG_VERSION);
if (version == 0x12) {
// sx1276
printf("SX1276 detected, starting.\n");
sx1272 = false;
} else {
printf("Unrecognized transceiver.\n");
//printf("Version: 0x%x\n",version);
exit(1);
}
}
opmode(OPMODE_SLEEP);
opmodeLora(); // <- THIS DOES THE TRICK, but remove the call from the main function later!
....
....
The second trick to get the CRC check failure detected, is to fix their packet reading function. I'll create another issue describing the problem, but it seems that they try to reset the flag saying that the Rx has been done, but the effect is that they clean all the IRQ flags, including the one for CRC check fail. To fix this issue, you have to change the order of calls in the beginning of this function:
boolean receive(char *payload) {
byte irqflags = readReg(REG_IRQ_FLAGS);
// clear rxDone
writeReg(REG_IRQ_FLAGS, 0x40); // THIS CALL CLEANS ALL FLAGS, WTF
// payload crc: 0x20
if((irqflags & 0x20) == 0x20)
{ ...