Problem mit der Anbindung eines Attiny84A-PU mit einem nRF24l01+

Hallo,
ich möchte Daten von einem Attiny84A-PU zu einem Arduino Nano 33 IOT schicken und verwende dazu die Transceiver nRF24l01+. Auf der Arduino Seite funktioniert alles soweit aber am Attiny gibt es Probleme. Ich versuche im ersten Schritt radio.begin(), aber er geht nie aus der Loop heraus. Geprüft habe ich das durch ein LED, was nach dem Verlassen der Loop eigentlich ausgeschalten werden sollte. Ich verwende diese Schaltung:

  • nRF24L01 VCC ---- VCC 1|o |14 GND --- nRF24L01 GND
  •                PB0  2|    |13 AREF
    
  •                PB1  3|    |12 PA1
    
  •                PB3  4|    |11 PA2 --- nRF24L01 CE
    
  •                PB2  5|    |10 PA3 --- nRF24L01 CSN
    
  •                PA7  6|    |9  PA4 --- nRF24L01 SCK
    
  • nRF24L01 MOSI --- PA6 7| |8 PA5 --- nRF24L01 MISO
  •                      +----+
    

Bitte kann mir wer dabei helfen.

#include "SPI.h"
#include "RF24.h"

// CE and CSN are configurable, specified values for ATTiny85 as connected above
#define CE_PIN 2
#define CSN_PIN 3
//#define CSN_PIN 3 // uncomment for ATTiny85 3 pins solution

// instantiate an object for the nRF24L01 transceiver
RF24 radio(CE_PIN, CSN_PIN);

// Let these addresses be used for the pair
uint8_t address[][6] = { "1Node", "2Node" };
// It is very helpful to think of an address as a path instead of as
// an identifying device destination

// to use different addresses on a pair of radios, we need a variable to
// uniquely identify which address this radio will use to transmit
bool radioNumber = 0;  // 0 uses address[0] to transmit, 1 uses address[1] to transmit

// Used to control whether this node is sending or receiving
bool role = true;  // true = TX node, false = RX node

// For this example, we'll be using a payload containing
// a string & an integer number that will be incremented
// on every successful transmission.
// Make a data structure to store the entire payload of different datatypes
struct PayloadStruct {
  char message[7];  // only using 6 characters for TX & RX payloads
  uint8_t counter;
};
PayloadStruct payload;

void setup() {

  // append a NULL terminating character for printing as a c-string
  payload.message[6] = 0;
  digitalWrite(PA7, HIGH); 
  // initialize the transceiver on the SPI bus
  if (!radio.begin()) {
    while (1) {}  // hold in infinite loop
  }
  digitalWrite(PA7, LOW);  
  // Set the PA Level low to try preventing power supply related problems
  // because these examples are likely run with nodes in close proximity to
  // each other.
  radio.setPALevel(RF24_PA_LOW);  // RF24_PA_MAX is default.

  // save on transmission time by setting the radio to only transmit the
  // number of bytes we need to transmit a float
  radio.setPayloadSize(sizeof(payload));  // char[7] & uint8_t datatypes occupy 8 bytes

  // set the TX address of the RX node into the TX pipe
  radio.openWritingPipe(address[radioNumber]);  // always uses pipe 0

  // set the RX address of the TX node into a RX pipe
  radio.openReadingPipe(1, address[!radioNumber]);  // using pipe 1

  if (role) {
    // setup the TX node

    memcpy(payload.message, "Hello ", 6);  // set the outgoing message
    radio.stopListening();                 // put radio in TX mode
  } else {
    // setup the RX node

    memcpy(payload.message, "World ", 6);  // set the outgoing message
    radio.startListening();                // put radio in RX mode
  }
}  // setup()

