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

Enquiry on DIO mapping LoRa mode #341

Closed
IoTThinks opened this issue Feb 24, 2020 · 21 comments
Closed

Enquiry on DIO mapping LoRa mode #341

IoTThinks opened this issue Feb 24, 2020 · 21 comments

Comments

@IoTThinks
Copy link
Collaborator

IoTThinks commented Feb 24, 2020

Hi all,
It's not a bug but my enquiry on DIO mapping LoRa mode.

On page 46 of the Semtech data sheet, it says the DIOx Mapping 00, 01, 10 and 11 to DIO0.
What do they mean?

image

In this LoRa library, I don't see we use them.
We only check if the DIO0 is rising and check RegIrgFlags if they are rxDone, txDone...
image

The masking is according to page 111.
image

=> So my question is what does the page 46 mean about DIOx Mapping 00, 01, 10 and 11?
Thanks a lot.

@IoTThinks IoTThinks changed the title Enquirers on DIO mapping LoRa mode Enquiry on DIO mapping LoRa mode Feb 24, 2020
@morganrallen
Copy link
Collaborator

Looks like you're slightly mixing up two things here.
The register for DIOx Mapping is to set what the DIO pins are doing. For the example of DIO0, setting REG_DIO_MAPPING_1 to 00 will cause DIO0 to be raised when data is receive. Likewise setting it to 01 to cause DIO0 to be raise then TX is done.

The second table you've shown is what you check to see what interrupt has occurred. Sometimes this doesn't matter, because you should know what start you're in, like for RX but in the case of CAD, multiple interrupt flags can be set at the same time.

In this LoRa library, I don't see we use them.

https://github.com/sandeepmistry/arduino-LoRa/blob/master/src/LoRa.cpp#L183
and
https://github.com/sandeepmistry/arduino-LoRa/blob/master/src/LoRa.cpp#L391

These setup the reason DIO0 will be raised. Hopefully this helps you understand what's going on.

@IoTThinks
Copy link
Collaborator Author

Thanks for your reply.
Let me digest your answer this afternoon :)

@morganrallen
Copy link
Collaborator

Hopefully I didn't overly complicated it.

Simply put,

  • REG_DIO_MAPPING_1 sets what the DIO pins do, according to page table 18
  • REG_IRQ_FLAGS hold the state of what happened after one of the DIO pins is raised.

@IoTThinks
Copy link
Collaborator Author

Now I understand.
From what I see in https://github.com/sandeepmistry/arduino-LoRa/blob/master/src/LoRa.cpp#L391
We need to proactive set the chip status when we are done with RX and TX at user code level (aka this library).

I always have a thinking that Semtech should do that for us?

Hopefully I didn't overly complicated it.

Simply put,

  • REG_DIO_MAPPING_1 sets what the DIO pins do, according to page table 18
  • REG_IRQ_FLAGS hold the state of what happened after one of the DIO pins is raised.

@morganrallen
Copy link
Collaborator

Not quite. It's not setting the chip status, but telling the chip to alert us (via DIO0) when one of those things is complete.

@IoTThinks
Copy link
Collaborator Author

IoTThinks commented Feb 24, 2020

Not quite. It's not setting the chip status, but telling the chip to alert us (via DIO0) when one of those things is complete.

  1. By default, the chip should alert us via DIO0 (and DIO1-5) when those things are completed even if we do not tell them to do so, right?
    As it is already written in the specs.

  2. I feel that Semtech needs the user code level to tell them when we already finish receiving the data. It makes sense to me.
    But why we need to tell Semtech when the TX is completed. Semtech chip should know better than user code.
    => That lead me to confusion.

@morganrallen
Copy link
Collaborator

  1. The default is 00, so yes, it will default to those in the first row.

  2. I think you still misunderstanding, by setting the DIO_MAPPING reg you are not telling it TX is complete, you telling it to tell you when it is complete. Look again at https://github.com/sandeepmistry/arduino-LoRa/blob/master/src/LoRa.cpp#L183, we change the DIO_MAPPING before we set the radio to TX mode.

