Author Topic: IRQ in RFM12b library  (Read 16222 times)

Lensdigital

  • Full Member
  • ***
  • Posts: 155
    • Lensdigital
IRQ in RFM12b library
« on: August 07, 2014, 07:17:33 PM »
I'm hoping someone can push me in the right direction with issue that I'm having :)
I previously successfully used my ATMega1284p based boards with RFM12b modules setup as receiver. 
Code: [Select]
#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
  #define RFM_IRQ    10
10 in this case corresponds to PD2/INT0 pin a.k.a. D10.
I built new board where RFM12b module's IRQ is connected to different (PB2/INT2) D2 pin. Changed RFM_IRQ to 2 and nothing works.
Now comes super weird part. I soldered RFM12b chip's IRQ connector to D10 (PD2/INT0) pin without cutting trace to D2 pin. Changed IRQ definition to 10 and it doesn't work. But when I change it to 2, it totally worked! If I cut soldered wire, it stops working. For some reason it seems like it needs to be connected to both D2 and D10 now in order to work.  Is it possible that somewhere in the library something is hard-coded to use IRQ port D10?
It's possible that something is flawed in my PCB design, but I don't understand why it needs to be connected to D10 in order to work with D2...

emjay

  • Full Member
  • ***
  • Posts: 119
  • Country: nl
Re: IRQ in RFM12b library
« Reply #1 on: August 09, 2014, 12:52:09 AM »
Do you have actual pull-up resistors on either INT pin?   Configuring the internal pull-up on the I/O pin is adequate for short PCB traces, but does need doing in the init code.

Lensdigital

  • Full Member
  • ***
  • Posts: 155
    • Lensdigital
Re: IRQ in RFM12b library
« Reply #2 on: August 10, 2014, 04:06:17 PM »
Do you have actual pull-up resistors on either INT pin?   Configuring the internal pull-up on the I/O pin is adequate for short PCB traces, but does need doing in the init code.
I do not. I only have pullup on SS (Chip Select) pin.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: IRQ in RFM12b library
« Reply #3 on: August 11, 2014, 08:37:40 AM »
Not sure what core you use for 1284p but you will need to make sure the IRQ2 corresponds to the pin you expect it to. And also change the reference of that pin in the library. Your core has to define which pin is the external interrupt one.

Lensdigital

  • Full Member
  • ***
  • Posts: 155
    • Lensdigital
Re: IRQ in RFM12b library
« Reply #4 on: August 11, 2014, 10:48:06 AM »
Not sure what core you use for 1284p but you will need to make sure the IRQ2 corresponds to the pin you expect it to. And also change the reference of that pin in the library. Your core has to define which pin is the external interrupt one.
I'm using Mighty-1284p bootloader, but good point I'll see if maybe IRQ2 is not properly defined the bootloader files.
Also I see that you now have ATMega1284p based Moteino, that is freaking awesome. Do you have your dual-optiboot version for this chip available for download? I'd love to try it out.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: IRQ in RFM12b library
« Reply #5 on: August 11, 2014, 12:49:00 PM »
Thanks!
I haven't released the DualOptiboot upgrade yet but you can find the bootloader HEX in the core package here:
https://github.com/LowPowerLab/Moteino/blob/master/MEGA/Core/MoteinoMEGA_Core.zip

Charly86

  • Jr. Member
  • **
  • Posts: 74
  • Country: fr
Re: IRQ in RFM12b library
« Reply #6 on: August 28, 2014, 08:13:57 PM »
Lensdigital

sure it does not work, I had the same problem and this this historical to jeelab port, the IRQ are hardcoded into the code, if you change the pin, it it will simply not work.

Somewhere in the code, hard coded to INT0 (and that is not the only place)

Code: [Select]
  if (nodeID != 0)
    attachInterrupt(0, RFM12B::InterruptHandler, LOW);
else
    detachInterrupt(0);

Based on Felix's lib there is a new version where you can change the IRQ and CS line in the code (among some other new features) that does work on my 328P but shoud work on 1284, if you can do a test and confirm it could be cool

here's the post http://hallard.me/rfm12b_arssi-library/ for more information

 

