Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrupted Data on receive #3

Open
HilalAlHakani1 opened this issue Aug 17, 2019 · 2 comments
Open

Corrupted Data on receive #3

HilalAlHakani1 opened this issue Aug 17, 2019 · 2 comments

Comments

@HilalAlHakani1
Copy link

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

@kubelvla
Copy link

kubelvla commented Aug 18, 2020

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!
    
    ....
    ....

@kubelvla
Copy link

kubelvla commented Aug 18, 2020

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)
    { ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants