So.....
I have a bigger problem since yesterday. When I run a sketch from Nick Gammon, I can get the microcontroller down to 80uA. When I put it in my code, this value increases to 450uA. Which is 5 times worse.
I played with my interrupts, They are active low and connected to the ground while being pulled up. They have to be **Normally Closed **for my project which means that they are triggered when they are Not connected.
When I saw 400uA, I opened the interrupt lines (5 interrupts) and after disconnecting them all, **the current went down to 40uA. **
I will write the code for you guys:
#include <arduino.h>
#include "HopeDuino_LoRa.h"
#include <avr/sleep.h>
#include "LowPower.h"
#include <avr/power.h>
#define RX_MODE 1
#define TX_MODE (!RX_MODE)
#define LEN 32
const int buttonPin0 = 0; // the number of the pushbutton pin
const int buttonPin1 = 1;
const int buttonPin2 = 2;
const int buttonPin3 = 3;
const int buttonPin4 = 7;
// variables will change:
volatile int stud0,stud1,stud2,stud3,stud4= 0; // variable for reading the pushbutton status
#define LED_PIN 6
#define LED_PORT() pinMode(LED_PIN,OUTPUT)
#define LED_HIGH() digitalWrite(LED_PIN,HIGH)
#define LED_LOW() digitalWrite(LED_PIN,LOW)
/*****************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
byte str[LEN] = {'H','o','p','e','R','F',' ','R','F','M',' ','C','O','B','R','F','M','9','5','W','A','+','+','+'};
byte getstr[LEN];
byte mode = RX_MODE;
const byte app_syncword[] = { 0x2D, 0xD4, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0 } ;
void setup(void)
{
byte i;
LED_PORT();
Modulation = LORA; ///Was FSK
COB = RFM95; // Was RFM95
Frequency = 915000; // was 866000
OutputPower = 10; //17dBm OutputPower
PreambleLength = 8; //8Byte preamble
FixedPktLength = true; //explicit header mode for LoRa
PayloadLength = 21;
CrcDisable = true ;
//for LORA parameter
SFSel = SF9;
BWSel = BW125K;
CRSel = CR4_5;
// initialize the pushbutton pin as an input:
pinMode(buttonPin0, INPUT_PULLUP);
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(buttonPin3, INPUT_PULLUP);
pinMode(buttonPin4, INPUT_PULLUP);
// Attach an interrupt to the ISR vector
attachInterrupt(digitalPinToInterrupt(buttonPin0|buttonPin1|buttonPin2|buttonPin3|buttonPin4), pin_ISR, HIGH);
vInitialize();
_delay_ms(10);
/************************
* LOW POWER parameters
************************/
// disable ADC
ADCSRA = 0;
delay(50);
power_adc_disable();
delay(50);
power_usart0_disable();
delay(50);
power_spi_disable();
delay(50);
power_twi_disable();
delay(50);
power_timer1_disable();
delay(50);
power_timer2_disable();
delay(50);
power_timer3_disable();
delay(50);
power_usart1_disable();
delay(50);
power_usb_disable();
delay(50);
USBCON |= (1 << FRZCLK); // Freeze the USB Clock
PLLCSR &= ~(1 << PLLE); // Disable the USB Clock (PPL)
USBCON &= ~(1 << USBE ); // Disable the USB
delay(50);
// Switch to RC Clock
UDINT &= ~(1 << SUSPI); // UDINT.SUSPI = 0; Usb_ack_suspend
USBCON |= ( 1 <<FRZCLK); // USBCON.FRZCLK = 1; Usb_freeze_clock
PLLCSR &= ~(1 << PLLE); // PLLCSR.PLLE = 0; Disable_pll
CLKSEL0 |= (1 << RCE); // CLKSEL0.RCE = 1; Enable_RC_clock()
while ( (CLKSTA & (1 << RCON)) == 0){} // while (CLKSTA.RCON != 1); while (!RC_clock_ready())
CLKSEL0 &= ~(1 << CLKS); // CLKSEL0.CLKS = 0; Select_RC_clock()
CLKSEL0 &= ~(1 << EXTE); // CLKSEL0.EXTE = 0; Disable_external_clock
delay(100);
}
void loop(void)
{
static byte last_mode=RX_MODE;
byte tmp;
pin_ISR();
stud0 = digitalRead(buttonPin0);
stud1 = digitalRead(buttonPin1);
stud2 = digitalRead(buttonPin2);
stud3 = digitalRead(buttonPin3);
stud4 = digitalRead(buttonPin4);
digitalWrite(LED_PIN, LOW);
if (stud0||stud1||stud2||stud3||stud4==1){
bSendMessage(str, 26);
LED_HIGH();
_delay_ms(250);
LED_LOW();
}
else {
LED_LOW();
}
ADCSRA = 0;
set_sleep_mode (SLEEP_MODE_PWR_DOWN);
noInterrupts (); // timed sequence follows
sleep_enable();
// turn off brown-out enable in software
// MCUCR = bit (BODS) | bit (BODSE);
// MCUCR = bit (BODS);
interrupts (); // guarantees next instruction executed
sleep_cpu ();
}
void pin_ISR() {
stud0 = digitalRead(buttonPin0);
stud1 = digitalRead(buttonPin1);
stud2 = digitalRead(buttonPin2);
stud3 = digitalRead(buttonPin3);
stud4 = digitalRead(buttonPin4);
digitalWrite(LED_PIN, stud0);
digitalWrite(LED_PIN, stud1);
digitalWrite(LED_PIN, stud2);
digitalWrite(LED_PIN, stud3);
digitalWrite(LED_PIN, stud4);
}
How can I modify the interrupts so that it doesn't draw current?