RFM69

Can someone help me port this library?
patafix
Posts: 7
Joined: Fri Nov 25, 2016 1:57 am

RFM69

Post by patafix » Fri Nov 25, 2016 2:03 am

Hello, I am new here. I am using https://github.com/LowPowerLab/RFM69 on my current AVR solution, however, it proves to be hard to implement it on Maple mini. There is this library https://github.com/ahessling/RFM69-STM32 that was implemented in plain C++, however it is not particularly well documented.
Any chance anyone has one already ported or can give some tips as to where to start? I manage to compile it without errors, but once I upload it to Maple mini clone - it just stops responding, so I know I have messed up somewhere.

It is very simplistic library (the LowPowerLab one), but I have had no experience of ARM mcus, so any tips would me much appreciated.

User avatar
RogerClark
Posts: 7556
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: RFM69

Post by RogerClark » Fri Nov 25, 2016 3:13 am

You could try using the HAL core for STM32 and the non Arduino library

https://github.com/ahessling/RFM69-STM32

But it looks like it may use the old Standard Peripheral Library rather than the new STM HAL, so porting it to the HAL may not be that straight forward.

INstructions for the HAL core - see, viewtopic.php?f=16&t=1553
But you'll need to download the Work In Progress branch https://github.com/stm32duino/Arduino_C ... 1/tree/WIP

Alternatively to stick with LibMaple, then about your only choice unless you have a way to use the GNU Debugger (GDB) using STLink etc, is just to comment out code until it works.

If merely including the files causes it to hang, then the problem is likely to be in the constructor, especially if it attempts store references to pins before setup() has been called

stevestrong
Posts: 1978
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: RFM69

Post by stevestrong » Fri Nov 25, 2016 8:34 am

patafix wrote:I manage to compile it without errors, but once I upload it to Maple mini clone - it just stops responding, so I know I have messed up somewhere.
Not necessarily.
I don't know what do you mean under "stops responding", but if you mean that you have no serial output, then remove all F() macros from your serial print lines and then try again.

patafix
Posts: 7
Joined: Fri Nov 25, 2016 1:57 am

Re: RFM69

Post by patafix » Fri Nov 25, 2016 9:12 am

Thank you for your replies.

It hangs at constructor, since I cannot get Serial.begin(115200); Serial.print("start"); to display anything @ setup().
I will give it a go once more over the weekend.

Couple more questions:

Code: Select all

// select the RFM69 transceiver (save SPI settings, set CS low)
void RFM69::select() {
  noInterrupts();
#if defined (SPCR) && defined (SPSR)
  // save current SPI settings
  _SPCR = SPCR;
  _SPSR = SPSR;
#endif
  // set RFM69 SPI settings
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(SPI_CLOCK_DIV4); // decided to slow down from DIV2 after SPI stalling in some instances, especially visible on mega1284p when RFM69 and FLASH chip both present
  digitalWrite(_slaveSelectPin, LOW);
}

// unselect the RFM69 transceiver (set CS high, restore SPI settings)
void RFM69::unselect() {
  digitalWrite(_slaveSelectPin, HIGH);
  // restore SPI settings to what they were before talking to RFM69
#if defined (SPCR) && defined (SPSR)
  SPCR = _SPCR;
  SPSR = _SPSR;
#endif
  maybeInterrupts();
}
At 437-462 https://github.com/LowPowerLab/RFM69/bl ... /RFM69.cpp

SPCR and SPSR are AVR specific SPI registers if I understand correctly, is there any equivalent for STM32? Or is it already taken care of within SPI library?

Code: Select all

attachInterrupt(_interruptNum, RFM69::isr0, RISING);
is RISING supported, or should I use CHANGE? If internet is correct, I should be able to use any IO pin for my external interrupt?

P.S. Found that guys at Teensy managed to get it working without any modifications, so I guess either SPI is not fully supported or the interrupts.
Thanks guys.

stevestrong
Posts: 1978
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: RFM69

Post by stevestrong » Fri Nov 25, 2016 10:29 am

I would recommend to wait a period of time after Serial.begin(); (lets say 6 seconds).
Or wait for serial connection:

Code: Select all

 Serial.begin();
 while ( !Serial.isConnected() );
 Serial.print("start"); 
This is necessary for the USB serial port, the USB re-enumeration takes some time on the PC.

patafix
Posts: 7
Joined: Fri Nov 25, 2016 1:57 am

