RAK13102 Blues interrupt ATTNP

To setup the MCU 4631 to receive and interrupt from the Blues.IO modem, on ATTNP (WB_IO5), I have configured the Blues module with {"req": "card.attn", "mode": "arm,signal"}, and have setup the MCU’s interrupt handling on WB_IO5 for rising signals. I can’t get a reliable trigger. The interrupt handler appears to always be triggered.
What is wrong with this interrupt setup?

#include <Arduino.h>
#include <SPI.h>
#ifdef NRF52_SERIES
#include <Adafruit_TinyUSB.h>
#endif
#include <blues-minimal-i2c.h>

#define ATTN_INPUT_PIN WB_IO5 

// Set to true whenever ATTN interrupt occurs
static bool attnInterruptOccurred;

//#include <SX126x-Arduino.h>

// Forward declarations
bool blues_hub_connected(void);
void blues_hub_status(void);
void startattnArm(void);
void resetattnArm(void);
void attnISR(void);
void attnArm();

// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

bool blues_connected = false;

char blues_response[2048];
long t;
/**
 * @brief Arduino setup function
 *
 */
void setup(void)
{
	Serial.begin(115200);
	time_t serial_timeout = millis();
	// On nRF52840 the USB serial is not available immediately
	while (!Serial)
	{
		if ((millis() - serial_timeout) < 5000)
		{
			delay(100);
			digitalWrite(LED_GREEN, !digitalRead(LED_GREEN));
		}
		else
		{
			break;
		}
	}

	// Initialize LoRa transceiver and send to sleep
#ifdef NRF52_SERIES
	//lora_rak4630_init();
#endif
#ifdef ESP32
	//lora_rak13300_init();
#endif
	//Radio.Sleep();

	// Initialize Blues Notecard interface
	Wire.begin();
	Wire.setClock(100000);
  // Attach an interrupt pin
   attnInterruptOccurred = false;
  pinMode(ATTN_INPUT_PIN, INPUT);
  attachInterrupt(digitalPinToInterrupt(ATTN_INPUT_PIN), attnISR, RISING);
  startattnArm();
  t = millis();
}

/**
 * @brief Arduino loop function
 *
 */
void loop()
{
  	Serial.println("=============================");
  	// Check if Blues Notecard has cellular connection
  	blues_connected = blues_hub_connected();
  	if (blues_connected)
  	{
  		Serial.println("NoteCard reports it has cellular connection");
  	}
  	else
  	{
  		Serial.println("NoteCard reports it has no cellular connection");
  	}
    if (millis() - t > 60000) 
    {
      
      	Serial.println("==========");
      	// Prepare a simple data packet
       
      	if (rak_blues.start_req((char *)"note.add"))
      	{
      		// Create data file
      		rak_blues.add_string_entry((char *)"file", (char *)"data.qo");
      		// Force sync
      		rak_blues.add_bool_entry((char *)"sync", true);
      		// Add some float values
      		rak_blues.add_nested_float_entry((char *)"body", (char *)"temp", 36.76);
      		rak_blues.add_nested_float_entry((char *)"body", (char *)"humid", 67);
      		rak_blues.add_nested_float_entry((char *)"body", (char *)"baro", 1024);
      
      		// Add connction status
      		if (blues_connected)
      		{
      			rak_blues.add_nested_string_entry((char *)"body", (char *)"status", (char *)"connected");
      		}
      		else
      		{
      			rak_blues.add_nested_string_entry((char *)"body", (char *)"status", (char *)"not connected");
      		}
      
      		Serial.println("Payload created");
      		if (!rak_blues.send_req())
      		{
      			Serial.println("Send request failed : 'note.add'");
      		}
      		else
      		{
      			Serial.println("Request sent to NoteCard");
      		}
      	}
      	else
      	{
      		Serial.println("Error creating the 'note.add' request");
      	}
       t = millis();
    }

      // check interrupt flag
    if (attnInterruptOccurred)
    {
      /**
      J *req = NoteNewRequest("hub.signal");
      NoteRequest(req);
      if (req != NULL) {
        J *body = JGetObject(req, "body");
        if (body != NULL) {
          J *control = JGetObject(body, "control");
          
          if (control != NULL) {
            Serial.println(JGetString(control, "value"));           
          }
        }
      }
      **/
      attnInterruptOccurred = false;
      if (rak_blues.start_req((char *)"hub.signal"))
      {
  
    
        Serial.println("Payload created");
        if (rak_blues.send_req(blues_response, 2048))
        {
          Serial.println("Got signal response");
          Serial.printf("%s\n", blues_response);
        }
        else
        {
          Serial.println("Error signal request from NoteCard");
        }
      }
      pinMode(ATTN_INPUT_PIN, INPUT);
      attachInterrupt(digitalPinToInterrupt(ATTN_INPUT_PIN), attnISR, RISING);
      //resetattnArm();
      startattnArm();
      
      
    }
    
  

	Serial.println("======================================================");

	// Get NoteCard status
	blues_hub_status();

	//delay(1000);
	//Serial.println("\n");
}

/**
 * @brief Check connection to cellular network
 *
 * @verbose
 *
 * @return true if connection is/was established
 * @return false if no connection
 */
bool blues_hub_connected(void)
{
	bool request_success = false;
	bool cellular_connected = false;
	for (int try_send = 0; try_send < 5; try_send++)
	{
		// Prepare "card.wireless" request
		if (rak_blues.start_req((char *)"card.wireless"))
		{
			// Send request
			if (rak_blues.send_req())
			{
				// Check if the response has an entry "net"
				if (rak_blues.has_entry((char *)"net"))
				{
					// Check if the response has an entry "band"
					if (rak_blues.has_nested_entry((char *)"net", (char *)"band"))
					{
						// If "band" is available, the NoteCard should have cellular connection
						cellular_connected = true;
					}
					request_success = true;
					break;
				}
			}
		}
	}
	if (!request_success)
	{
		Serial.println("'card.wireless' request failed");
		return false;
	}
	return cellular_connected;
}

/**
 * @brief Request NoteHub status, only for debug purposes
 *
 */
void blues_hub_status(void)
{
	bool request_success = false;
	for (int try_send = 0; try_send < 3; try_send++)
	{
		rak_blues.start_req((char *)"hub.status");
		if (rak_blues.send_req(blues_response, 2048))
		{
			Serial.println("Notecard Hub status:");
			Serial.printf("%s\n", blues_response);
			request_success = true;
			break;
		}
	}
	if (!request_success)
	{
		Serial.println("'hub.status' request failed");
	}
	Serial.println("======================================================");

	request_success = false;
	for (int try_send = 0; try_send < 3; try_send++)
	{
		rak_blues.start_req((char *)"hub.get");
		if (rak_blues.send_req(blues_response, 2048))
		{
			Serial.println("Notecard Hub setup:");
			Serial.printf("%s\n", blues_response);
			request_success = true;
			break;
		}
	}
	if (!request_success)
	{
		Serial.println("'hub.get' request failed");
	}
	Serial.println("======================================================");

	request_success = false;
	for (int try_send = 0; try_send < 3; try_send++)
	{
		rak_blues.start_req((char *)"card.wireless");
		if (rak_blues.send_req(blues_response, 2048))
		{
			Serial.println("Notecard wireless status:");
			Serial.printf("%s\n", blues_response);
			request_success = true;
			break;
		}
	}
	if (!request_success)
	{
		Serial.println("'card.wireless' request failed");
	}
	Serial.println("======================================================");
}

// Interrupt Service Routine for ATTN_INPUT_PIN transitions rising from LOW
// to HIGH
void attnISR()
{
    attnInterruptOccurred = true;
}

// Re-arm the interrupt
void attnArm()
{
    // Make sure that we pick up the next RISING edge of the interrupt
    attnInterruptOccurred = false;
    // Set the ATTN pin low, and wait for the earlier of file modification or
    // a timeout
    //J *req = notecard.newRequest("card.attn");
    //JAddStringToObject(req, "mode", "reset");
    //JAddNumberToObject(req, "seconds", 120);
    //notecard.sendRequest(req);
    
    
}


void resetattnArm()
{
    // Setup signal interrupts
  if (rak_blues.start_req((char *)"card.attn"))
  {
    // Create data file
    rak_blues.add_string_entry((char *)"mode", (char *)"reset");

    Serial.println("Payload created");
    if (!rak_blues.send_req())
    {
      Serial.println("Send request failed : 'card.attn'");
    }
    else
    {
      Serial.println("Request card attn sent to NoteCard");
    }
  }
  else
  {
    Serial.println("Error creating the 'card.attn' request");
  }
}



void startattnArm()
{
    // Setup signal interrupts
  if (rak_blues.start_req((char *)"card.attn"))
  {
    // Create data file
    rak_blues.add_string_entry((char *)"mode", (char *)"arm,signal");

    Serial.println("Payload created");
    if (!rak_blues.send_req())
    {
      Serial.println("Send request failed : 'card.attn'");
    }
    else
    {
      Serial.println("Request card attn sent to NoteCard");
    }
  }
  else
  {
    Serial.println("Error creating the 'card.attn' request");
  }
}

You set the ATTN to be raised when a “signal” is received.

I never worked with “signal” as an ATTN reason, the documentation of Blues about this might help:

card.attn

Not sure what “signals” are:
Signals

Hi @jvdstoel1024 … did you finally made this works?. In addition, @beegee is there any example for rak4631+rak13102 to be used as a reference for blues notecard with attnp interrupt?. Thanks

Blues-WisBlock-Tracker is using attn to detect motion.
Not a simple example, but the only one I have.

1 Like

Thanks @beegee as always for your great support … i’ve finally implemented an sketch for rak4631+rak13102 which successfully manage ATTN interrupt … i’ve tried to minimize as possible power consumption between wakeup periods. Following your LoRa-DeepSleep-Ard.ino reference, i’ve created a semaphore, and put sx1262 into sleep mode with the following sentences:

  // Initialize LoRa Transceiver chip
  lora_rak4630_init();  
  // Put SX1262 LoRa Transceiver into Sleep mode
  Radio.Sleep();

… in addition, the notecard’s mode is configured as minimum, reaching a current consumption around 110uA (measured with PPK2) … however, in case i try to additionaly de-initialize the board peripherals as follows

  // Initialize LoRa Transceiver chip
  lora_rak4630_init();  
  // Put SX1262 LoRa Transceiver into Sleep mode
  Radio.Sleep();
  // De-initialize the target board peripherals to decrease power consumption. 
  lora_hardware_uninit();

… the power consumption for deep sleep intervals rises above 300uA … does it make sense? … it is possible to reduce the power consumption in sleep mode under this 110uA?. Thanks a lot.

lora_hardware_uninit(); is not a good solution for it. The original idea for the “uninit” was to reset the SX1262, SPI, … before a new setup. I think it might leave the SX1262 in standby mode (higher consumption) and not in sleep mode.

110uA seems slightly high for sleep mode of the RAK4630, what else do you have on the board?

… the rak13102 with notecard’s mode configured as minimum and GPS, AUX and accelerometer disabled.

Not sure. What do you get when the Notecard is not present?

… you mean deattaching rak13102 module from wisbase?

yes, just the BaseBoard and the RAK4631.
I don’t remember what the NoteCard was using.

Hi @beegee … sorry for the delay. I forgot that there was also a RAK15005 FRAM module on the board connected to the RAK4631. In case i turn off the power supply for this module (by setting WB_IO2 pin to LOW), the current consumption for sleep mode with the RAK13102 configuration i mention, drops to around 80uA.