Project

General

Profile

RFM12B board not working together with Micro Pro? (No pin 11, 12, 13)

Added by julle.p 5 months ago

Hi Jee's :-)

I have an issue with the RFM12B module driver.
http://jeelabs.net/projects/hardware/wiki/RFM12B_Board

When uploading the RF12demo code to an Arduino Clone Micro Pro, the Arduino IDE says 'Done Uploading', but then bricks the Arduino - it never becomes visible again, i.e. the COM port disappears. The only way to recover the Arduino is by entering the bootloader mode, and quickly upload a simple sketch (e.g. Blinking led). This repairs the Arduino - I can then upload the RF12demo example again, and it bricks the Micro Pro again.

The Arduino Clone Micro Pro is working well, when trying one of the simple built-in examples, like Blinking led (i.e. the output pin changes between high and low).

Important to say is, that I haven't even connected the RFM12B board to the Arduino - the Arduino is only connected to the PC using USB. So I haven't messed up that part :-)

The RF12demo example is working when uploading to an official Arduino Mega.

Facts about hardware:
Arduino Clone, Pro Micro ATmega32U4, running Leonardo.

More info can be found here - please note, it is not the Sparkfun version I have, but it is an eBay clone of that. The one I have is running the Leonardo bootloader, not the Spartfun Leonardo bootloader.
https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide/hardware-overview-pro-micro

As you can see from the link, the Micro Pro does NOT have a pin number 11, 12 nor 13 - and I believe the library expects those pin numbers??

I hope you can help!

Thanks, Alex.


Replies (22)

RE: RFM12B board not working together with Micro Pro? (No pin 11, 12, 13) - Added by JohnO 5 months ago

It is important to have a radio actually connected to the hardware when the RF12Demo sketch starts up. RF12Demo attempts to configures the radio at startup and spins waiting for the radio responses. If using a ATmega32U4 the code expects to see the SPI connected like this:

#elif defined(__AVR_ATmega32U4__) //Arduino Leonardo

#define RFM_IRQ     0       // PD0, INT0, Digital3
#define SS_DDR      DDRB
#define SS_PORT     PORTB
#define SS_BIT      6       // Dig10, PB6

#define SPI_SS      17    // PB0, pin 8, Digital17
#define SPI_MISO    14    // PB3, pin 11, Digital14
#define SPI_MOSI    16    // PB2, pin 10, Digital16
#define SPI_SCK     15    // PB1, pin 9, Digital15

RE: RFM12B board not working together with Micro Pro? (No pin 11, 12, 13) - Added by julle.p 5 months ago

Thanks a lot for your reply.

When running the example code on the Arduino Mega, with no other hardware, I am still able to use the Serial Monitor. It even outputs some help information:
[RF12demo.12] A i1 g212 @ 868 MHz q1

Available commands:
i - set node ID (standard node ids are 1..30)
b - set MHz band (4 = 433, 8 = 868, 9 = 915)
o - change frequency offset within the band (default 1600)
* 96..3903 is the range supported by the RFM12B*
g - set network group (RFM12 only allows 212, 0 = any)
c - set collect mode (advanced, normally 0)
t - broadcast max-size test packet, request ack
..., a - send data packet to node , request ack
..., s - send data packet to node , no ack
q - set quiet mode (1 = don't report bad packets)
x - set reporting format (0: decimal, 1: hex, 2: hex+ascii)
123 z - total power down, needs a reset to start up again
Remote control commands:
,,, f - FS20 command (868 MHz)
,, k - KAKU command (433 MHz)
Current configuration:
A i1 g212 @ 868 MHz q1

But when running the code on the Leonardo Clone (Pro Micro), I loose connection and is not able to reconnect to it.

I am changing to the correct board in the Board Manager, and then compiling to that specific target.

Any ideas what can go wrong, and how I can debug any further?
I can try to hook up the RFM12B board tonight when I get home, but I would expect to be able to get to the same states as the Arduino Mega, before hooking up the actual hardware...

RE: RFM12B board not working together with Micro Pro? (No pin 11, 12, 13) - Added by jcw 5 months ago

Did you select Leonardo as board type in the Arduino IDE?

As far as I know, the Leonardo needs to have runtime support included to keep the USB connection going.

Edit: also, pending output may not get sent back if the sketch crashes before the output is sent out by the USB driver. So indeed, better to have a radio connected. You could also modify the sketch to send out a greeting on startup and delay(1000) to make sure it goes out.

RE: RFM12B board not working together with Micro Pro? (No pin 11, 12, 13) - Added by julle.p 5 months ago

Yes, Leonardo is selected as board :-)

