IRQ in RFM12b library

Started by Lensdigital, August 07, 2014, 07:17:33 PM

Lensdigital

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. 
#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

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

Quote from: emjay 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.
I do not. I only have pullup on SS (Chip Select) pin.

Felix

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

Quote from: Felix 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.
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

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

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)

  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

Wow thank you! I will give it a try and will report back!

Charly86

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

#9
It's not compiling for 1284p chip :(

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

Charly86

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

Quote from: Charly86 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.
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!
#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

#12
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 :

//                         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)

#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

Lensdigital

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

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.