void loop() {
  
  if (role) {
    // This device is a TX node

    bool report = radio.write(&payload, sizeof(payload));  // transmit & save the report

    if (report) {
      // transmission successful; wait for response and print results

      radio.startListening();                  // put in RX mode
      unsigned long start_timeout = millis();  // timer to detect no response
      while (!radio.available()) {             // wait for response or timeout
        if (millis() - start_timeout > 200)    // only wait 200 ms
          break;
      }
      radio.stopListening();  // put back in TX mode

      // print summary of transactions
      if (radio.available()) {  // is there a payload received?
        PayloadStruct received;
        radio.read(&received, sizeof(received));  // get payload from RX FIFO
        payload.counter = received.counter;       // save incoming counter for next outgoing counter
      }
    }  // report

    // to make this example readable in the serial monitor
    delay(1000);  // slow transmissions down by 1 second

  } else {
    // This device is a RX node

    if (radio.available()) {  // is there a payload?

      PayloadStruct received;
      radio.read(&received, sizeof(received));  // get incoming payload
      payload.counter = received.counter + 1;   // increment incoming counter for next outgoing response

      // transmit response & save result to `report`
      radio.stopListening();  // put in TX mode

      radio.writeFast(&payload, sizeof(payload));  // load response to TX FIFO
      radio.txStandBy(150);                        // keep retrying for 150 ms

      radio.startListening();  // put back in RX mode
    }
  }  // role
}  // loop

Das musst du mal etwas genauer erklären.
Wenn der Sketch richtig funktioniert, muss die loop() immer laufen.
Was heißt das dann mit"verlassen" ?

ich rede von dieser loop, welche am Anfang der setup funktion steht:

 if (!radio.begin()) {
    while (1) {}  // hold in infinite loop
  }

und diese wird nicht verlassen.

Da bitte genauer beschreiben.
Die loop ist hier allgemein die "Hauptschleife" des Sketches.
Du sprichst von der while Schleife, die absichtlich so geschrieben ist, damit der Programmierer erkennt, dass in der if-Abfrage etwas nicht funktiert bzw. diese nicht wahr ist.
Wohl weil nichts empfangen wurde.

OK sorry für die ungenaue Beschreibung.
Hier liegt mein Problem.
radio.beginn() ist immer false, obwohl ich es so angeschlossen habe wie in der Schaltung im ersten Post, dann sollte es eigentlich erkannt werden.

Ja, sollte.
Ob der Fehler jetzt an deiner Hardware oder Schaltung oder.....liegt kann ich so nicht sehen. Was den Sketch betrifft, muss ich mir nochmal anschauen. Habe mit dem NRF24L01 lange nichts gemacht.

der Sketch ist eine Vorlage aus GitHub - nRF24/RF24: OSI Layer 2 driver for nRF24L01 on Arduino & Raspberry Pi/Linux Devices hier ist auch die Schaltung enthalten, welche ich verwendet habe.

Huch....ich erinnere.
Hattest du nicht im anderen Thread geschrieben, es funktioniert jetzt ?

da habe ich 2 Arduino versucht zu verbinden, aber der Arduino Nano IOT33 ist zu groß, deshalb musste ich auf einen Attiny84A-PU umsteigen.

Hi,

tausche mal MOSI mit MISO, der ATtiny84 hat kein echtes SPI Interface ...

Gruß André

Ich kann mich schwach daran erinnern, das di Pinbelegung sehr stark von der core-Version abhängig ist.
Versuche mal mit PBx die Pins zu definieren.

Alternativ könntest du auch einen Pro mini verwenden.

MISO, MOSI und SCK auch so wie hier :
#define MISO = PBx

oder nur CE und CSN?

Im Gegensatz zum UNO/NANO etc. müssen nur die MISO und MOSI Leitung getauscht werden.

Gruß André

nein das vertauschen von MISO und MOSI hat leider auch nichts geholfen.

CE / CSn ist frei definierbar, z.Bsp. Pin 5/6
MISO nRF24 kommt an Pin 7 des ATtiny84 (IC-Pin)
MOSI nRF24 ...............Pin 8 ..................
SCK nRF24 ...............Pin 9 ..................

Gruß André

Mit welcher Geschwindigkeit rennt dein ATTiny?

Ja diese Beschaltung habe bereits. MISO ist korrekt und MOSI ebenso.

da habe ich nichts umgestellt und der Clockspeed liegt bei 8 MHz

Ich bin mir nicht sicher, ob der ATtiny84 mit 1MHz oder 8MHz ausgeliefert wird. 1MHz könnte zu langsam sein, meine rennen bei 4MHz ...

Gruß André

Hast du den Clockspeed selbst per "Bootloader" geflasht ?