Re: RFM69

Post by patafix » Mon Nov 28, 2016 2:18 pm

Interesting discovery. Tried out something simple - read register values from RFM69HW.
Returns all 0 values if I use SPI1 port (Pins 4-7) on Baite Maple mini.
Returns expected values if I use SPI2 port (Pins 28-32) on Baite Maple mini.

Checked all connections and signals arrive to soldered pins, maybe it is a faulty pcb, will have to order another one to check. Code for reference.

Works:

Code: Select all

#include <SPI.h>

byte data;
#define chipSelect 31
SPIClass spi(2);

void setup() {
  spi.begin(); //Initialize the SPI_1 port.
  spi.setBitOrder(MSBFIRST); // Set the SPI_1 bit order
  spi.setDataMode(SPI_MODE0); //Set the  SPI_2 data mode 0
  spi.setClockDivider(SPI_CLOCK_DIV16);      // Slow speed (72 / 16 = 4.5 MHz SPI_1 speed)
  pinMode(chipSelect, OUTPUT);
  Serial.println("aa");
}

void loop() {
readRegs();
delay(5000);
}

void readRegs()
{
  byte regVal;
  
  for (byte regAddr = 1; regAddr <= 0x4F; regAddr++)
  {
    digitalWrite(chipSelect, LOW); // manually take CSN low for SPI_1 transmission
    spi.transfer(regAddr & 0x7f); // send address + r/w bit
    regVal = spi.transfer(0);
    digitalWrite(chipSelect, HIGH); // manually take CSN low for SPI_1 transmission

    Serial.print(regAddr, HEX);
    Serial.print(" - ");
    Serial.print(regVal,HEX);
    Serial.print(" - ");
    Serial.println(regVal,BIN);
  }
}
Doesn't work:

Code: Select all

#include <SPI.h>

byte data;
#define chipSelect 7


void setup() {
  SPI.begin(); //Initialize the SPI_1 port.
  SPI.setBitOrder(MSBFIRST); // Set the SPI_1 bit order
  SPI.setDataMode(SPI_MODE0); //Set the  SPI_2 data mode 0
  SPI.setClockDivider(SPI_CLOCK_DIV16);      // Slow speed (72 / 16 = 4.5 MHz SPI_1 speed)
  pinMode(chipSelect, OUTPUT);
  Serial.println("aa");
}

void loop() {
readRegs();
delay(5000);
}

void readRegs()
{
  byte regVal;
  
  for (byte regAddr = 1; regAddr <= 0x4F; regAddr++)
  {
    digitalWrite(chipSelect, LOW); // manually take CSN low for SPI_1 transmission
    SPI.transfer(regAddr & 0x7f); // send address + r/w bit
    regVal = SPI.transfer(0);
    digitalWrite(chipSelect, HIGH); // manually take CSN low for SPI_1 transmission

    Serial.print(regAddr, HEX);
    Serial.print(" - ");
    Serial.print(regVal,HEX);
    Serial.print(" - ");
    Serial.println(regVal,BIN);
  }
}

patafix
Posts: 7
Joined: Fri Nov 25, 2016 1:57 am

Re: RFM69

Post by patafix » Mon Nov 28, 2016 5:10 pm

OK, quick update RFM69HW works fine on Baite Maple mini. Had to change SPIClass to use SPI2 as default and comment out

Code: Select all

#if defined (SPCR) && defined (SPSR)
  SPCR = _SPCR;
  SPSR = _SPSR;
#endif
I guess there is a way to get around commenting them out, but it will do for me.

stevestrong
Posts: 1978
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: RFM69

Post by stevestrong » Tue Nov 29, 2016 9:20 am

In general, I would recommend you to use the PXy (ex. PA5) naming convention for defining GPIOs, not simple numbers.

stevestrong
Posts: 1978
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: RFM69

Post by stevestrong » Thu Feb 16, 2017 10:48 pm

@patafix,
Can you please post here the lib for RFM69 you ported for STM32F103?
I am asking this because I am currently also working with this chip and have some problems.

zmemw16
Posts: 1613
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: RFM69

Post by zmemw16 » Sun Feb 19, 2017 12:52 am

spi1 v spi2 long, long thread ... ... ...
no one going to mention clk source and dividers ?
try spi1 again with SPI_CLOCK_DIV32 ??
or have got the wrong idea from tha thread?


stephen

Post Reply