@IoTThinks
Copy link
Collaborator Author

Ok, well-understood now.
Thanks a lot for your effort. 👯‍♂️

@artemen
Copy link

artemen commented Feb 24, 2020

I think it would be useful to add at least one more DIO interrupt callback for DIO2, but this would need some way to keep track of which DIO mapping bits are set.

@IoTThinks
Copy link
Collaborator Author

IoTThinks commented Feb 24, 2020

I think it would be useful to add at least one more DIO interrupt callback for DIO2, but this would need some way to keep track of which DIO mapping bits are set.

Why you want callback to DIO2? I don't seem to know or need to use FhssChangeChannel btw.
Most of the China made LoRa board doesnt seem to connect to DIO2.

I think I may need CadDetected in DIO1 but my board also doesn't connect to DIO1 yet. :/

@artemen
Copy link

artemen commented Feb 24, 2020 via email

@morganrallen
Copy link
Collaborator

I think it would be useful to add at least one more DIO interrupt callback for DIO2, but this would need some way to keep track of which DIO mapping bits are set.

You don't really need to track the DIO mapping state, REG_IRQ_FLAG will have the current state of what has happened since the last time it was cleared, so you can just figure it out from there.

I think I may need CadDetected in DIO1 but my board also doesn't connect to DIO1 yet. :/

Fun fact! CADDetect can be performed with just DIO0.
From datasheet page 44

Once the calculation is finished the modem generates the CadDone interrupt. If the correlation was successful, CadDetected is generated simultaneously.

What this means is, CadDone get triggered on DIO0 you can also check the IRQ flag if CadDetect was raised. This can be seen in PR #334

_onCadDone((irqFlags & IRQ_CAD_DETECTED_MASK) != 0);

@artemen
Copy link

artemen commented Feb 24, 2020 via email

@morganrallen
Copy link
Collaborator

This is correct. When you set the radio to CAD mode, DIO0 is set to be raised on CadDone it's up to the user to determine what state to go into next. Typically after calling CAD you'd want to send if the channel is free or receive if you're expecting something. Else you'd probably just go back into CAD mode.

@artemen
Copy link

artemen commented Feb 24, 2020 via email

@Erik84750
Copy link

You don't really need to track the DIO mapping state, REG_IRQ_FLAG will have the current state of what has happened since the last time it was cleared, so you can just figure it out from there.

Continuing on IoTThinks discussion regarding the use of DIO0 to detect an incoming packet (when using onReceive): where in LoRa.cpp does this RegIrqFlags(0x12) bit 6 gets cleared (ie. "writing a 1 clears the IRQ")?

@IoTThinks
Copy link
Collaborator Author

IoTThinks commented Apr 11, 2021

@Erik84750 Then you need to poll the regIrqFlag for events.

@Erik84750
Copy link

@Erik84750 Then you need to poll the regIrqFlag for events.

Strange because the DIO0 does get reset after 50usec; so I am wondering where in the LoRa.cpp this is accomplished?

@IoTThinks
Copy link
Collaborator Author

IoTThinks commented Apr 11, 2021

No idea.
(1) After the RXDone, the library will set the chip to listen again.

I wonder if the chip itself automatically resets the DIO0 back to LOW state or due to (1).

@morganrallen
Copy link
Collaborator

Yes, writing the flags back clears them.
https://github.com/sandeepmistry/arduino-LoRa/blob/master/src/LoRa.cpp#L696-L697

@EMendesS
Copy link

Is there anything missed when not connecting any of the DIOx pins to my microcontroller? I meant, in my project I have no pins available to connect to DIOx, which I'm leaving all six unconnected. Despite my software will suffer, am I missing something by not connecting them all, like lorawan stuff or any possible feature not accessible through SPI?

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

5 participants