Lensdigital

  • Full Member
  • ***
  • Posts: 155
    • Lensdigital
Re: IRQ in RFM12b library
« Reply #7 on: August 28, 2014, 11:08:01 PM »
Wow thank you! I will give it a try and will report back!

Charly86

  • Jr. Member
  • **
  • Posts: 74
  • Country: fr
Re: IRQ in RFM12b library
« Reply #8 on: August 29, 2014, 05:57:29 AM »
The Library has been updated to 1284p interrupt comptatibility.
Please use the latest version on github, not tried (I don't have one) but it should work better for any of the 3 external interrupt on 1284p ;)

https://github.com/hallard/RFM12B_arssi

Lensdigital

  • Full Member
  • ***
  • Posts: 155
    • Lensdigital
Re: IRQ in RFM12b library
« Reply #9 on: August 30, 2014, 10:24:03 PM »
It's not compiling for 1284p chip :(

Code: [Select]
d:\Documents\Arduino\libraries\RFM12B_arssi\RFM12B_arssi.cpp: In static member function 'static void RFM12B::ConfigureInterrupts()':
d:\Documents\Arduino\libraries\RFM12B_arssi\RFM12B_arssi.cpp:144: error: 'irqPin' was not declared in this scope
d:\Documents\Arduino\libraries\RFM12B_arssi\RFM12B_arssi.cpp:144: error: 'irqpin' was not declared in this scope

Seem to work when I select Uno board, but when I choose "Mightly 1284p" it gives me above error
« Last Edit: August 30, 2014, 10:25:40 PM by Lensdigital »

Charly86

  • Jr. Member
  • **
  • Posts: 74
  • Country: fr
Re: IRQ in RFM12b library
« Reply #10 on: August 31, 2014, 07:14:30 AM »
Lensdigital,

Correct, I tried to compile for Mighty1284p it was not working, just pushed the new version which compile fine now.

Sorry about that.

Lensdigital

  • Full Member
  • ***
  • Posts: 155
    • Lensdigital
Re: IRQ in RFM12b library
« Reply #11 on: August 31, 2014, 10:33:34 AM »
Lensdigital,

Correct, I tried to compile for Mighty1284p it was not working, just pushed the new version which compile fine now.

Sorry about that.
Thanks! I complies now but doesn't work. I tested my original 1284p board where CS is pin D18 and IRQ is D10, but it says: RFM12B Detection FAIL!
Code: [Select]
#define RFM_CS_PIN  18 // RFM12B Chip Select Pin
#define RFM_IRQ_PIN 10  // RFM12B IRQ Pin

Same issue with newer board where IRQ is D2...

I verified that same sketch works fine with Moteino R2 (w/ different pin definitions of course)...
Is there something I should modify in header perhaps?

Charly86

  • Jr. Member
  • **
  • Posts: 74
  • Country: fr
Re: IRQ in RFM12b library
« Reply #12 on: August 31, 2014, 11:13:33 AM »
Your sketch looks good, I noticed during my test that isPresent(..) method works, whatever IRQ is. Because there is no transmit/receive while trying to detect module, So I'm suspecting a chip select problem, but,

You said you connected RFM12B CS to D18, just to be sure, this is connected to PC2 Pin of Atmega 1284p right ? and you're using Felix's Mega Arduino IDE board and source ?

The pin definition is tweaked by Felix are :

Code: [Select]

//                         ATMEL ATMEGA644P/1284P
//
//                               +---\/---+
//            PCINT8/(D0 ) PB0  1|        |40  PA0 (A0 / D24)/PCINT0
//            PCINT9/(D1 ) PB1  2|        |39  PA1 (A1 / D25)/PCINT1
//      PCINT10/INT2 (D2 ) PB2  3|        |38  PA2 (A2 / D26)/PCINT2
//      PCINT11/OC0A (D3 ) PB3  4|~       |37  PA3 (A3 / D27)/PCINT3
//   PCINT12/0C0B/SS (D4 ) PB4  5|~       |36  PA4 (A4 / D28)/PCINT4
//      PCINT13/MOSI (D5 ) PB5  6|        |35  PA5 (A5 / D29)/PCINT5
// PCINT14/OC3A/MISO (D6 ) PB6  7|~*      |34  PA6 (A6 / D30)/PCINT6
//  PCINT15/OC3B/SCK (D7 ) PB7  8|~*      |33  PA7 (A7 / D31)/PCINT7
//                         RST  9|        |32  AREF
//                         VCC 10|        |31  GND
//                         GND 11|        |30  AVCC
//                       XTAL2 12|        |29  PC7 (D23) TOSC2/PCINT23
//                       XTAL1 13|        |28  PC6 (D22) TOSC1/PCINT22
//       PCINT24/RX0 (D8 ) PD0 14|        |27  PC5 (D21) TDI/PCINT21
//       PCINT25/TX0 (D9 ) PD1 15|        |26  PC4 (D20) TDO/PCINT20
//  PCINT26/INT0/RX1 (D10) PD2 16|        |25  PC3 (D19) TMS/PCINT19
//  PCINT27/INT1/TX1 (D11) PD3 17|        |24  PC2 (D18) TCK/PCINT18
//      PCINT28/OC1B (D12) PD4 18|~       |23  PC1 (D17) SDA/PCINT17
//      PCINT29/OC1A (D13) PD5 19|~       |22  PC0 (D16) SCL/PCINT16
//      PCINT30/OC2B (D14) PD6 20|~      ~|21  PD7 (D15) OC2A/PCINT31
//                               +--------+
//

By the way I just saw a bug for D2 as IRQ, I fixed it and just updated the library, could you retry with IRQ D2 (which should not solve if the problem is coming from CS 18 pin)

So last test could be, if it's possible for you to change CS pin, just to see and connect it do D4 (PB4 of atmel)

Code: [Select]
#define RFM_CS_PIN  SS // RFM12B Chip Select Pin
#define RFM_IRQ_PIN 2  // RFM12B IRQ Pin )

I think I'm definitely need a 1284p board to investigate on this issue, because I'm using the lib on several different 328p boards, with D2/D3 as IRQ and D10/D5 as CS without any problem.

Let me know it it's better like that
« Last Edit: August 31, 2014, 11:16:01 AM by Charly86 »

Lensdigital

  • Full Member
  • ***
  • Posts: 155
    • Lensdigital
Re: IRQ in RFM12b library
« Reply #13 on: August 31, 2014, 02:38:35 PM »
Sorry it still not working :(
Yes it's PC2 pin (physical pin 24), but I'm not using Felix's board :)  It's my own design, here's link to Eagle schematic and I'll post image at the end. One possible issue might is that I have pullup resistor on CS/SS line. I think it would be best if I build naked breadboard version of ATMega1284p with RFM12b and test it, this way I'll know for sure...
I will try today/tomorrow.
Schematic URL

Charly86

  • Jr. Member
  • **
  • Posts: 74
  • Country: fr
Re: IRQ in RFM12b library
« Reply #14 on: September 01, 2014, 06:58:34 AM »
Lensdigital,

Whatever you use Felix's board or not is not a problem for the lib, only the wiring matter. And your wiring match Felix Moteino Mega core so it should work. I do not know if Felix added func to his own RFM12B library to support mega (I don't think so) but it could be a good testing.

By the way pullup on CS is not necessary for testing because I setup CS pin as output with pullup in the code of the lib.

I sampled some 1284p in DIP40 format, I will try on a breadboard as soon as I get them to investigate this issue.

I saw also that on Mega board Felix as pushed a new version of SPI library driver in the Mega Core package, have you installed his Core for Arduino IDE ? I will check into this new SPI.cpp the differences with the one included in Arduino IDE 1.0.5, may the problem is on some difference in SPI calls for the MEGA, I'll dig on this.

Charly86

  • Jr. Member
  • **
  • Posts: 74
  • Country: fr
Re: IRQ in RFM12b library
« Reply #15 on: September 01, 2014, 07:39:24 AM »
I think I found the problem, in fact, for SPI the RFM12B Library use this definitions (in rfm12b_arrsi.h)

Code: [Select]
#define SPI_SS          10  // D10 
#define SPI_MOSI        11  // PB3, pin 17
#define SPI_MISO        12  // PB4, pin 18
#define SPI_SCK         13  // PB5, pin 19

I did not remembered that and I though in my code that these defined values were done by Arduino environment so adapted to SPI hardware depending on the target, but it's not and for the 1284p these pins are not for the hardware SPI and so they are wrong and should be :

Code: [Select]
#define SPI_SS          4   // PB4, pin 5
#define SPI_MOSI        5   // PB5, pin 6
#define SPI_MISO        6   // PB6, pin 7
#define SPI_SCK         7   // PB7, pin 8

So I added the following definition in the rfm12b_arssi.h for the library
Code: [Select]
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega88) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__)
  #define RFM_DEFAULT_IRQ 2   // default IRQ PIN D2 (can be changed by SetIRQ)
  #define SPI_SS          10  // D10
  #define SPI_MOSI        11  // PB3, pin 17
  #define SPI_MISO        12  // PB4, pin 18
  #define SPI_SCK         13  // PB5, pin 19
