LowPowerLab Forum

Hardware support => Moteino => Topic started by: ianselmi on June 19, 2014, 07:25:14 PM

Title: RFM12B and cli [solved]
Post by: ianselmi on June 19, 2014, 07:25:14 PM
Hi to all,
I wrote some test to use moteino to read a water flow meter like this http://www.seeedstudio.com/forum/viewtopic.php?f=4&t=989&start=0
To read a values I used a interrupt. If I test the code on arduino it's works fine.
If I test the code on moteino with radio enabled the code hang.
If I test the code on moteino without radio enabled the code works fine.
The the code is the follow:


#include <RFM12B.h>

volatile int NbTopsFan; //measuring the rising edges of the signal
double Calc;
double LitriTotali = 0;

unsigned long startMillis = 0;
const int ledPin = 9;
//
typedef struct {
int temperature, tzdst;
double wh_gen, wh_consuming;     //variables to store cumulative power being generated, consumed, dumping

}  PayloadGLCD;
PayloadGLCD emonglcd;

RFM12B radio;

//--------------------------------------------------------------------------------------------
// RFM12B Settings
//--------------------------------------------------------------------------------------------
#define MYNODE 25           // Should be unique on network, node ID 30 reserved for base station
#define freq RF12_868MHZ     // frequency - match to same frequency as RFM12B module (change to 868Mhz or 915Mhz if appropriate)
#define group 210            // network group, must be same as emonTx and emonBase

void rpm()     //This is the function that the interupt calls
{
NbTopsFan++;  //This function measures the rising and falling edge of the hall effect sensors signal
}



void setup()
{
radio.Initialize(MYNODE, freq, group);
Serial.begin(9600);
Serial.println("initialing...");
attachInterrupt(1, rpm, RISING);
}

void loop()
{
Serial.print(" loop ");
Serial.print(" 1 ");
sei();
delay(1000);
cli();     

Serial.print(" radio ");

int i = 0; while (!radio.CanSend() && i<10) { radio.ReceiveComplete(); i++; }

Serial.print(" send ");
radio.SendStart(0, &emonglcd, sizeof emonglcd);
Serial.print(" wait ");
radio.SendWait(0);
Serial.print(" end ");


}


The code hang also if I wrote attachInterrupt(0, rpm, RISING);

I use moteino R2 and RFM12B.

Can someone help me?

Thanks a lot for help
Title: Re: RFM12B and cli
Post by: Felix on June 20, 2014, 08:11:35 AM
RFM12b is using interrupt 0. Use interrupt 1 instead.
Title: Re: RFM12B and cli
Post by: ianselmi on June 22, 2014, 12:47:51 PM
It's works
thanks