C/C++ Question Pin interrup issue in LoRa library only in B4R project

candide

Active Member
Licensed User
in March, i was working on a wrapper for LoRa library, but from tests done by ehsan gilassi, both call-back were not working.

last week i received 2 SX1278, Ra-01 M modules, i was able to make tests and i was able to reproduce this issue.
- call-back OnReceive/OnRxDone is OK under arduino (project example with library)
- call-back OnReceive/OnRxDone is NOK under B4R. (same project converted in B4R)

from tests, call-back process is working => issue is before
with traces added in library, i found an issue at interruption on Dio0 pin, after Dio0 interrupt, behavior was different in arduino project and in B4R project
=======================
code at Dio0 interrupt:
=======================
B4X:
ISR_PREFIX void LoRaClass::onDio0Rise()
{
   LoRa.handleDio0Rise();
}
void LoRaClass::handleDio0Rise()
{
   int irqFlags = readRegister(REG_IRQ_FLAGS);
   Serial.print("irqFlags=");Serial.println(irqFlags); //debug******************
//=> irqFlags should be "80" but with B4R it is "00"
  // clear IRQ's
  writeRegister(REG_IRQ_FLAGS, irqFlags);

  if ((irqFlags & IRQ_PAYLOAD_CRC_ERROR_MASK) == 0) {
    if ((irqFlags & IRQ_RX_DONE_MASK) != 0) {
//=> du to irqflags=00, never we come in this part, never we received a packet
       Serial.println("receive packet");//debug*********************************
      _packetIndex = 0;

      // read packet length
      int packetLength = _implicitHeaderMode ? readRegister(REG_PAYLOAD_LENGTH) : readRegister(REG_RX_NB_BYTES);

      // set FIFO address to current RX address
      writeRegister(REG_FIFO_ADDR_PTR, readRegister(REG_FIFO_RX_CURRENT_ADDR));

      if (_onReceive) {
        _onReceive(packetLength);
      }
    }
    else if ((irqFlags & IRQ_TX_DONE_MASK) != 0) {
      if (_onTxDone) {
        _onTxDone();
      }
    }
  }
}
after several tests done, interruption routine don't have access to variables in the library... No crash, but value are seen = 00

i did a change in code to check what is wrong: i run handleDio0Rise from a loop in B4R project, not from interruption, and interruption is doing nothing
===================
code after modification is this one:
====================
B4X:
//added for B4R
void LoRaClass::processing()  {
   if (digitalRead(_dio0)== HIGH) {handleDio0Rise(); }  //test of pin dio0 used for interruption
   }  
ISR_PREFIX void LoRaClass::onDio0Rise()
{
  //LoRa.handleDio0Rise();
}
void LoRaClass::handleDio0Rise()
{
  int irqFlags = readRegister(REG_IRQ_FLAGS);

  // clear IRQ's
  writeRegister(REG_IRQ_FLAGS, irqFlags);

  if ((irqFlags & IRQ_PAYLOAD_CRC_ERROR_MASK) == 0) {

    if ((irqFlags & IRQ_RX_DONE_MASK) != 0) {
      // received a packet
      _packetIndex = 0;

      // read packet length
      int packetLength = _implicitHeaderMode ? readRegister(REG_PAYLOAD_LENGTH) : readRegister(REG_RX_NB_BYTES);

      // set FIFO address to current RX address
      writeRegister(REG_FIFO_ADDR_PTR, readRegister(REG_FIFO_RX_CURRENT_ADDR));

      if (_onReceive) {
        _onReceive(packetLength);
      }
    }
    else if ((irqFlags & IRQ_TX_DONE_MASK) != 0) {
      if (_onTxDone) {
        _onTxDone();
      }
    }
  }
}
in this configuration interruption is doing nothing, a check of dio0 pin is done from a loop in B4R and if level HIGHT => run of handleDio0Rise.
=> with this modification call-backs are working.
tests were done on esp32 and esp8266, and issue is the same: library is working with arduino, library is not working with B4R due to issue on pin interrupt

=> why interruption on pin working in arduino project is not working in B4R project ? i didn't find explanation...

if someone have an idea, he will be welcome
 

Attachments

  • rLoRa.zip
    11.6 KB · Views: 164

candide

Active Member
Licensed User
in fact, data are missing at SPI interface :
|code]
uint8_t LoRaClass::singleTransfer(uint8_t address, uint8_t value)
{
uint8_t response;

digitalWrite(_ss, LOW);
_spi->beginTransaction(_spiSettings);
_spi->transfer(address);
response = _spi->transfer(value);
_spi->endTransaction();
Serial.print("response SPI :");Serial.println(response) ; // always "00" when interruption at origin of request
digitalWrite(_ss, HIGH);

return response;
}
[/code]

=> when request to SPI library is coming from interruption , i have an answer "NULL"
=> when request to SPI library is not coming from an interruption, i have correct answer.

if someone have an explanation, he will be welcome
 

Similar Threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…