#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
  #define RFM_DEFAULT_IRQ 2   // default IRQ PIN D2 -> PB2, pin 3(can be changed by SetIRQ)
  #define SPI_SS          4   // PB4, pin 5
  #define SPI_MOSI        5   // PB5, pin 6
  #define SPI_MISO        6   // PB6, pin 7
  #define SPI_SCK         7   // PB7, pin 8
#else
  #error Target not supported for HW Interrupts
#endif

And I'm sure it should be working much better now, let me know

Library has been updated according the above modifications

« Last Edit: September 01, 2014, 07:40:59 AM by Charly86 »

Lensdigital

  • Full Member
  • ***
  • Posts: 155
    • Lensdigital
Re: IRQ in RFM12b library
« Reply #16 on: September 02, 2014, 09:42:50 PM »
Wow you did it! It works on my breadboard setup and with actual circuit!  I kind of suspected it was issue with PORT names :)
So RFM_CS_PIN and RFM_IRQ_PIN definitions in the sketch are optional?
« Last Edit: September 02, 2014, 09:59:19 PM by Lensdigital »

Charly86

  • Jr. Member
  • **
  • Posts: 74
  • Country: fr
Re: IRQ in RFM12b library
« Reply #17 on: September 03, 2014, 04:09:09 AM »
Great that it works  :)
The definition RFM_CS_PIN and RFM_IRQ_PIN are default IRQ used a compilation time, but you can change them according to your wiring in the setup of your sketch (or at any place) using the 2 following lines of code (this has to be done only once) :