What I find strange, is that my COM port disappears. This does not happen when uploading an Arduino built in exaple.
I'll try with hardware connected tonight.

RE: RFM12B board not working together with Micro Pro? (No pin 11, 12, 13) - Added by julle.p 5 months ago

Hmm, just took a look at the pinout you gave:

#define RFM_IRQ 0 // PD0, INT0, Digital3
#define SS_DDR DDRB
#define SS_PORT PORTB
#define SS_BIT 6 // Dig10, PB6

#define SPI_SS 17 // PB0, pin 8, Digital17
#define SPI_MISO 14 // PB3, pin 11, Digital14
#define SPI_MOSI 16 // PB2, pin 10, Digital16
#define SPI_SCK 15 // PB1, pin 9, Digital15

I'm not sure this makes sense for the Micro Pro... See image below.
Pin 3 is correct, it is intertupt 0.

However, I cannot understand pin 8, 9, 10, 11, and the mapping to 17, 15, 16, 14.
As you can see on the image, the pin number is the same as the digital IO. And no pin 17 exists?


Taken from documentation:
- https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide/hardware-overview-pro-micro

FYI, this is the board I have:
http://www.ebay.co.uk/itm/272374507509?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

RE: RFM12B board not working together with Micro Pro? (No pin 11, 12, 13) - Added by JohnO 5 months ago

This schematic shows PD0 linked to D17: http://cdn.sparkfun.com/datasheets/Dev/Arduino/Boards/Pro-Micro-v11-5V_B.pdf

I think it will be the same for the 3v version.

RE: RFM12B board not working together with Micro Pro? (No pin 11, 12, 13) - Added by JohnO 5 months ago

But looks like it is used for an LED. Umh...

RE: RFM12B board not working together with Micro Pro? (No pin 11, 12, 13) - Added by julle.p 5 months ago

Yes, the board has two LEDs for UART communication, one for sending and one for receiving data.
Hmm, can it be used for both? I guess not - maybe that is why my COM communication breaks?

RE: RFM12B board not working together with Micro Pro? (No pin 11, 12, 13) - Added by JohnO 5 months ago

PB0 is for chip select, there is code in the library to change that at runtime:

// function to set chip select pin from within sketch
void rf12_set_cs (uint8_t pin) {
#if defined(__AVR_ATmega32U4__) //Arduino Leonardo
  cs_pin = pin - 4;             // Dig10 (PB6), Dig9 (PB5), or Dig8 (PB4)
#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328__) || defined (__AVR_ATmega328P__) // ATmega168, ATmega328
  cs_pin = pin - 8;             // Dig10 (PB2), Dig9 (PB1), or Dig8 (PB0)
#endif
}

RE: RFM12B board not working together with Micro Pro? (No pin 11, 12, 13) - Added by JohnO 5 months ago

I think you have spotted a glitch. When you get home it would be good to know which free ports you have to connect to instead of D17. I would like you to have D10 which is PB6. If it is available a code tweak to test the new settings is needed.

Are you able to edit your copy of rf12.cpp in the jeelib library as follows:
Change line 96 from:

#define SPI_SS      17    // PB0, pin 8, Digital17

to:

#define SPI_SS      10    // PB6, pin 30, Digital10

Let us know how you get on.

RE: RFM12B board not working together with Micro Pro? (No pin 11, 12, 13) - Added by julle.p 5 months ago

Sounds very interesting!

I will modify the code to what you have suggested, and report back :-) This is how it will look like for the Leonardo:
#define RFM_IRQ 0 // PD0, INT0, Digital3
#define SS_DDR DDRB
#define SS_PORT PORTB
#define SS_BIT 6 // Dig10, PB6

#define SPI_SS 10 // PB6, pin 30, Digital10
#define SPI_MISO 14 // PB3, pin 11, Digital14
#define SPI_MOSI 16 // PB2, pin 10, Digital16
#define SPI_SCK 15 // PB1, pin 9, Digital15

However, isn't that already used for SS_BIT? What is SS_BIT, because I only have 5 wires from the RFM12B board, so is it some internal routing?

Just to be sure, this is how it is then supposed to be connected (name in code, name on board):
RFM_IRQ = IRQ => Pin 3
SPI_SS = SEL => Pin 10
SPI_MISO = SDQ => Pin 14
SPI_MOSI = SDI => Pin 16
SPI_SCK = SCK => Pin 15

RE: RFM12B board not working together with Micro Pro? (No pin 11, 12, 13) - Added by JohnO 5 months ago

