RFM69 / ATTiny841 interface problems - help?

Started by stevensarns, September 26, 2023, 12:19:48 PM

stevensarns

Hello & thanks in advance for any help.  I am having a problem using the RFM69HCW module attached to a ATtiny841.  I think the problem is with the SPI library/ATTinyCore.  I have successfully used the same code with ATmega328PB and ESP8266 processors.  I have narrowed the code down as much as possible to illustrate the issue.
When all code using SPI transfers is commented out, the code works as expected as evidenced by the action on the "scope" pin.  However as soon as any SPI action is called, the code hangs; no action on the scope pin and no action on any SPI pin.
I am using ATTinyCore/Konde v1.4.1 and RFM_LowPowerLab v1.5.2, Arduino IDE v1.8.13. The RFM69 module is connected to PA4 to PA6 (SCK, MISO, MOSI, NSS) but not connected for this test (same results if connected).  I have whittled the code down to reduce debugging effort. 
I think this may be a problem with the Low Power Lab driver because Konde mentions the need to use SPI.h library, but I think that it may be precompiled into the Low Power Lab RFM69 driver.
Thanks.

// ATtiny841, chip 841, clock 8MHz internal<4.5V, bootloader UART0
// with optiboot - 71% flash, 66% RAM, requires millis()
// use print(F("xx")) 72% flash, 58% RAM

#include <RFM69.h>
#include <SPI.h>

#define NETWORKID     0           // Must be the same for all nodes
#define MYNODEID      22          // My node ID
#define TONODEID      99          // Destination node ID
#define FREQUENCY     RF69_915MHZ // RFM69 frequency
#define scopePin      PIN_PB0     // debug

RFM69 radio;                      // Create a library object

// ----------------------- Setup -------------------------------
void setup() {
  Serial.begin(9600);             // 115200 works also
  pinMode(scopePin, OUTPUT);
  delay(200);  
  Serial.println("Start");
  radio.initialize(FREQUENCY, MYNODEID, NETWORKID);  // Initialize the RFM69HCW:
//  radio.setHighPower();           // Always for RFM69HCW
  Serial.println("ok");
}

// ------------------------ Main ----------------------------
void loop() {
  scope();
//  if (radio.receiveDone()) {            // incoming msg complete
//    Serial.print(F("received from "));  // print out the data received
//    Serial.print(radio.SENDERID, DEC);  // from ID
//    Serial.print(F(", msg ["));         // DATA array, DATALEN bytes in size:
//    for (byte i = 0; i < radio.DATALEN; i++) Serial.print((char)radio.DATA[i]);
//    Serial.print("], RSSI ");           // RSSI smaller stronger
//    Serial.println(radio.RSSI);
//  }
}

void scope() {
  delay(1);
  digitalWrite(scopePin, HIGH);
  delay(1);
  digitalWrite(scopePin, LOW);
}

Felix

Unless you can You will have to put this on a logic analyzer.
The LPL driver uses the generic SPI driver. Whatever that is for your board definition, you should look in there. There is nothing precompiled in LPL libraries, that would be a very bad idea.
And why the bother with ATtiny841?

rsucaet

I use a ATTIny841, you have the SPI connected to the wrong pins. These pins are correct > PA3 SCK, PA2 MISO, PA1 MOSI. Once you connect your RFM69 to these pins it will work with LowPowerLab library, no problem.