Code: [Select]
// sample setting
uint8_t arduinoCSPin = D7 ;
uint8_t ArduinoIRQPin = D3 ;

// This is for choosing the CS pin where is connected the Chip Select pin of the RFM12B
// Arduino pin is Arduino format (5, 8, … A2, ..)
// This call should be done before any Initialize(…) standard code
radio.SetCS( arduinoCSPin );

// This is for choosing the Hardware IRQ pin where is connected the IRQ of the RFM12B.
// You can only use with external hardware IRQ of Arduino, so for :
// ATMega328 it’s 2 for IRQ Pin 2 (INT0) and 3 for IRQ Pin 3 (INT1).
// ATMega1284 it’s 10 for IRQ Pin 10 (INT0), 11 for IRQ Pin 11 (INT1) and 2 for IRQ Pin 2 (INT3)
radio.SetIRQ( ArduinoIRQPin );

// Then Initialize the RFM module
radio.Initialize(....)

You can avoid these 2 calls when trying detecting the Module presence,

Code: [Select]
Serial.print(F("Trying to detect RFM12B..."))

// Check if RFM12B device is present, return true if RFM12B device is detected using the cspin and irqpin false otherwise (same format as above)
// This call inside call SetCS and SetIRQ so if you call isPresent you can avoid calling SetCS and SetIRQ.
// If you call isPresent without parameters it assume that the RFM12B module is connected with default values (CS=D10 and IRQ=D2)
if ( radio.isPresent( arduinoCSPin , arduinoIRQPin ) )
{
  Serial.print(F("Found!"))
  radio.Initialize(...)
}
else
{
  Serial.print(F("Not Found, check Wiring)"))
}

Let me know if you have any question. If you want more details, take a look at the documentation