It get hard around here, SS_BIT is the bit position (0 to 7) within Port B these hardware ports are mapped to Digital/Analogue using "Arduino Wiring". They map to the same pin but the hardware method is a very quick way to set pins whereas setting pins using Digital10 with Arduino Wiring is slower.

RE: RFM12B board not working together with Micro Pro? (No pin 11, 12, 13) - Added by jcw 5 months ago

#define SPI_SS 10

This is a quirk in AVR's implementation of SPI: the pin must be defined as an output pin for SPI to be used as master - even if some other pin is actually selecting the slave. IOW, pin 10 must be set as an output, regardless what it's used for, and the actual select bit must match what's hooked up to the radio module.

RE: RFM12B board not working together with Micro Pro? (No pin 11, 12, 13) - Added by julle.p 5 months ago

Great! Thanks for your replies.
I'll get back to you, as soon as I have tested it :-)

RE: RFM12B board not working together with Micro Pro? (No pin 11, 12, 13) - Added by julle.p 5 months ago

Yah! Success! I am now able to communicate between an Arduino Clone Micro Pro (Leonardo) and an official Arduino Mega!

For reference:
- Arduino Clone Micro Pro
SCK => DIO15
SDQ => DIO14
SDI => DIO16
SEL => DIO10 NB: Code change needed in JeeLib
IRQ => DIO3
- Arduino Mega
SCK => DIO52
SDQ => DIO50
SDI => DIO51
SEL => DIO53
IRQ => DIO2

A couple of things I have noticed:
* Arduino Clone Micro Pro is NOT able of running the RFM12demo example, if the RFM12B board is NOT connected. The COM port isn't recognized, and it kinda seem like it's bricked.
* Arduino Mega IS capable of running the RFM12demo example, even without the RFM12B board connected. You can display the Help menu (type ?), and you can change the frequency (type 8b).
* The LED on pin13 on the Arduino Mega is always on, when running the example. In the example code, we define a LED_PIN, but this is set to "9", so I'm still a bit puzzled about this??

RE: RFM12B board not working together with Micro Pro? (No pin 11, 12, 13) - Added by JohnO 5 months ago

Pleased you got things working, we are looking at upgrading the library to correct the inconsistency. Your "Arduino Mega" is behaving unusually in that the user interface as coded should hang if the radio is not present. Which device do you select from the Boards menu when programming your "Arduino Mega"?

RE: RFM12B board not working together with Micro Pro? (No pin 11, 12, 13) - Added by julle.p 5 months ago

And thank you very much for all your support and help!

Regarding the Mega, I have selected the following when compiling:
- Board: Arduino /Genuino Mega or Mega 2560
- Processor: ATmega 2560 (Mega 2560)

Any idea why the LED on pin 13 is on? I have tried to upload another sketch that turns it off, but when I upload the RFM12demo, it turns on again?

What are the limitations, if I want to use other pins on the Mega, than the default ones? I know that IRQ needs to be on a pin that supports interrupts, but does the other 4 pins have any requirements, or can I use any DIO?

RE: RFM12B board not working together with Micro Pro? (No pin 11, 12, 13) - Added by JohnO 5 months ago

Have you tried changing "#define LED_PIN 9 // activity LED, comment out to disable" to the pin 13 value? The undefined state of pin 13 is being represented by the led being on.

Specific pins on the processor are designated as the SPI bus pins, your processor may have two sets of SPI buses in which case you should be able to use either. It is probably more predictable to stick with the pins that other people are using.

RE: RFM12B board not working together with Micro Pro? (No pin 11, 12, 13) - Added by julle.p 5 months ago

Thanks for helping!

I have now tested, where I have changed the LED-PIN to value 13. This does not change the behaviour on the MEGA. Nor does it change anything to comment out the entire line. The built-in LED is continuously on.

Do you have more detailed information about the SPI busses - e.g. how many does the MEGA have, which pins are they, and most importantly which of the 5 pins on the RFM12B board uses the SPI bus pin?

Thanks!

RE: RFM12B board not working together with Micro Pro? (No pin 11, 12, 13) - Added by JohnO 5 months ago

I think some time spent with the datasheet will put you in the right direction. From a brief scan it appears that only one hardware SPI is present.

Regarding pin 13, you don't mention which code line you adjusted but I think that line 31:

#define LED_PIN     9       // activity LED, comment out to disable

is what you ought to change, I don't know your hardware and am guessing that the software wiring is set up like this.

Note the use of underscore '_' versus the hypen '-' you mention in your post above.

RE: RFM12B board not working together with Micro Pro? (No pin 11, 12, 13) - Added by JohnO 5 months ago

Just found this which introduces the SPI bus.

    (1-22/22)